use of org.jkiss.dbeaver.model.exec.compile.DBCSourceHost in project dbeaver by serge-rider.
the class CompileHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final List<OracleSourceObject> objects = getSelectedObjects(event);
if (!objects.isEmpty()) {
final Shell activeShell = HandlerUtil.getActiveShell(event);
if (objects.size() == 1) {
final OracleSourceObject unit = objects.get(0);
DBCSourceHost sourceHost = null;
final IWorkbenchPart activePart = HandlerUtil.getActiveEditor(event);
if (activePart != null) {
sourceHost = RuntimeUtils.getObjectAdapter(activePart, DBCSourceHost.class);
if (sourceHost == null) {
sourceHost = activePart.getAdapter(DBCSourceHost.class);
}
}
if (sourceHost != null && sourceHost.getSourceObject() != unit) {
sourceHost = null;
}
final DBCCompileLog compileLog = sourceHost == null ? new DBCCompileLogBase() : sourceHost.getCompileLog();
compileLog.clearLog();
Throwable error = null;
try {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
compileUnit(monitor, compileLog, unit);
} catch (DBCException e) {
throw new InvocationTargetException(e);
}
}
});
if (compileLog.getError() != null) {
error = compileLog.getError();
}
} catch (InvocationTargetException e) {
error = e.getTargetException();
} catch (InterruptedException e) {
return null;
}
if (error != null) {
UIUtils.showErrorDialog(activeShell, "Unexpected compilation error", null, error);
} else if (!CommonUtils.isEmpty(compileLog.getErrorStack())) {
// Show compile errors
int line = -1, position = -1;
StringBuilder fullMessage = new StringBuilder();
for (DBCCompileError oce : compileLog.getErrorStack()) {
fullMessage.append(oce.toString()).append(GeneralUtils.getDefaultLineSeparator());
if (line < 0) {
line = oce.getLine();
position = oce.getPosition();
}
}
// If compiled object is currently open in editor - try to position on error line
if (sourceHost != null && sourceHost.getSourceObject() == unit && line > 0 && position > 0) {
sourceHost.positionSource(line, position);
activePart.getSite().getPage().activate(activePart);
}
String errorTitle = unit.getName() + " compilation failed";
if (sourceHost != null) {
sourceHost.setCompileInfo(errorTitle, true);
sourceHost.showCompileLog();
}
UIUtils.showErrorDialog(activeShell, errorTitle, fullMessage.toString());
} else {
String message = unit.getName() + " compiled successfully";
if (sourceHost != null) {
sourceHost.setCompileInfo(message, true);
}
UIUtils.showMessageBox(activeShell, "Done", message, SWT.ICON_INFORMATION);
}
} else {
OracleCompilerDialog dialog = new OracleCompilerDialog(activeShell, objects);
dialog.open();
}
}
return null;
}
use of org.jkiss.dbeaver.model.exec.compile.DBCSourceHost in project dbeaver by dbeaver.
the class CompileHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchPart activePart = HandlerUtil.getActiveEditor(event);
final List<OracleSourceObject> objects = getSelectedObjects(event);
if (!objects.isEmpty()) {
if (activePart instanceof EntityEditor) {
// Save editor before compile
// USe null monitor as entity editor has its own detached job for save
EntityEditor entityEditor = (EntityEditor) activePart;
if (entityEditor.isDirty()) {
NullProgressMonitor monitor = new NullProgressMonitor();
entityEditor.doSave(monitor);
if (monitor.isCanceled()) {
// Save failed - doesn't make sense to compile
return null;
}
}
}
final Shell activeShell = HandlerUtil.getActiveShell(event);
if (objects.size() == 1) {
final OracleSourceObject unit = objects.get(0);
DBCSourceHost sourceHost = null;
if (activePart != null) {
sourceHost = RuntimeUtils.getObjectAdapter(activePart, DBCSourceHost.class);
if (sourceHost == null) {
sourceHost = activePart.getAdapter(DBCSourceHost.class);
}
}
if (sourceHost != null && sourceHost.getSourceObject() != unit) {
sourceHost = null;
}
final DBCCompileLog compileLog = sourceHost == null ? new DBCCompileLogBase() : sourceHost.getCompileLog();
compileLog.clearLog();
Throwable error = null;
try {
DBeaverUI.runInProgressService(new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
try {
compileUnit(monitor, compileLog, unit);
} catch (DBCException e) {
throw new InvocationTargetException(e);
}
}
});
if (compileLog.getError() != null) {
error = compileLog.getError();
}
} catch (InvocationTargetException e) {
error = e.getTargetException();
} catch (InterruptedException e) {
return null;
}
if (error != null) {
DBUserInterface.getInstance().showError("Unexpected compilation error", null, error);
} else if (!CommonUtils.isEmpty(compileLog.getErrorStack())) {
// Show compile errors
int line = -1, position = -1;
StringBuilder fullMessage = new StringBuilder();
for (DBCCompileError oce : compileLog.getErrorStack()) {
fullMessage.append(oce.toString()).append(GeneralUtils.getDefaultLineSeparator());
if (line < 0) {
line = oce.getLine();
position = oce.getPosition();
}
}
// If compiled object is currently open in editor - try to position on error line
if (sourceHost != null && sourceHost.getSourceObject() == unit && line > 0 && position > 0) {
sourceHost.positionSource(line, position);
activePart.getSite().getPage().activate(activePart);
}
String errorTitle = unit.getName() + " compilation failed";
if (sourceHost != null) {
sourceHost.setCompileInfo(errorTitle, true);
sourceHost.showCompileLog();
}
DBUserInterface.getInstance().showError(errorTitle, fullMessage.toString());
} else {
String message = unit.getName() + " compiled successfully";
if (sourceHost != null) {
sourceHost.setCompileInfo(message, true);
}
UIUtils.showMessageBox(activeShell, "Done", message, SWT.ICON_INFORMATION);
}
} else {
OracleCompilerDialog dialog = new OracleCompilerDialog(activeShell, objects);
dialog.open();
}
}
return null;
}
use of org.jkiss.dbeaver.model.exec.compile.DBCSourceHost in project dbeaver by serge-rider.
the class CompileHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchPart activePart = HandlerUtil.getActiveEditor(event);
final List<OracleSourceObject> objects = getSelectedObjects(event);
if (!objects.isEmpty()) {
/*
if (activePart instanceof EntityEditor) {
// Save editor before compile
// USe null monitor as entity editor has its own detached job for save
EntityEditor entityEditor = (EntityEditor) activePart;
if (entityEditor.isDirty()) {
NullProgressMonitor monitor = new NullProgressMonitor();
entityEditor.doSave(monitor);
if (monitor.isCanceled()) {
// Save failed - doesn't make sense to compile
return null;
}
}
}
*/
final Shell activeShell = HandlerUtil.getActiveShell(event);
if (objects.size() == 1) {
final OracleSourceObject unit = objects.get(0);
DBCSourceHost sourceHost = null;
if (activePart != null) {
sourceHost = RuntimeUtils.getObjectAdapter(activePart, DBCSourceHost.class);
if (sourceHost == null) {
sourceHost = activePart.getAdapter(DBCSourceHost.class);
}
}
if (sourceHost != null && sourceHost.getSourceObject() != unit) {
sourceHost = null;
}
final DBCCompileLog compileLog = sourceHost == null ? new DBCCompileLogBase() : sourceHost.getCompileLog();
compileLog.clearLog();
Throwable error = null;
try {
UIUtils.runInProgressService(monitor -> {
monitor.beginTask("Compile", 1);
try {
compileUnit(monitor, compileLog, unit);
} catch (DBCException e) {
throw new InvocationTargetException(e);
} finally {
monitor.done();
}
});
if (compileLog.getError() != null) {
error = compileLog.getError();
}
} catch (InvocationTargetException e) {
error = e.getTargetException();
} catch (InterruptedException e) {
return null;
}
if (error != null) {
DBWorkbench.getPlatformUI().showError("Unexpected compilation error", null, error);
} else if (!CommonUtils.isEmpty(compileLog.getErrorStack())) {
// Show compile errors
int line = -1, position = -1;
StringBuilder fullMessage = new StringBuilder();
for (DBCCompileError oce : compileLog.getErrorStack()) {
fullMessage.append(oce.toString()).append(GeneralUtils.getDefaultLineSeparator());
if (line < 0) {
line = oce.getLine();
position = oce.getPosition();
}
}
// If compiled object is currently open in editor - try to position on error line
if (sourceHost != null && sourceHost.getSourceObject() == unit && line > 0 && position >= 0) {
sourceHost.positionSource(line, position);
activePart.getSite().getPage().activate(activePart);
}
String errorTitle = unit.getName() + " compilation failed";
if (sourceHost != null) {
sourceHost.setCompileInfo(errorTitle, true);
sourceHost.showCompileLog();
}
DBWorkbench.getPlatformUI().showError(errorTitle, fullMessage.toString());
} else {
String message = unit.getName() + " compiled successfully";
if (sourceHost != null) {
sourceHost.setCompileInfo(message, true);
}
UIUtils.showMessageBox(activeShell, "Done", message, SWT.ICON_INFORMATION);
}
} else {
OracleCompilerDialog dialog = new OracleCompilerDialog(activeShell, objects);
dialog.open();
}
}
return null;
}
Aggregations