Search in sources :

Example 31 with IContextService

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

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

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

the class WorkbenchContextListener method listenWindowEvents.

private void listenWindowEvents(IWorkbenchWindow window) {
    {
        // Register ds toolbar handler
        DataSourceToolbarHandler toolbarHandler = new DataSourceToolbarHandler(window);
        window.getShell().addDisposeListener(e -> toolbarHandler.dispose());
    }
    IPerspectiveListener perspectiveListener = new IPerspectiveListener() {

        private IContextActivation perspectiveActivation;

        @Override
        public void perspectiveActivated(IWorkbenchPage page, IPerspectiveDescriptor perspective) {
            IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
            if (contextService == null) {
                return;
            }
            if (perspective.getId().equals(DBeaverPerspective.PERSPECTIVE_ID)) {
                perspectiveActivation = contextService.activateContext(PERSPECTIVE_CONTEXT_ID);
            } else if (perspectiveActivation != null) {
                contextService.deactivateContext(perspectiveActivation);
                perspectiveActivation = null;
            }
        }

        @Override
        public void perspectiveChanged(IWorkbenchPage page, IPerspectiveDescriptor perspective, String changeId) {
        }
    };
    window.addPerspectiveListener(perspectiveListener);
    IWorkbenchPage activePage = window.getActivePage();
    if (activePage != null) {
        perspectiveListener.perspectiveActivated(activePage, activePage.getPerspective());
    }
    window.addPageListener(this);
    for (IWorkbenchPage page : window.getPages()) {
        page.addPartListener(this);
    }
}
Also used : ExecutionEvent(org.eclipse.core.commands.ExecutionEvent) DataSourceToolbarHandler(org.jkiss.dbeaver.ui.actions.datasource.DataSourceToolbarHandler) IContextActivation(org.eclipse.ui.contexts.IContextActivation) DBRFeature(org.jkiss.dbeaver.model.runtime.features.DBRFeature) DBRFeatureRegistry(org.jkiss.dbeaver.model.runtime.features.DBRFeatureRegistry) SQLEditorContributions(org.jkiss.dbeaver.ui.editors.sql.SQLEditorContributions) ICommandService(org.eclipse.ui.commands.ICommandService) ExecutionException(org.eclipse.core.commands.ExecutionException) SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) DBeaverPerspective(org.jkiss.dbeaver.ui.perspective.DBeaverPerspective) IExecutionListener(org.eclipse.core.commands.IExecutionListener) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView) org.eclipse.ui(org.eclipse.ui) EntityEditor(org.jkiss.dbeaver.ui.editors.entity.EntityEditor) DBSDataContainer(org.jkiss.dbeaver.model.struct.DBSDataContainer) SQLEditorCommands(org.jkiss.dbeaver.ui.editors.sql.SQLEditorCommands) IContextService(org.eclipse.ui.contexts.IContextService) ResultSetViewer(org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer) SQLEditor(org.jkiss.dbeaver.ui.editors.sql.SQLEditor) ConnectionCommands(org.jkiss.dbeaver.ui.actions.datasource.ConnectionCommands) ActionUtils(org.jkiss.dbeaver.ui.ActionUtils) NotHandledException(org.eclipse.core.commands.NotHandledException) IContextActivation(org.eclipse.ui.contexts.IContextActivation) DataSourceToolbarHandler(org.jkiss.dbeaver.ui.actions.datasource.DataSourceToolbarHandler) IContextService(org.eclipse.ui.contexts.IContextService)

Example 33 with IContextService

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

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)

Example 34 with IContextService

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

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

use of org.eclipse.ui.contexts.IContextService in project mylyn.docs by eclipse.

the class MarkupEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    super.init(site, input);
    IContextService contextService = site.getService(IContextService.class);
    contextService.activateContext(CONTEXT);
}
Also used : IContextService(org.eclipse.ui.contexts.IContextService)

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