Search in sources :

Example 1 with DataSourceToolbarHandler

use of org.jkiss.dbeaver.ui.actions.datasource.DataSourceToolbarHandler 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 2 with DataSourceToolbarHandler

use of org.jkiss.dbeaver.ui.actions.datasource.DataSourceToolbarHandler 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)

Aggregations

ExecutionEvent (org.eclipse.core.commands.ExecutionEvent)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 IExecutionListener (org.eclipse.core.commands.IExecutionListener)2 NotHandledException (org.eclipse.core.commands.NotHandledException)2 org.eclipse.ui (org.eclipse.ui)2 ICommandService (org.eclipse.ui.commands.ICommandService)2 IContextActivation (org.eclipse.ui.contexts.IContextActivation)2 IContextService (org.eclipse.ui.contexts.IContextService)2 DBRFeature (org.jkiss.dbeaver.model.runtime.features.DBRFeature)2 DBRFeatureRegistry (org.jkiss.dbeaver.model.runtime.features.DBRFeatureRegistry)2 DBSDataContainer (org.jkiss.dbeaver.model.struct.DBSDataContainer)2 ActionUtils (org.jkiss.dbeaver.ui.ActionUtils)2 ConnectionCommands (org.jkiss.dbeaver.ui.actions.datasource.ConnectionCommands)2 DataSourceToolbarHandler (org.jkiss.dbeaver.ui.actions.datasource.DataSourceToolbarHandler)2 ResultSetViewer (org.jkiss.dbeaver.ui.controls.resultset.ResultSetViewer)2 EntityEditor (org.jkiss.dbeaver.ui.editors.entity.EntityEditor)2 SQLEditor (org.jkiss.dbeaver.ui.editors.sql.SQLEditor)2 SQLEditorBase (org.jkiss.dbeaver.ui.editors.sql.SQLEditorBase)2 SQLEditorCommands (org.jkiss.dbeaver.ui.editors.sql.SQLEditorCommands)2 SQLEditorContributions (org.jkiss.dbeaver.ui.editors.sql.SQLEditorContributions)2