Example usage for org.eclipse.jface.action ToolBarContributionItem getId

List of usage examples for org.eclipse.jface.action ToolBarContributionItem getId

Introduction

In this page you can find the example usage for org.eclipse.jface.action ToolBarContributionItem getId.

Prototype

@Override
    public String getId() 

Source Link

Usage

From source file:com.nokia.tools.screen.ui.editor.BaseEditorContributor.java

License:Open Source License

@Override
public void dispose() {
    getPage().removePartListener(this);
    if (getContentEditor() != null) {
        getContentEditor().removePropertyListener(this);
    }/* w  ww.j a v  a  2 s  . c  o m*/
    if (parentCoolBarManager != null && canDisposeCoolBarItems()) {
        for (ToolBarContributionItem item : coolBarItems) {
            IContributionItem realItem = parentCoolBarManager.find(item.getId());

            // We should not call dispose method directly, unless we
            // removed contribution item from the containing
            // IContributionManager before the contribution lifecycle
            // has ended.
            parentCoolBarManager.remove(realItem);
            if (realItem != null) {
                realItem.dispose();
            }
        }
        if (PlatformUI.getWorkbench().getActiveWorkbenchWindow() != null
                && PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() != null) {
            parentCoolBarManager.update(true);
        }
    }
    editor = null;
    super.dispose();
}

From source file:hydrograph.ui.graph.execution.tracking.utils.CoolBarHelperUtility.java

License:Apache License

/**
 * disable or enable coolbar icons/*from w  w w . ja v  a2s .com*/
 * 
 * @param enabled
 */
public void disableCoolBarIcons(boolean enabled) {
    ToolBarContributionItem toolBarContributionItem = WorkbenchWidgetsUtils.INSTANCE
            .getToolBarMangerOrMenuManagerFromCoolBar("hydrograph.ui.graph.toolbar1");
    for (IContributionItem contributionItem : toolBarContributionItem.getToolBarManager().getItems()) {
        ToolItem toolItem = WorkbenchWidgetsUtils.INSTANCE
                .getToolItemFromToolBarManger(toolBarContributionItem.getId(), contributionItem.getId());
        if (toolItem != null) {
            IWorkbenchPart partView = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage()
                    .getActivePart();
            if (!((ELTGraphicalEditor) partView).getContainer().isOpenedForTracking()) {
                toolItem.getParent().setEnabled(true);
                enableSaveAs(true);
            } else {
                toolItem.getParent().setEnabled(false);
                enableSaveAs(false);
            }
            break;
        }
    }
    ToolBarContributionItem toolBarContributionItem2 = WorkbenchWidgetsUtils.INSTANCE
            .getToolBarMangerOrMenuManagerFromCoolBar(Constants.RUN_STOP_BUTTON_TOOLBAR_ID);
    for (IContributionItem contributionItem : toolBarContributionItem2.getToolBarManager().getItems()) {
        ToolItem toolItem = WorkbenchWidgetsUtils.INSTANCE
                .getToolItemFromToolBarManger(toolBarContributionItem2.getId(), contributionItem.getId());
        if (toolItem != null) {
            toolItem.getParent().setEnabled(enabled);
            break;
        }
    }
}

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

License:Open Source License

/**
 * Removes all contributions of this registry from the CoolBar of the
 * given coolBarManager. Ideally this is done by making the contributions
 * invisible, so Eclipse can remember their positions. However
 * this is currently not possible and thats why this method
 * removes the affected contributions from the CoolBar.
 * This behaviour can is configured via {@link #useRemoveInsteadOfUnvisibleWorkaround}.
 *
 * @param coolBarManager The {@link ICoolBarManager} where the contributions of this registry should be removed from.
 *//*  w ww.  ja va  2 s  .  c om*/
public void removeAllFromCoolBar(ICoolBarManager coolBarManager) {
    if (Display.getCurrent() == null)
        throw new IllegalStateException("This method must be called on the UI thread!"); //$NON-NLS-1$

    IContributionManager coolBarContributionManager = coolBarManager;
    if (coolBarManager instanceof SubCoolBarManager)
        coolBarContributionManager = ((SubCoolBarManager) coolBarManager).getParent();

    if (!useRemoveInsteadOfUnvisibleWorkaround)
        ((SubCoolBarManager) coolBarManager).setVisible(false);

    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();
    ActionVisibilityDecider backupActionVisibilityDecider = this.actionVisibilityDecider;
    try {
        this.actionVisibilityDecider = actionVisibilityDeciderAlwaysVisible;
        contribute(tmpMenu, ContributionManagerKind.coolBar);
    } finally {
        this.actionVisibilityDecider = backupActionVisibilityDecider;
    }

    // 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 = ((SubCoolBarManager)coolBarManager).getParent().getItems();
    IContributionItem[] coolBarItems = coolBarContributionManager.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);
        logger.debug("Having " + coolBarItem.getId() + " in CoolBar"); //$NON-NLS-1$ //$NON-NLS-2$
    }

    ToolBarContributionItem orphanageToolBarContributionItem = getToolBarContributionItem(
            coolBarItemMap.get(orphanageToolbarID));
    if (orphanageToolBarContributionItem != null) {
        IContributionItem item = coolBarContributionManager.find(orphanageToolBarContributionItem.getId());
        if (item != null) {
            if (useRemoveInsteadOfUnvisibleWorkaround) {
                coolBarContributionManager.remove(orphanageToolBarContributionItem.getId());
            } else {
                orphanageToolBarContributionItem.setVisible(false);
                item.setVisible(false);
            }
        }
    }

    // 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];

        // Test for items that are already in the parent
        if (tmpItem instanceof IMenuManager) {
            IMenuManager tmpSubMenu = (IMenuManager) tmpItem;
            String tmpSubMenuID = baseID + '.' + tmpSubMenu.getId();

            ToolBarContributionItem toolBarContributionItem = getToolBarContributionItem(
                    coolBarItemMap.get(tmpSubMenuID));
            if (toolBarContributionItem != null) {
                IContributionItem item = coolBarContributionManager.find(toolBarContributionItem.getId());
                if (item != null) {
                    if (useRemoveInsteadOfUnvisibleWorkaround) {
                        coolBarContributionManager.remove(tmpSubMenuID);
                    } else {
                        toolBarContributionItem.setVisible(false);
                        item.setVisible(false);
                    }
                }
            }
        }
    }

    try {
        coolBarContributionManager.update(true);
    } catch (Exception x) {
        // https://bugs.eclipse.org/bugs/show_bug.cgi?id=239945
        logger.error("CoolBarManager.update failed: " + x.getLocalizedMessage(), x); //$NON-NLS-1$
    }
}