Search in sources :

Example 1 with IWorkbenchListener

use of org.eclipse.ui.IWorkbenchListener in project knime-core by knime.

the class KNIMEApplicationWorkbenchWindowAdvisor method addGlobalNodeTimerShutdownHook.

/**
 * Adds a workbench shutdown listener to write and send usage data.
 */
private void addGlobalNodeTimerShutdownHook() {
    IWorkbench wb = PlatformUI.getWorkbench();
    wb.addWorkbenchListener(new IWorkbenchListener() {

        @Override
        public boolean preShutdown(final IWorkbench workbench, final boolean forced) {
            // Write and send usage data.
            NodeTimer.GLOBAL_TIMER.performShutdown();
            // Don't interrupt regular shutdown!
            return true;
        }

        @Override
        public void postShutdown(final IWorkbench workbench) {
        /*nothing to do*/
        }
    });
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchListener(org.eclipse.ui.IWorkbenchListener)

Example 2 with IWorkbenchListener

use of org.eclipse.ui.IWorkbenchListener in project epp.mpc by eclipse.

the class MarketplaceWizardDialog method configureShell.

@Override
protected void configureShell(Shell newShell) {
    super.configureShell(newShell);
    // make jface dialog accessible for swtbot
    newShell.setData(this);
    new MarketplaceDropAdapter() {

        @Override
        protected void proceedInstallation(String url) {
            SolutionInstallationInfo info = MarketplaceUrlHandler.createSolutionInstallInfo(url);
            CatalogDescriptor catalogDescriptor = info.getCatalogDescriptor();
            String installItem = info.getInstallId();
            // we ignore previous wizard state here, since the wizard is still open...
            if (installItem != null && installItem.length() > 0) {
                info.setState(null);
                getWizard().handleInstallRequest(info, url);
            }
        }

        @Override
        protected void proceedFavorites(String url) {
            getWizard().importFavorites(url);
        }
    }.installDropTarget(newShell);
    final IWorkbenchListener workbenchListener = new IWorkbenchListener() {

        public boolean preShutdown(IWorkbench workbench, boolean forced) {
            MarketplaceWizardDialog wizardDialog = MarketplaceWizardDialog.this;
            Shell wizardShell = wizardDialog.getShell();
            if (wizardShell != null && !wizardShell.isDisposed()) {
                if (!forced) {
                    MarketplaceWizard wizard = wizardDialog.getWizard();
                    boolean hasPendingActions = false;
                    IWizardPage currentPage = wizardDialog.getCurrentPage();
                    if (currentPage != null && wizard != null) {
                        if (currentPage == wizard.getCatalogPage()) {
                            hasPendingActions = !wizard.getSelectionModel().getSelectedCatalogItems().isEmpty();
                        } else {
                            hasPendingActions = true;
                        }
                    }
                    if (hasPendingActions) {
                        Shell parentShell = activate(wizardDialog.getShell());
                        MessageDialog messageDialog = new MessageDialog(parentShell, Messages.MarketplaceWizardDialog_PromptPendingActionsTitle, null, Messages.MarketplaceWizardDialog_PromptPendingActionsMessage, MessageDialog.QUESTION_WITH_CANCEL, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL, IDialogConstants.CANCEL_LABEL }, SWT.NONE);
                        int result = messageDialog.open();
                        switch(result) {
                            case // yes
                            0:
                                finishWizard();
                                return false;
                            case // no
                            1:
                                break;
                            // cancel
                            case 3:
                            // [x]
                            case SWT.DEFAULT:
                            default:
                                return false;
                        }
                    }
                }
                if (forced) {
                    wizardShell.close();
                } else {
                    boolean closed = wizardDialog.close();
                    return closed;
                }
            }
            return true;
        }

        private void finishWizard() {
            MarketplaceWizardDialog wizardDialog = MarketplaceWizardDialog.this;
            MarketplaceWizard wizard = wizardDialog.getWizard();
            IWizardPage currentPage = wizardDialog.getCurrentPage();
            if (currentPage == wizard.getCatalogPage()) {
                ((MarketplacePage) currentPage).showNextPage();
            }
        }

        private Shell activate(Shell shell) {
            Shell activeShell = shell.getDisplay().getActiveShell();
            if (activeShell != shell) {
                Shell[] childShells = shell.getShells();
                if (childShells.length == 0 || !Arrays.asList(childShells).contains(activeShell)) {
                    shell.forceActive();
                    shell.forceFocus();
                }
            }
            if (activeShell == null) {
                activeShell = PlatformUI.getWorkbench().getDisplay().getActiveShell();
                if (activeShell == null) {
                    activeShell = shell;
                }
            }
            return activeShell;
        }

        public void postShutdown(IWorkbench workbench) {
        }
    };
    PlatformUI.getWorkbench().addWorkbenchListener(workbenchListener);
    newShell.addDisposeListener(new DisposeListener() {

        public void widgetDisposed(DisposeEvent e) {
            PlatformUI.getWorkbench().removeWorkbenchListener(workbenchListener);
        }
    });
    if (newShell.getParent() == null) {
        // bug 500379 - root shells don't handle escape traversal by default
        newShell.addTraverseListener(new TraverseListener() {

            public void keyTraversed(TraverseEvent e) {
                if (e.keyCode == SWT.ESC) {
                    Shell shell = (Shell) e.widget;
                    if (shell != null && !shell.isDisposed() && shell.isVisible() && shell.isEnabled()) {
                        shell.close();
                    }
                }
            }
        });
    }
}
Also used : IWorkbenchListener(org.eclipse.ui.IWorkbenchListener) DisposeListener(org.eclipse.swt.events.DisposeListener) TraverseEvent(org.eclipse.swt.events.TraverseEvent) TraverseListener(org.eclipse.swt.events.TraverseListener) DisposeEvent(org.eclipse.swt.events.DisposeEvent) IWorkbench(org.eclipse.ui.IWorkbench) Shell(org.eclipse.swt.widgets.Shell) SolutionInstallationInfo(org.eclipse.epp.mpc.ui.MarketplaceUrlHandler.SolutionInstallationInfo) IWizardPage(org.eclipse.jface.wizard.IWizardPage) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) CatalogDescriptor(org.eclipse.epp.mpc.ui.CatalogDescriptor)

Example 3 with IWorkbenchListener

use of org.eclipse.ui.IWorkbenchListener in project mdw-designer by CenturyLinkCloud.

the class WorkflowAssetFactory method deRegisterWorkbenchListener.

public static void deRegisterWorkbenchListener(IFile file) {
    if (workbenchListeners != null) {
        IWorkbenchListener listener = workbenchListeners.get(file);
        if (listener != null) {
            PlatformUI.getWorkbench().removeWorkbenchListener(listener);
            workbenchListeners.remove(file);
        }
    }
}
Also used : IWorkbenchListener(org.eclipse.ui.IWorkbenchListener)

Example 4 with IWorkbenchListener

use of org.eclipse.ui.IWorkbenchListener in project azure-tools-for-java by Microsoft.

the class ContainerRegistryExplorerEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    setSite(site);
    setInput(input);
    if (input instanceof ContainerRegistryExplorerEditorInput) {
        ContainerRegistryExplorerEditorInput containerInput = (ContainerRegistryExplorerEditorInput) input;
        this.setPartName(containerInput.getName());
        this.subscriptionId = containerInput.getSubscriptionId();
        this.registryId = containerInput.getId();
        containerExplorerPresenter.onGetRegistryProperty(containerInput.getSubscriptionId(), containerInput.getId());
    }
    IWorkbench workbench = PlatformUI.getWorkbench();
    final IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
    workbench.addWorkbenchListener(new IWorkbenchListener() {

        @Override
        public boolean preShutdown(IWorkbench workbench, boolean forced) {
            activePage.closeEditor(ContainerRegistryExplorerEditor.this, true);
            return true;
        }

        @Override
        public void postShutdown(IWorkbench workbench) {
        }
    });
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchListener(org.eclipse.ui.IWorkbenchListener) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Example 5 with IWorkbenchListener

use of org.eclipse.ui.IWorkbenchListener in project azure-tools-for-java by Microsoft.

the class RedisExplorerEditor method init.

@Override
public void init(IEditorSite site, IEditorInput input) throws PartInitException {
    setSite(site);
    setInput(input);
    if (input instanceof RedisExplorerEditorInput) {
        RedisExplorerEditorInput redisInput = (RedisExplorerEditorInput) input;
        this.redisExplorerPresenter.initializeResourceData(redisInput.getSubscriptionId(), redisInput.getId());
        this.setPartName(redisInput.getRedisName());
        this.redisExplorerPresenter.onReadDbNum();
    }
    IWorkbench workbench = PlatformUI.getWorkbench();
    final IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
    workbench.addWorkbenchListener(new IWorkbenchListener() {

        public boolean preShutdown(IWorkbench workbench, boolean forced) {
            activePage.closeEditor(RedisExplorerEditor.this, true);
            return true;
        }

        public void postShutdown(IWorkbench workbench) {
        }
    });
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) IWorkbenchListener(org.eclipse.ui.IWorkbenchListener) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage)

Aggregations

IWorkbenchListener (org.eclipse.ui.IWorkbenchListener)9 IWorkbench (org.eclipse.ui.IWorkbench)8 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)4 TaskVO (com.centurylink.mdw.model.value.task.TaskVO)1 WorkflowSelectionProvider (com.centurylink.mdw.plugin.designer.WorkflowSelectionProvider)1 WorkflowPackage (com.centurylink.mdw.plugin.designer.model.WorkflowPackage)1 WorkflowProject (com.centurylink.mdw.plugin.project.model.WorkflowProject)1 TaskTemplateDocument (com.centurylink.mdw.task.TaskTemplateDocument)1 IFile (org.eclipse.core.resources.IFile)1 CatalogDescriptor (org.eclipse.epp.mpc.ui.CatalogDescriptor)1 SolutionInstallationInfo (org.eclipse.epp.mpc.ui.MarketplaceUrlHandler.SolutionInstallationInfo)1 IPageChangedListener (org.eclipse.jface.dialogs.IPageChangedListener)1 MessageDialog (org.eclipse.jface.dialogs.MessageDialog)1 PageChangedEvent (org.eclipse.jface.dialogs.PageChangedEvent)1 IWizardPage (org.eclipse.jface.wizard.IWizardPage)1 DisposeEvent (org.eclipse.swt.events.DisposeEvent)1 DisposeListener (org.eclipse.swt.events.DisposeListener)1 TraverseEvent (org.eclipse.swt.events.TraverseEvent)1 TraverseListener (org.eclipse.swt.events.TraverseListener)1 Shell (org.eclipse.swt.widgets.Shell)1