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

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

Introduction

In this page you can find the example usage for org.eclipse.jface.action ICoolBarManager 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:com.mercatis.lighthouse3.ui.application.LighthouseApplicationWorkbenchWindowAdvisor.java

License:Apache License

@Override
public void postWindowCreate() {
    super.postWindowCreate();

    //Remove some toolbar entries provides by the platform but not needed
    String[] menuItemsToRemove = new String[] { "org.eclipse.ui.edit.text.actionSet.navigation",
            "org.eclipse.ui.edit.text.actionSet.annotationNavigation", "org.eclipse.search.searchActionSet" };

    ICoolBarManager coolBarManager = getWindowConfigurer().getActionBarConfigurer().getCoolBarManager();
    for (String menuItem : menuItemsToRemove) {
        coolBarManager.remove(menuItem);
    }//from  www.j  av a 2 s . c om
    coolBarManager.update(true);

    // close all projects on startup
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (IProject project : projects) {
        try {
            project.close(new NullProgressMonitor());
        } catch (CoreException e) {
        }
    }
}

From source file:gov.nasa.ensemble.core.rcp.EnsembleWorkbenchWindowAdvisor.java

License:Open Source License

protected void cleanupMenusAndCoolBar() {
    IContributionItem[] mItems, mSubItems;
    IMenuManager mm = getWindowConfigurer().getActionBarConfigurer().getMenuManager();
    mItems = mm.getItems();/*from  w  ww  .j  a va 2 s.  c o  m*/
    for (int i = 0; i < mItems.length; i++) {
        if (mItems[i] instanceof MenuManager) {
            mSubItems = ((MenuManager) mItems[i]).getItems();
            for (int j = 0; j < mSubItems.length; j++) {
                if (getItemsToRemove().keySet().contains(mItems[i].getId())) {
                    for (String fileItemToRemove : getItemsToRemove().get(mItems[i].getId()))
                        ((MenuManager) mItems[i]).remove(fileItemToRemove);
                }
            }
        }
    }
    if (getItemsToRemove().keySet().contains("file")) {
        ICoolBarManager cbm = getWindowConfigurer().getActionBarConfigurer().getCoolBarManager();
        for (String itemToRemove : getItemsToRemove().get("file")) {
            for (IContributionItem item : cbm.getItems()) {
                if (item instanceof ToolBarContributionItem)
                    ((ToolBarContributionItem) item).getToolBarManager().remove(itemToRemove);
                else
                    cbm.remove(itemToRemove);
            }
        }
        cbm.update(true);
    }
}

From source file:org.csstudio.display.builder.rcp.RCPHacks.java

License:Open Source License

/** Remove toolbar and menu entries unrelated to the display builder
 *  @param page {@link IWorkbenchPage}//  w w  w  . j ava 2 s .  c o  m
 */
public static void hideUnrelatedUI(final IWorkbenchPage page) {
    // Hide BOY "Top Files" tool bar drop-down
    page.hideActionSet("org.csstudio.opibuilder.actionSet");
    // Hide "Search" (git, file) from tool bar
    page.hideActionSet("org.eclipse.search.searchActionSet");

    if (!(page.getWorkbenchWindow() instanceof WorkbenchWindow))
        return;
    final WorkbenchWindow window = (WorkbenchWindow) page.getWorkbenchWindow();

    final ICoolBarManager toolbar = window.getCoolBarManager2();
    for (IContributionItem item : toolbar.getItems()) {
        // System.out.println(item.getId());
        if (remove_from_toolbar.contains(item.getId())) { // Result of trial-and-error:
                                                          // * item.setVisible(false) has no effect
                                                          // * toolbar.remove(item) results in
                                                          //   Error disposing widget for : org.eclipse.e4.ui.model.application.ui.menu.impl.ToolBarImpl
                                                          //     java.lang.NullPointerException
                                                          //     at org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer.cleanUpCopy(ToolBarManagerRenderer.java:554)
                                                          //     at org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer.cleanUp(ToolBarManagerRenderer.java:534)
                                                          //     at org.eclipse.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer$4.widgetDisposed(ToolBarManagerRenderer.java:423
                                                          // * disposing the item without removing it from the toolbar "works" ?!
            item.dispose();
        }
    }
    toolbar.update(true);

    patchMenu(window);
}

From source file:org.neo4j.neoclipse.ApplicationWindowAdvisor.java

License:Apache License

@Override
public void postWindowOpen() {
    super.postWindowOpen();
    IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
    ICoolBarManager coolBar = configurer.getActionBarConfigurer().getCoolBarManager();
    coolBar.removeAll();/*from  w  ww . j a  v  a  2 s.c o  m*/
    actionBarAdvisor.fillCoolBar(coolBar);
    coolBar.update(true);
}

From source file:org.netxms.ui.eclipse.console.preferencepages.WorkbenchGeneralPrefs.java

License:Open Source License

@Override
public boolean performOk() {
    Activator.getDefault().getPreferenceStore().setValue("SHOW_HIDDEN_ATTRIBUTES", //$NON-NLS-1$
            cbShowHiddenAttributes.getSelection());
    Activator.getDefault().getPreferenceStore().setValue("SHOW_SERVER_CLOCK", cbShowServerClock.getSelection()); //$NON-NLS-1$

    ICoolBarManager coolBar = (ICoolBarManager) ConsoleSharedData.getProperty("CoolBarManager"); //$NON-NLS-1$
    coolBar.remove(ServerClockContributionItem.ID);
    if (cbShowServerClock.getSelection()) {
        coolBar.add(new ServerClockContributionItem());
        coolBar.update(true);
        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell().layout(true, true);
    } else {//from   www .ja  v  a2s  .c  om
        coolBar.update(true);
    }

    return super.performOk();
}

From source file:org.nightlabs.base.ui.action.registry.AbstractActionRegistry.java

License:Open Source License

/**
 * @param coolBarManager/* ww  w  .  j  av a  2  s  .c o m*/
 * @return Returns the number of visible items (i.e. actions) that have been added (because some
 *      might be invisible and therefore not added).
 */
public Map<Class<? extends ItemDescriptor>, List<ItemDescriptor>> contributeToCoolBar(
        ICoolBarManager coolBarManager) {
    if (coolBarManager instanceof SubContributionManager)
        ((SubCoolBarManager) coolBarManager).setVisible(true);

    String baseID = this.getClass().getName();
    String orphanageToolbarID = baseID + '.' + ORPHANAGE_TOOLBAR_ID;

    // We use a temporary MenuManager which will be translated into the real
    // coolbar afterwards.
    MenuManager tmpMenu = new MenuManager();
    Map<Class<? extends ItemDescriptor>, List<ItemDescriptor>> res = contribute(tmpMenu,
            ContributionManagerKind.coolBar);

    // all contributionItems with these IDs must not be added to the orphanage menu but directly
    // to the coolbar
    // TODO this should be somehow cached
    Set<String> additions_contributionItemIDs = new HashSet<String>();
    additions_contributionItemIDs.add("additions"); // additions itself must not end up in orphanage menu //$NON-NLS-1$
    for (ActionDescriptor actionDescriptor : getActionDescriptors()) {
        if ("additions".equals(actionDescriptor.getToolbarPath())) //$NON-NLS-1$
            additions_contributionItemIDs.add(actionDescriptor.getID());
    }

    // convert the existing items of the real coolbar-manager into a Map - the new items might
    // already exist because of Eclipse's workspace memory (and then the old ones need to be
    // manipulated - new ones would be ignored because of a bug/feature in the EclipseRCP)
    IContributionItem[] coolBarItems = null;
    if (coolBarManager instanceof SubCoolBarManager) {
        coolBarItems = ((SubCoolBarManager) coolBarManager).getParent().getItems();
    } else if (coolBarManager instanceof IContributionManager) {
        coolBarItems = ((IContributionManager) coolBarManager).getItems();
    }
    //      IContributionItem[] coolBarItems = ((SubCoolBarManager)coolBarManager).getParent().getItems();

    // key: String itemId
    // value: IXContributionItem
    Map<String, IContributionItem> coolBarItemMap = new HashMap<String, IContributionItem>(coolBarItems.length);
    for (int i = 0; i < coolBarItems.length; ++i) {
        IContributionItem coolBarItem = coolBarItems[i];
        coolBarItemMap.put(coolBarItem.getId(), coolBarItem);
    }

    // Clean the "orphanage" toolbar which holds all those actions, that are not wrapped by a menu.
    // This toolbar does only exist, if it is needed.
    ToolBarContributionItem orphanageToolBarContributionItem = getToolBarContributionItem(
            coolBarItemMap.get(orphanageToolbarID));
    if (orphanageToolBarContributionItem != null)
        orphanageToolBarContributionItem.getToolBarManager().removeAll();

    // We need to collect all the "orphaned" actions in a menu first and at them after all the other menus.
    MenuManager orphanageMenu = new MenuManager();

    List<IContributionItem> additionsToBeAddedDirectlyToCoolBar = new ArrayList<IContributionItem>();

    // Now, we iterate all the "precompiled" items and contribute them to the coolbar
    IContributionItem[] tmpItems = tmpMenu.getItems();
    for (int i = 0; i < tmpItems.length; ++i) {
        IContributionItem tmpItem = tmpItems[i];

        // Either, we've hit a menu or an "orphaned" item
        if (tmpItem instanceof IMenuManager) {
            IMenuManager tmpSubMenu = (IMenuManager) tmpItem;
            String tmpSubMenuID = baseID + '.' + tmpSubMenu.getId();

            // find the previously existing ToolBarManager or create a new one.
            IToolBarManager toolBarManager;
            ToolBarContributionItem toolBarContributionItem = getToolBarContributionItem(
                    coolBarItemMap.get(tmpSubMenuID));
            if (toolBarContributionItem != null)
                toolBarManager = toolBarContributionItem.getToolBarManager();
            else {
                toolBarManager = new ToolBarManager();
                toolBarContributionItem = new ToolBarContributionItem(toolBarManager, tmpSubMenuID);
                toolBarContributionItem.setUseChevron(false);
                coolBarManager.add(toolBarContributionItem);
            }

            toolBarManager.removeAll();
            addFlattenedMenu(toolBarManager, tmpSubMenuID + ".separator", tmpSubMenu); //$NON-NLS-1$
        } else {
            if (additions_contributionItemIDs.contains(tmpItem.getId()))
                additionsToBeAddedDirectlyToCoolBar.add(tmpItem);
            else
                orphanageMenu.add(tmpItem);
        }
    } // for (int i = 0; i < tmpItems.length; ++i) {

    // If we have actions without menus, populate a toolbar with them.
    if (!orphanageMenu.isEmpty()) {
        IToolBarManager toolBarManager;
        orphanageToolBarContributionItem = getToolBarContributionItem(coolBarItemMap.get(orphanageToolbarID));
        if (orphanageToolBarContributionItem != null)
            toolBarManager = orphanageToolBarContributionItem.getToolBarManager();
        else {
            toolBarManager = new ToolBarManager();
            orphanageToolBarContributionItem = new ToolBarContributionItem(toolBarManager, orphanageToolbarID);
            orphanageToolBarContributionItem.setUseChevron(false);
            coolBarManager.add(orphanageToolBarContributionItem);
        }

        toolBarManager.removeAll();
        addFlattenedMenu(toolBarManager, orphanageToolbarID + ".separator", orphanageMenu); //$NON-NLS-1$
    }

    // contribute this stuff directly into the CoolBar (not a nested ToolBar).
    for (IContributionItem contributionItem : additionsToBeAddedDirectlyToCoolBar) {
        coolBarManager.add(contributionItem);
    }

    try {
        coolBarManager.update(true);
    } catch (Exception e) {
        // TODO WORKAROUND
        // sometimes at first startup an ArrayIndexOutOfBounds occurs, because
        // CoolBarManager.adjustContributionList removes first an separator and
        // afterwards also the first element, of an now empty list
        // this is an workaround for this bug
        logger.warn("Eclipse bug in coolBarManager.update(true) occured", e); //$NON-NLS-1$
    }

    //      if (coolBarManager instanceof CoolBarManager)
    //         ((CoolBarManager)coolBarManager).refresh();

    return res;
}