Search in sources :

Example 16 with IContextService

use of org.eclipse.ui.contexts.IContextService 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 17 with IContextService

use of org.eclipse.ui.contexts.IContextService in project dbeaver by serge-rider.

the class EditorUtils method trackControlContext.

public static void trackControlContext(IWorkbenchSite site, Control control, String contextId) {
    final IContextService contextService = site.getService(IContextService.class);
    if (contextService != null) {
        final IContextActivation[] activation = new IContextActivation[1];
        FocusListener focusListener = new FocusListener() {

            @Override
            public void focusGained(FocusEvent e) {
                // No need to deactivate the same context
                if (activation[0] != null) {
                    contextService.deactivateContext(activation[0]);
                    activation[0] = null;
                }
                activation[0] = contextService.activateContext(contextId);
            // new Exception().printStackTrace();
            }

            @Override
            public void focusLost(FocusEvent e) {
                if (activation[0] != null) {
                    contextService.deactivateContext(activation[0]);
                    activation[0] = null;
                }
            }
        };
        control.addFocusListener(focusListener);
        control.addDisposeListener(e -> {
            if (activation[0] != null) {
                contextService.deactivateContext(activation[0]);
                activation[0] = null;
            }
        });
    }
}
Also used : IContextActivation(org.eclipse.ui.contexts.IContextActivation) IContextService(org.eclipse.ui.contexts.IContextService) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Example 18 with IContextService

use of org.eclipse.ui.contexts.IContextService in project dbeaver by dbeaver.

the class WorkbenchContextListener method deactivatePartContexts.

void deactivatePartContexts(IWorkbenchPart part) {
    IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
    if (contextService == null) {
        return;
    }
    try {
        contextService.deferUpdates(true);
        // }
        if (activationSQL != null) {
            contextService.deactivateContext(activationSQL);
            activationSQL = null;
        }
        if (activationResults != null) {
            contextService.deactivateContext(activationResults);
            activationResults = null;
        }
    } finally {
        contextService.deferUpdates(false);
    }
}
Also used : IContextService(org.eclipse.ui.contexts.IContextService)

Example 19 with IContextService

use of org.eclipse.ui.contexts.IContextService in project dbeaver by dbeaver.

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 20 with IContextService

use of org.eclipse.ui.contexts.IContextService in project dbeaver by dbeaver.

the class AbstractPresentation method activateTextKeyBindings.

protected void activateTextKeyBindings(@NotNull IResultSetController controller, Control control) {
    final IContextService contextService = controller.getSite().getService(IContextService.class);
    control.addFocusListener(new FocusListener() {

        IContextActivation activation;

        @Override
        public void focusGained(FocusEvent e) {
            controller.updateEditControls();
            if (activation == null) {
                activation = contextService.activateContext("org.eclipse.ui.textEditorScope");
            }
        }

        @Override
        public void focusLost(FocusEvent e) {
            controller.updateEditControls();
            if (activation != null) {
                contextService.deactivateContext(activation);
                activation = null;
            }
        }
    });
}
Also used : IContextActivation(org.eclipse.ui.contexts.IContextActivation) IContextService(org.eclipse.ui.contexts.IContextService) FocusListener(org.eclipse.swt.events.FocusListener) FocusEvent(org.eclipse.swt.events.FocusEvent)

Aggregations

IContextService (org.eclipse.ui.contexts.IContextService)39 IContextActivation (org.eclipse.ui.contexts.IContextActivation)8 IHandlerService (org.eclipse.ui.handlers.IHandlerService)8 FocusEvent (org.eclipse.swt.events.FocusEvent)7 FocusListener (org.eclipse.swt.events.FocusListener)7 SQLEditorBase (org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase)6 INavigatorModelView (org.jkiss.dbeaver.ui.navigator.INavigatorModelView)6 ActionHandler (org.eclipse.jface.commands.ActionHandler)5 ISourceViewer (org.eclipse.jface.text.source.ISourceViewer)5 ProjectionViewer (org.eclipse.jface.text.source.projection.ProjectionViewer)4 DBSDataContainer (org.jkiss.dbeaver.model.struct.DBSDataContainer)4 ResultSetViewer (org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)4 EntityEditor (org.jkiss.dbeaver.ui.editors.entity.EntityEditor)4 SQLEditor (org.jkiss.dbeaver.ui.editors.sql.SQLEditor)4 IAction (org.eclipse.jface.action.IAction)3 Shell (org.eclipse.swt.widgets.Shell)3 IPageSite (org.eclipse.ui.part.IPageSite)3 ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IExecutionListener (org.eclipse.core.commands.IExecutionListener)2