Example usage for org.eclipse.jface.action IContributionManager update

List of usage examples for org.eclipse.jface.action IContributionManager update

Introduction

In this page you can find the example usage for org.eclipse.jface.action IContributionManager update.

Prototype

void update(boolean force);

Source Link

Document

Updates this manager's underlying widget(s) with any changes which have been made to it or its items.

Usage

From source file:org.eclipse.ocl.examples.emf.validation.validity.ui.view.ValidityView.java

License:Open Source License

private void fillConstrainingColumnToolBar(IContributionManager manager) {
    manager.add(expandAllConstrainingNodesAction);
    manager.add(collapseAllConstrainingNodesAction);
    manager.add(new Separator());
    manager.add(enableAllConstrainingNodesAction);
    manager.add(disableAllConstrainingNodesAction);
    manager.add(new Separator());
    manager.add(disableAllUnusedConstrainingNodesAction);

    manager.update(true);
}

From source file:org.eclipse.ocl.examples.emf.validation.validity.ui.view.ValidityView.java

License:Open Source License

private void fillValidatableColumnToolBar(IContributionManager manager) {
    manager.add(expandAllValidatableNodesAction);
    manager.add(collapseAllValidatableNodesAction);
    manager.add(new Separator());
    manager.add(enableAllValidatableNodesAction);
    manager.add(disableAllValidatableNodesAction);
    manager.add(new Separator());
    manager.add(disableAllUnusedValidatableNodesAction);

    manager.update(true);
}

From source file:org.eclipse.sirius.editor.tools.api.menu.AbstractMenuBuilder.java

License:Open Source License

/**
 * Populate the menumanager with the given actions.
 * //from www .j ava2  s .c o m
 * @param manager
 *            manager to populate.
 * @param actions
 *            actions to populate.
 * @param contributionID
 *            the Id for the contribution.
 */
protected void populateManager(final IContributionManager manager, final Collection actions,
        final String contributionID) {
    if (actions != null) {
        List<IAction> sortedActions = Lists.newArrayList(Iterables.filter(actions, IAction.class));
        Comparator<IAction> comparator = new Comparator<IAction>() {
            @Override
            public int compare(IAction a1, IAction a2) {
                int diff = getPriority(a1) - getPriority(a2);
                if (diff == 0) {
                    // if both actions have no priority associated, or if
                    // they have the same priority, we compare the text
                    diff = Collator.getInstance().compare(a1.getText(), a2.getText());
                }
                return diff;
            }
        };
        Collections.sort(sortedActions, comparator);

        for (final IAction action : sortedActions) {
            if (contributionID != null) {
                manager.insertBefore(contributionID, action);
            } else {
                manager.add(action);
            }
        }
    }
    manager.update(true);
}

From source file:org.eclipse.ui.internal.ActionSetActionBars.java

License:Open Source License

/**
 * Activate / Deactivate the contributions.
 */// w  w  w . jav a2 s  .c  o m
protected void setActive(boolean set) {
    super.setActive(set);

    ICoolBarManager coolBarManager = getCastedParent().getCoolBarManager();
    if (coolBarManager == null) {
        return;
    }

    // 1. Need to set visibility for all non-adjunct actions
    if (coolItemToolBarMgr != null) {
        IContributionItem[] items = coolItemToolBarMgr.getItems();
        for (int i = 0; i < items.length; i++) {
            IContributionItem item = items[i];
            if (item instanceof PluginActionCoolBarContributionItem) {
                PluginActionCoolBarContributionItem actionSetItem = (PluginActionCoolBarContributionItem) item;
                // Only if the action set id for this contribution item is
                // the same
                // as this object
                if (actionSetItem.getActionSetId().equals(actionSetId)) {
                    item.setVisible(set);
                    coolItemToolBarMgr.markDirty();
                    if (!coolBarManager.isDirty()) {
                        coolBarManager.markDirty();
                    }
                }
            }
        }
        // Update the manager
        coolItemToolBarMgr.update(false);
        if (toolBarContributionItem != null) {
            toolBarContributionItem.update(ICoolBarManager.SIZE);
        }
    }

    // 2. Need to set visibility for all adjunct actions
    if (adjunctContributions.size() > 0) {
        for (Iterator i = adjunctContributions.iterator(); i.hasNext();) {
            IContributionItem item = (IContributionItem) i.next();
            if (item instanceof ContributionItem) {
                item.setVisible(set);
                IContributionManager manager = ((ContributionItem) item).getParent();
                manager.markDirty();
                manager.update(false);
                if (!coolBarManager.isDirty()) {
                    coolBarManager.markDirty();
                }
                item.update(ICoolBarManager.SIZE);
            }

        }

    }
}

From source file:org.eclipse.ui.internal.activities.ws.WorkbenchActivitySupport.java

License:Open Source License

/**
 * Create a new instance of this class./* w  w  w  .  j  ava 2  s .co  m*/
 */
public WorkbenchActivitySupport() {
    triggerPointManager = new TriggerPointManager();
    IExtensionTracker tracker = PlatformUI.getWorkbench().getExtensionTracker();
    tracker.registerHandler(this,
            ExtensionTracker.createExtensionPointFilter(getActivitySupportExtensionPoint()));
    mutableActivityManager = new MutableActivityManager(getTriggerPointAdvisor());
    proxyActivityManager = new ProxyActivityManager(mutableActivityManager);
    mutableActivityManager.addActivityManagerListener(new IActivityManagerListener() {

        private Set lastEnabled = new HashSet(mutableActivityManager.getEnabledActivityIds());

        /* (non-Javadoc)
         * @see org.eclipse.ui.activities.IActivityManagerListener#activityManagerChanged(org.eclipse.ui.activities.ActivityManagerEvent)
         */
        public void activityManagerChanged(ActivityManagerEvent activityManagerEvent) {
            Set activityIds = mutableActivityManager.getEnabledActivityIds();
            // only update the windows if we've not processed this new enablement state already.
            if (!activityIds.equals(lastEnabled)) {
                lastEnabled = new HashSet(activityIds);

                // abort if the workbench isn't running
                if (!PlatformUI.isWorkbenchRunning()) {
                    return;
                }

                // refresh the managers on all windows.
                final IWorkbench workbench = PlatformUI.getWorkbench();
                IWorkbenchWindow[] windows = workbench.getWorkbenchWindows();
                for (int i = 0; i < windows.length; i++) {
                    if (windows[i] instanceof WorkbenchWindow) {
                        final WorkbenchWindow window = (WorkbenchWindow) windows[i];

                        final ProgressMonitorDialog dialog = new ProgressMonitorDialog(window.getShell());

                        final IRunnableWithProgress runnable = new IRunnableWithProgress() {

                            /**
                             * When this operation should open a dialog
                             */
                            private long openTime;

                            /**
                             * Whether the dialog has been opened yet.
                             */
                            private boolean dialogOpened = false;

                            /* (non-Javadoc)
                             * @see org.eclipse.jface.operation.IRunnableWithProgress#run(org.eclipse.core.runtime.IProgressMonitor)
                             */
                            public void run(IProgressMonitor monitor) {

                                openTime = System.currentTimeMillis()
                                        + workbench.getProgressService().getLongOperationTime();

                                //two work units - updating the window bars, and updating view bars
                                monitor.beginTask(ActivityMessages.ManagerTask, 2);

                                monitor.subTask(ActivityMessages.ManagerWindowSubTask);

                                //update window managers...
                                updateWindowBars(window);
                                monitor.worked(1);

                                monitor.subTask(ActivityMessages.ManagerViewsSubTask);
                                // update all of the (realized) views in all of the pages
                                IWorkbenchPage[] pages = window.getPages();
                                for (int j = 0; j < pages.length; j++) {
                                    IWorkbenchPage page = pages[j];
                                    IViewReference[] refs = page.getViewReferences();
                                    for (int k = 0; k < refs.length; k++) {
                                        IViewPart part = refs[k].getView(false);
                                        if (part != null) {
                                            updateViewBars(part);
                                        }
                                    }
                                }
                                monitor.worked(1);

                                monitor.done();
                            }

                            /**
                             * Update the managers on the given given view.
                             * 
                             * @param part the view to update
                             */
                            private void updateViewBars(IViewPart part) {
                                IViewSite viewSite = part.getViewSite();
                                // check for badly behaving or badly initialized views
                                if (viewSite == null) {
                                    return;
                                }
                                IActionBars bars = viewSite.getActionBars();
                                IContributionManager manager = bars.getMenuManager();
                                if (manager != null) {
                                    updateManager(manager);
                                }
                                manager = bars.getToolBarManager();
                                if (manager != null) {
                                    updateManager(manager);
                                }
                                manager = bars.getStatusLineManager();
                                if (manager != null) {
                                    updateManager(manager);
                                }
                            }

                            /**
                             * Update the managers on the given window.
                             * 
                             * @param window the window to update
                             */
                            private void updateWindowBars(final WorkbenchWindow window) {
                                IContributionManager manager = window.getMenuBarManager();
                                if (manager != null) {
                                    updateManager(manager);
                                }
                                manager = window.getCoolBarManager2();
                                if (manager != null) {
                                    updateManager(manager);
                                }
                                manager = window.getToolBarManager2();
                                if (manager != null) {
                                    updateManager(manager);
                                }
                                manager = window.getStatusLineManager();
                                if (manager != null) {
                                    updateManager(manager);
                                }
                            }

                            /**
                             * Update the given manager in the UI thread.
                             * This may also open the progress dialog if 
                             * the operation is taking too long.
                             * 
                             * @param manager the manager to update
                             */
                            private void updateManager(final IContributionManager manager) {
                                if (!dialogOpened && System.currentTimeMillis() > openTime) {
                                    dialog.open();
                                    dialogOpened = true;
                                }

                                manager.update(true);
                            }
                        };

                        // don't open the dialog by default - that'll be
                        // handled by the runnable if we take too long
                        dialog.setOpenOnRun(false);
                        // run this in the UI thread
                        workbench.getDisplay().asyncExec(new Runnable() {

                            /* (non-Javadoc)
                             * @see java.lang.Runnable#run()
                             */
                            public void run() {
                                BusyIndicator.showWhile(workbench.getDisplay(), new Runnable() {

                                    /* (non-Javadoc)
                                     * @see java.lang.Runnable#run()
                                     */
                                    public void run() {
                                        try {
                                            dialog.run(false, false, runnable);
                                        } catch (InvocationTargetException e) {
                                            log(e);
                                        } catch (InterruptedException e) {
                                            log(e);
                                        }
                                    }
                                });
                            }
                        });
                    }
                }
            }
        }

        /**
         * Logs an error message to the workbench log.
         * 
         * @param e the exception to log
         */
        private void log(Exception e) {
            StatusUtil.newStatus(IStatus.ERROR, "Could not update contribution managers", e); //$NON-NLS-1$ 
        }
    });
}

From source file:org.eclipse.ui.menus.CommandContributionItem.java

License:Open Source License

private void updateCommandProperties(final CommandEvent commandEvent) {
    if (commandEvent.isHandledChanged()) {
        dropDownMenuOverride = null;/*from ww w .j  ava  2  s. c  om*/
    }
    Runnable update = new Runnable() {
        public void run() {
            if (commandEvent.isEnabledChanged() || commandEvent.isHandledChanged()) {
                if (visibleEnabled) {
                    IContributionManager parent = getParent();
                    if (parent != null) {
                        parent.update(true);
                    }
                }
                IHandler handler = commandEvent.getCommand().getHandler();
                if (shouldRestoreAppearance(handler)) {
                    label = contributedLabel;
                    icon = contributedIcon;
                    disabledIcon = contributedDisabledIcon;
                    hoverIcon = contributedHoverIcon;
                }
            }
            if (commandEvent.getCommand().isDefined()) {
                update(null);
            }
        }
    };
    if (display.getThread() == Thread.currentThread()) {
        update.run();
    } else {
        display.asyncExec(update);
    }
}

From source file:org.eclipse.wst.sse.ui.internal.contentoutline.ConfigurableContentOutlinePage.java

License:Open Source License

/**
 * Configures (or reconfigures) the page according to the given
 * configuration./*from   w w  w . ja va  2 s .  c  o  m*/
 * 
 * @param configuration
 */
public void setConfiguration(ContentOutlineConfiguration configuration) {
    // intentionally do not check to see if the new configuration != old
    // configuration
    if (getTreeViewer() != null) {
        // remove the key listeners
        if (getControl() != null && !getControl().isDisposed()) {
            KeyListener[] listeners = getConfiguration().getKeyListeners(getTreeViewer());
            if (listeners != null) {
                for (int i = 0; i < listeners.length; i++) {
                    getControl().removeKeyListener(listeners[i]);
                }
            }
        }

        IContributionManager toolbar = getSite().getActionBars().getToolBarManager();
        if (toolbar != null) {
            IContributionItem[] toolbarItems = getConfiguration().getToolbarContributions(getTreeViewer());
            if (toolbarItems != null && toolbarItems.length > 0) {
                for (int i = 0; i < toolbarItems.length; i++) {
                    toolbar.remove(toolbarItems[i]);
                }
                toolbar.update(false);
            }
        }

        IContributionManager menubar = getSite().getActionBars().getMenuManager();
        if (menubar != null) {
            IContributionItem[] menuItems = getConfiguration().getMenuContributions(getTreeViewer());
            if (menuItems != null && menuItems.length > 0) {
                for (int i = 0; i < menuItems.length; i++) {
                    menubar.remove(menuItems[i]);
                }
                menubar.remove(IWorkbenchActionConstants.MB_ADDITIONS);
                menubar.update(false);
            }
        }
        // clear the DnD listeners and transfer types
        if (fDragAdapter != null && !fDragAdapter.isEmpty() && fDragSource != null && !fDragSource.isDisposed()
                && fDragSource.getTransfer().length > 0) {
            if (fActiveDragListeners != null) {
                for (int i = 0; i < fActiveDragListeners.length; i++) {
                    fDragAdapter.removeDragSourceListener(fActiveDragListeners[i]);
                }
            }
            fActiveDragListeners = null;
            fDragSource.removeDragListener(fDragAdapter);
            fDragSource.setTransfer(new Transfer[0]);
        }
        if (fDropAdapter != null && !fDropAdapter.isEmpty() && fDropTarget != null && !fDropTarget.isDisposed()
                && fDropTarget.getTransfer().length > 0) {
            if (fActiveDropListeners != null) {
                for (int i = 0; i < fActiveDropListeners.length; i++) {
                    fDropAdapter.removeDropTargetListener(fActiveDropListeners[i]);
                }
            }
            fActiveDropListeners = null;
            fDropTarget.removeDropListener(fDropAdapter);
            fDropTarget.setTransfer(new Transfer[0]);
        }
        getConfiguration().getContentProvider(getTreeViewer()).inputChanged(getTreeViewer(), fInput, null);
        // release any ties to this tree viewer
        getConfiguration().unconfigure(getTreeViewer());
    }

    fConfiguration = configuration;

    if (getTreeViewer() != null && getControl() != null && !getControl().isDisposed()) {
        // (re)set the providers
        getTreeViewer().setLabelProvider(getConfiguration().getLabelProvider(getTreeViewer()));
        getTreeViewer().setContentProvider(getConfiguration().getContentProvider(getTreeViewer()));

        // view toolbar
        IContributionManager toolbar = getSite().getActionBars().getToolBarManager();
        if (toolbar != null) {
            IContributionItem[] toolbarItems = getConfiguration().getToolbarContributions(getTreeViewer());
            if (toolbarItems != null) {
                for (int i = 0; i < toolbarItems.length; i++) {
                    toolbar.add(toolbarItems[i]);
                }
                toolbar.update(true);
            }
        }
        // view menu
        IContributionManager menu = getSite().getActionBars().getMenuManager();
        if (menu != null) {
            IContributionItem[] menuItems = getConfiguration().getMenuContributions(getTreeViewer());
            if (menuItems != null) {
                for (int i = 0; i < menuItems.length; i++) {
                    menuItems[i].setVisible(true);
                    menu.add(menuItems[i]);
                    menuItems[i].update();
                }
                menu.update(true);
            }
        }
        // add the allowed DnD listeners and types
        TransferDragSourceListener[] dragListeners = getConfiguration()
                .getTransferDragSourceListeners(getTreeViewer());
        if (fDragAdapter != null && dragListeners.length > 0) {
            for (int i = 0; i < dragListeners.length; i++) {
                fDragAdapter.addDragSourceListener(dragListeners[i]);
            }
            fActiveDragListeners = dragListeners;
            fDragSource.addDragListener(fDragAdapter);
            fDragSource.setTransfer(fDragAdapter.getTransfers());
        }
        TransferDropTargetListener[] dropListeners = getConfiguration()
                .getTransferDropTargetListeners(getTreeViewer());
        if (fDropAdapter != null && dropListeners.length > 0) {
            for (int i = 0; i < dropListeners.length; i++) {
                fDropAdapter.addDropTargetListener(dropListeners[i]);
            }
            fActiveDropListeners = dropListeners;
            fDropTarget.addDropListener(fDropAdapter);
            fDropTarget.setTransfer(fDropAdapter.getTransfers());
        }
        // add the key listeners
        KeyListener[] listeners = getConfiguration().getKeyListeners(getTreeViewer());
        if (listeners != null) {
            for (int i = 0; i < listeners.length; i++) {
                getControl().addKeyListener(listeners[i]);
            }
        }
    }

    if (fInput != null) {
        setInput(fInput);
    }
}

From source file:org.eclipsetrader.directa.internal.ui.StatusLineContributionItem.java

License:Open Source License

/**
 * Sets the text to be displayed in the status line.
 *
 * @param text// ww w.ja  va 2 s .c  om
 *            the text to be displayed, must not be <code>null</code>
 */
public void setText(String text) {
    Assert.isNotNull(text);

    this.text = escape(text);

    if (label != null && !label.isDisposed()) {
        label.setText(this.text);
    }

    if (this.text.length() == 0) {
        if (isVisible()) {
            setVisible(false);
            IContributionManager contributionManager = getParent();

            if (contributionManager != null) {
                contributionManager.update(true);
            }
        }
    } else {
        if (!isVisible()) {
            setVisible(true);
            IContributionManager contributionManager = getParent();

            if (contributionManager != null) {
                contributionManager.update(true);
            }
        }
    }
}

From source file:org.eclipsetrader.directa.internal.ui.StatusLineContributionItem.java

License:Open Source License

/**
 * Sets the image to be displayed in the status line.
 *
 * @param image// w  w  w. ja va  2s .co m
 *            the image to be displayed
 */
public void setImage(Image image) {
    this.image = image;

    if (label != null && !label.isDisposed()) {
        label.setImage(this.image);
    }

    if (!isVisible()) {
        setVisible(true);
        IContributionManager contributionManager = getParent();

        if (contributionManager != null) {
            contributionManager.update(true);
        }
    }
}

From source file:org.jboss.tools.internal.deltacloud.ui.utils.WorkbenchUtils.java

License:Open Source License

/**
 * Register the given ContributionManager with the given id. The
 * contribution manager gets unregistered on control disposal.
 * //w  ww . j a  va2s  .c o  m
 * @param id
 *            the id
 * @param contributionManager
 *            the contribution manager
 * @param control
 *            the control
 * 
 * @see ContributionManager
 * @see IMenuService
 * @see DisposeListener
 */
public static void registerContributionManager(final String id, final IContributionManager contributionManager,
        final Control control) {
    Assert.isNotNull(id);
    Assert.isNotNull(contributionManager);
    Assert.isTrue(control != null && !control.isDisposed());

    final IMenuService menuService = (IMenuService) PlatformUI.getWorkbench().getService(IMenuService.class);
    menuService.populateContributionManager((ContributionManager) contributionManager, id);
    contributionManager.update(true);
    control.addDisposeListener(new DisposeListener() {
        public void widgetDisposed(DisposeEvent e) {
            menuService.releaseContributions((ContributionManager) contributionManager);
        }
    });
}