Search in sources :

Example 26 with IContextService

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

the class WorkbenchContextListener method partDeactivated.

@Override
public void partDeactivated(IWorkbenchPart part) {
    IContextService contextService = PlatformUI.getWorkbench().getService(IContextService.class);
    if (contextService == null) {
        return;
    }
    try {
        contextService.deferUpdates(true);
        if (activationNavigator != null && part instanceof INavigatorModelView) {
            contextService.deactivateContext(activationNavigator);
            activationNavigator = null;
        }
        if (activationSQL != null && part instanceof SQLEditorBase) {
            contextService.deactivateContext(activationSQL);
            activationSQL = null;
        }
        if (activationResults != null) {
            contextService.deactivateContext(activationResults);
            activationResults = null;
        }
    } finally {
        contextService.deferUpdates(false);
    }
// log.info(part.getClass().getSimpleName() + " DEACTIVATED: " + contextService.getActiveContextIds());
}
Also used : SQLEditorBase(org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase) IContextService(org.eclipse.ui.contexts.IContextService) INavigatorModelView(org.jkiss.dbeaver.ui.navigator.INavigatorModelView)

Example 27 with IContextService

use of org.eclipse.ui.contexts.IContextService in project tmdm-studio-se by Talend.

the class TreeViewerListener method activateContext.

/**
 * Activate a context that this view uses. It will be tied to this view activation events and will be removed when
 * the view is disposed.
 */
private void activateContext() {
    IContextService contextService = (IContextService) getSite().getService(IContextService.class);
    contextService.activateContext(VIEW_CONTEXT_ID);
}
Also used : IContextService(org.eclipse.ui.contexts.IContextService)

Example 28 with IContextService

use of org.eclipse.ui.contexts.IContextService in project tdq-studio-se by Talend.

the class DQRespositoryView method activateContext.

/**
 * Activate a context that this view uses. It will be tied to this view activation events and will be removed when
 * the view is disposed.
 */
private void activateContext() {
    IContextService contextService = (IContextService) getSite().getService(IContextService.class);
    contextService.activateContext(VIEW_CONTEXT_ID);
}
Also used : IContextService(org.eclipse.ui.contexts.IContextService)

Example 29 with IContextService

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

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

use of org.eclipse.ui.contexts.IContextService in project xtext-eclipse by eclipse.

the class EmbeddedEditorActions method createFocusAndDisposeListeners.

protected void createFocusAndDisposeListeners() {
    final List<IHandlerActivation> handlerActivations = Lists.newArrayListWithExpectedSize(3);
    final IHandlerService handlerService = workbench.getAdapter(IHandlerService.class);
    final IContextService contextService = workbench.getAdapter(IContextService.class);
    Shell shell = viewer.getTextWidget().getShell();
    final ActiveShellExpression expression = new ActiveShellExpression(shell);
    final IContextActivation contextActivation = contextService.activateContext(EMBEDDED_TEXT_EDITOR_SCOPE, expression);
    shell.addDisposeListener(new DisposeListener() {

        @Override
        public void widgetDisposed(DisposeEvent e) {
            handlerService.deactivateHandlers(handlerActivations);
            contextService.deactivateContext(contextActivation);
        }
    });
    viewer.getTextWidget().addFocusListener(new FocusListener() {

        @Override
        public void focusLost(FocusEvent e) {
            handlerService.deactivateHandlers(handlerActivations);
            handlerActivations.clear();
        }

        @Override
        public void focusGained(FocusEvent e) {
            for (final IAction action : allActions.values()) {
                handlerActivations.add(handlerService.activateHandler(action.getActionDefinitionId(), new ActionHandler(action), expression, true));
            }
        }
    });
}
Also used : DisposeListener(org.eclipse.swt.events.DisposeListener) IAction(org.eclipse.jface.action.IAction) DisposeEvent(org.eclipse.swt.events.DisposeEvent) FocusEvent(org.eclipse.swt.events.FocusEvent) Shell(org.eclipse.swt.widgets.Shell) IHandlerService(org.eclipse.ui.handlers.IHandlerService) IContextActivation(org.eclipse.ui.contexts.IContextActivation) IHandlerActivation(org.eclipse.ui.handlers.IHandlerActivation) IContextService(org.eclipse.ui.contexts.IContextService) ActiveShellExpression(org.eclipse.ui.ActiveShellExpression) FocusListener(org.eclipse.swt.events.FocusListener) ActionHandler(org.eclipse.jface.commands.ActionHandler)

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