use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by dbeaver.
the class ExecuteHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
SQLEditor editor = RuntimeUtils.getObjectAdapter(HandlerUtil.getActiveEditor(event), SQLEditor.class);
if (editor == null) {
log.error("No active SQL editor found");
return null;
}
String actionId = event.getCommand().getId();
switch(actionId) {
case CoreCommands.CMD_EXECUTE_STATEMENT:
editor.processSQL(false, false);
break;
case CoreCommands.CMD_EXECUTE_STATEMENT_NEW:
editor.processSQL(true, false);
break;
case CoreCommands.CMD_EXECUTE_SCRIPT:
editor.processSQL(false, true);
break;
case CoreCommands.CMD_EXECUTE_SCRIPT_NEW:
editor.processSQL(true, true);
break;
case CoreCommands.CMD_EXECUTE_ROW_COUNT:
editor.processSQL(false, false, new SQLQueryTransformerCount(), null);
break;
case CoreCommands.CMD_EXECUTE_EXPRESSION:
editor.processSQL(false, false, new SQLQueryTransformerExpression(), null);
break;
case CoreCommands.CMD_EXECUTE_ALL_ROWS:
editor.processSQL(false, false, new SQLQueryTransformerAllRows(), null);
break;
case CoreCommands.CMD_EXPLAIN_PLAN:
editor.explainQueryPlan();
break;
default:
log.error("Unsupported SQL editor command: " + actionId);
break;
}
return null;
}
use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by dbeaver.
the class MaximizeResultsPanelHandler method updateElement.
@Override
public void updateElement(UIElement element, Map parameters) {
IWorkbenchWindow workbenchWindow = element.getServiceLocator().getService(IWorkbenchWindow.class);
if (workbenchWindow == null || workbenchWindow.getActivePage() == null) {
return;
}
IEditorPart activeEditor = workbenchWindow.getActivePage().getActiveEditor();
if (activeEditor == null) {
return;
}
SQLEditor editor = RuntimeUtils.getObjectAdapter(activeEditor, SQLEditor.class);
if (editor != null) {
if (editor.hasMaximizedControl()) {
element.setText("Restore results panel");
} else {
element.setText("Maximize results panel");
}
}
}
use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by dbeaver.
the class OpenObjectConsoleHandler method openConsole.
protected void openConsole(IWorkbenchWindow workbenchWindow, DBRRunnableWithResult<String> generator, DBPDataSourceContainer ds, String title, boolean doRun) {
DBeaverUI.runInUI(workbenchWindow, generator);
String sql = generator.getResult();
SQLEditor editor = OpenHandler.openSQLConsole(workbenchWindow, ds, title, sql);
if (editor != null) {
AbstractJob execJob = new AbstractJob("Execute SQL in console") {
@Override
protected IStatus run(DBRProgressMonitor monitor) {
// So let's give it a chance and wait for 10 seconds
for (int i = 0; i < 100; i++) {
if (editor.getExecutionContext() != null) {
break;
}
RuntimeUtils.pause(100);
}
return Status.OK_STATUS;
}
};
execJob.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
DBeaverUI.syncExec(new Runnable() {
@Override
public void run() {
if (doRun) {
editor.processSQL(false, false);
}
}
});
}
});
execJob.schedule();
}
}
use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by dbeaver.
the class SwitchPanelHandler method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
SQLEditor editor = RuntimeUtils.getObjectAdapter(HandlerUtil.getActiveEditor(event), SQLEditor.class);
if (editor == null) {
return null;
}
String actionId = event.getCommand().getId();
switch(actionId) {
case CoreCommands.CMD_SQL_SWITCH_PANEL:
editor.toggleActivePanel();
break;
case CoreCommands.CMD_SQL_SHOW_OUTPUT:
editor.showOutputPanel();
break;
case CoreCommands.CMD_SQL_SHOW_LOG:
editor.showExecutionLogPanel();
break;
}
return null;
}
use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by dbeaver.
the class NavigatorHandlerLinkEditor method execute.
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
final IWorkbenchPage activePage = HandlerUtil.getActiveWorkbenchWindow(event).getActivePage();
final IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
if (activeEditor == null) {
return null;
}
NavigatorViewBase navigatorView = NavigatorUtils.getActiveNavigatorView(event);
if (navigatorView == null) {
return null;
}
if (navigatorView instanceof ProjectExplorerView) {
if (activeEditor instanceof SQLEditor) {
IFile file = EditorUtils.getFileFromInput(activeEditor.getEditorInput());
if (file != null) {
showResourceInNavigator(navigatorView, file);
}
} else if (activeEditor.getEditorInput() instanceof ProjectFileEditorInput) {
IFile editorFile = ((ProjectFileEditorInput) activeEditor.getEditorInput()).getFile();
showResourceInNavigator(navigatorView, editorFile);
}
} else if (activeEditor.getEditorInput() instanceof IDatabaseEditorInput) {
IDatabaseEditorInput editorInput = (IDatabaseEditorInput) activeEditor.getEditorInput();
DBNNode dbnNode = editorInput.getNavigatorNode();
if (dbnNode != null) {
navigatorView.showNode(dbnNode);
}
} else if (activeEditor instanceof IDataSourceContainerProvider) {
DBPDataSourceContainer dsContainer = ((IDataSourceContainerProvider) activeEditor).getDataSourceContainer();
@NotNull final DBSObject activeObject;
if (dsContainer != null) {
DBPDataSource dataSource = dsContainer.getDataSource();
if (dataSource != null) {
activeObject = DBUtils.getDefaultOrActiveObject(dataSource);
} else {
activeObject = dsContainer;
}
final NavigatorViewBase view = navigatorView;
DBeaverUI.runInUI(activePage.getWorkbenchWindow(), new DBRRunnableWithProgress() {
@Override
public void run(DBRProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
DBSObject showObject = activeObject;
if (showObject instanceof DBPDataSource) {
showObject = ((DBPDataSource) showObject).getContainer();
}
DBNDatabaseNode objectNode = view.getModel().getNodeByObject(monitor, showObject, true);
if (objectNode != null) {
view.showNode(objectNode);
}
}
});
}
}
activePage.activate(navigatorView);
return null;
}
Aggregations