Search in sources :

Example 6 with SQLEditorBase

use of org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase in project dbeaver by dbeaver.

the class AssistTemplatesHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (activeEditor instanceof SQLEditorBase) {
        SQLEditorBase editor = (SQLEditorBase) activeEditor;
        boolean oldValue = SQLCompletionProcessor.isLookupTemplates();
        SQLCompletionProcessor.setLookupTemplates(true);
        try {
            editor.getTextViewer().doOperation(SourceViewer.CONTENTASSIST_PROPOSALS);
        } finally {
            SQLCompletionProcessor.setLookupTemplates(oldValue);
        }
    }
    return null;
}
Also used : SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) IEditorPart(org.eclipse.ui.IEditorPart)

Example 7 with SQLEditorBase

use of org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase in project dbeaver by dbeaver.

the class NavigateObjectHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (activeEditor != null) {
        SQLEditorBase sqlEditor = DBUtils.getAdapter(SQLEditorBase.class, activeEditor);
        if (sqlEditor != null) {
            IHyperlink hyperlink = getCurrentHyperlink(sqlEditor);
            if (hyperlink != null) {
                IRegion selRegion2 = hyperlink.getHyperlinkRegion();
                TextViewer textViewer = sqlEditor.getTextViewer();
                if (textViewer != null) {
                    textViewer.setSelectedRange(selRegion2.getOffset(), selRegion2.getLength());
                }
                hyperlink.open();
            }
        }
    }
    return null;
}
Also used : SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) IHyperlink(org.eclipse.jface.text.hyperlink.IHyperlink) IEditorPart(org.eclipse.ui.IEditorPart) IRegion(org.eclipse.jface.text.IRegion) TextViewer(org.eclipse.jface.text.TextViewer)

Example 8 with SQLEditorBase

use of org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase in project dbeaver by dbeaver.

the class NavigateQueryHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    IEditorPart activeEditor = HandlerUtil.getActiveEditor(event);
    if (!(activeEditor instanceof SQLEditorBase)) {
        return null;
    }
    SQLEditorBase editor = (SQLEditorBase) activeEditor;
    String actionId = event.getCommand().getId();
    SQLScriptElement nextQuery;
    switch(actionId) {
        case CoreCommands.CMD_SQL_QUERY_NEXT:
            nextQuery = editor.extractNextQuery(true);
            break;
        case CoreCommands.CMD_SQL_QUERY_PREV:
            nextQuery = editor.extractNextQuery(false);
            break;
        default:
            nextQuery = null;
            break;
    }
    if (nextQuery != null) {
        editor.selectAndReveal(nextQuery.getOffset(), nextQuery.getLength());
    }
    return null;
}
Also used : SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) SQLScriptElement(org.jkiss.dbeaver.model.sql.SQLScriptElement) IEditorPart(org.eclipse.ui.IEditorPart)

Example 9 with SQLEditorBase

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

the class WorkbenchContextListener method activatePartContexts.

void activatePartContexts(IWorkbenchPart part) {
    IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
    if (contextService == null) {
        return;
    }
    try {
        contextService.deferUpdates(true);
        if (part instanceof INavigatorModelView) {
        // We check for instanceof (do not use adapter) because otherwise it become active
        // for all entity editor and clashes with SQL editor and other complex stuff.
        // if (activationNavigator != null) {
        // //log.debug("Double activation of navigator context");
        // contextService.deactivateContext(activationNavigator);
        // }
        // activationNavigator = contextService.activateContext(INavigatorModelView.NAVIGATOR_CONTEXT_ID);
        }
        if (part instanceof SQLEditorBase || part.getAdapter(SQLEditorBase.class) != null) {
            if (activationSQL != null) {
                // log.debug("Double activation of SQL context");
                contextService.deactivateContext(activationSQL);
            }
            activationSQL = contextService.activateContext(SQLEditorContributions.SQL_EDITOR_CONTEXT);
        }
        if (part.getAdapter(ResultSetViewer.class) != null || (part instanceof SQLEditor) || (part instanceof EntityEditor && ((EntityEditor) part).getDatabaseObject() instanceof DBSDataContainer)) {
            if (activationResults != null) {
                contextService.deactivateContext(activationResults);
            }
            activationResults = contextService.activateContext(RESULTS_CONTEXT_ID);
        }
        // Refresh auto-commit element state (#3315)
        // Refresh OpenSeparateConnection
        ActionUtils.fireCommandRefresh(ConnectionCommands.CMD_TOGGLE_AUTOCOMMIT, SQLEditorCommands.CMD_TOGGLE_SEPARATE_CONNECTION);
    } finally {
        contextService.deferUpdates(false);
    }
}
Also used : SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) IContextService(org.eclipse.ui.contexts.IContextService) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)

Example 10 with SQLEditorBase

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

the class PackageNavigateHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    final OracleProcedurePackaged procedure = getSelectedProcedure(event);
    if (procedure != null) {
        OraclePackage procPackage = procedure.getParentObject();
        IEditorPart entityEditor = NavigatorHandlerObjectOpen.openEntityEditor(procPackage);
        if (entityEditor instanceof EntityEditor) {
            ((EntityEditor) entityEditor).switchFolder("source.definition");
            SQLEditorBase sqlEditor = entityEditor.getAdapter(SQLEditorBase.class);
            if (sqlEditor != null) {
                new NavigateJob(procedure, sqlEditor).schedule();
            }
        }
    }
    return null;
}
Also used : OracleProcedurePackaged(org.jkiss.dbeaver.ext.oracle.model.OracleProcedurePackaged) OraclePackage(org.jkiss.dbeaver.ext.oracle.model.OraclePackage) SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) IEditorPart(org.eclipse.ui.IEditorPart)

Aggregations

SQLEditorBase (org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase)25 IEditorPart (org.eclipse.ui.IEditorPart)14 StyledText (org.eclipse.swt.custom.StyledText)7 FillLayout (org.eclipse.swt.layout.FillLayout)7 GridData (org.eclipse.swt.layout.GridData)7 DisposeEvent (org.eclipse.swt.events.DisposeEvent)4 DisposeListener (org.eclipse.swt.events.DisposeListener)4 Composite (org.eclipse.swt.widgets.Composite)4 NotNull (org.jkiss.code.NotNull)4 DBCExecutionContext (org.jkiss.dbeaver.model.exec.DBCExecutionContext)4 StringEditorInput (org.jkiss.dbeaver.ui.editors.StringEditorInput)4 SubEditorSite (org.jkiss.dbeaver.ui.editors.SubEditorSite)4 InputStream (java.io.InputStream)3 IRegion (org.eclipse.jface.text.IRegion)3 IHyperlink (org.eclipse.jface.text.hyperlink.IHyperlink)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 IContextService (org.eclipse.ui.contexts.IContextService)3 SQLDialect (org.jkiss.dbeaver.model.sql.SQLDialect)3 EntityEditor (org.jkiss.dbeaver.ui.editors.entity.EntityEditor)3