Search in sources :

Example 21 with SQLEditor

use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by serge-rider.

the class SQLEditorHandlerSwitchPanel 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 SQLEditorCommands.CMD_SQL_SWITCH_PANEL:
            editor.toggleActivePanel();
            break;
        case SQLEditorCommands.CMD_SQL_SHOW_OUTPUT:
            editor.showOutputPanel();
            break;
        case SQLEditorCommands.CMD_SQL_SHOW_LOG:
            editor.showExecutionLogPanel();
            break;
    }
    return null;
}
Also used : SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor)

Example 22 with SQLEditor

use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by serge-rider.

the class CopySourceCodeHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    SQLEditor editor = RuntimeUtils.getObjectAdapter(HandlerUtil.getActiveEditor(event), SQLEditor.class);
    if (editor == null) {
        return null;
    }
    ISelection selection = editor.getSelectionProvider().getSelection();
    if (selection.isEmpty() || !(selection instanceof TextSelection)) {
        return null;
    }
    TextSelection textSelection = (TextSelection) selection;
    if (textSelection.getLength() < 2) {
        // Use active query
        SQLScriptElement activeQuery = editor.extractActiveQuery();
        if (activeQuery != null && activeQuery.getLength() > 1) {
            textSelection = new TextSelection(editor.getDocument(), activeQuery.getOffset(), activeQuery.getLength());
        }
    }
    TargetFormatDialog dialog = new TargetFormatDialog(editor, textSelection);
    if (dialog.open() != IDialogConstants.OK_ID) {
        return null;
    }
    UIUtils.setClipboardContents(Display.getCurrent(), TextTransfer.getInstance(), dialog.getConvertedText());
    return null;
}
Also used : SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) TextSelection(org.eclipse.jface.text.TextSelection) ISelection(org.eclipse.jface.viewers.ISelection) SQLScriptElement(org.jkiss.dbeaver.model.sql.SQLScriptElement)

Example 23 with SQLEditor

use of org.jkiss.dbeaver.ui.editors.sql.SQLEditor in project dbeaver by serge-rider.

the class SQLEditorHandlerExecute 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 SQLEditorCommands.CMD_EXECUTE_STATEMENT:
            editor.processSQL(false, false);
            break;
        case SQLEditorCommands.CMD_EXECUTE_STATEMENT_NEW:
            editor.processSQL(true, false);
            break;
        case SQLEditorCommands.CMD_EXECUTE_SCRIPT:
            editor.processSQL(false, true);
            break;
        case SQLEditorCommands.CMD_EXECUTE_SCRIPT_NEW:
            editor.processSQL(true, true);
            break;
        case SQLEditorCommands.CMD_EXECUTE_ROW_COUNT:
            editor.processSQL(false, false, new SQLQueryTransformerCount(), null);
            break;
        case SQLEditorCommands.CMD_EXECUTE_EXPRESSION:
            editor.processSQL(false, false, new SQLQueryTransformerExpression(), null);
            break;
        case SQLEditorCommands.CMD_EXECUTE_ALL_ROWS:
            editor.processSQL(false, false, new SQLQueryTransformerAllRows(), null);
            break;
        case SQLEditorCommands.CMD_EXPLAIN_PLAN:
            editor.explainQueryPlan();
            break;
        case SQLEditorCommands.CMD_LOAD_PLAN:
            editor.loadQueryPlan();
            break;
        default:
            log.error("Unsupported SQL editor command: " + actionId);
            break;
    }
    editor.refreshActions();
    return null;
}
Also used : SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) SQLQueryTransformerCount(org.jkiss.dbeaver.model.impl.sql.SQLQueryTransformerCount) SQLQueryTransformerExpression(org.jkiss.dbeaver.model.impl.sql.SQLQueryTransformerExpression) SQLQueryTransformerAllRows(org.jkiss.dbeaver.model.impl.sql.SQLQueryTransformerAllRows)

Aggregations

SQLEditor (org.jkiss.dbeaver.ui.editors.sql.SQLEditor)23 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)5 IFile (org.eclipse.core.resources.IFile)4 IEditorPart (org.eclipse.ui.IEditorPart)4 DBRProgressMonitor (org.jkiss.dbeaver.model.runtime.DBRProgressMonitor)4 TextSelection (org.eclipse.jface.text.TextSelection)3 ISelection (org.eclipse.jface.viewers.ISelection)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 DBPDataSourceContainer (org.jkiss.dbeaver.model.DBPDataSourceContainer)3 SQLQueryTransformerCount (org.jkiss.dbeaver.model.impl.sql.SQLQueryTransformerCount)3 SQLQueryTransformerExpression (org.jkiss.dbeaver.model.impl.sql.SQLQueryTransformerExpression)3 DBSObject (org.jkiss.dbeaver.model.struct.DBSObject)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IJobChangeEvent (org.eclipse.core.runtime.jobs.IJobChangeEvent)2 JobChangeAdapter (org.eclipse.core.runtime.jobs.JobChangeAdapter)2 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)2 SelectionEvent (org.eclipse.swt.events.SelectionEvent)2 MenuItem (org.eclipse.swt.widgets.MenuItem)2 NotNull (org.jkiss.code.NotNull)2 DBException (org.jkiss.dbeaver.DBException)2