Example usage for org.eclipse.jface.action IContributionItem setParent

List of usage examples for org.eclipse.jface.action IContributionItem setParent

Introduction

In this page you can find the example usage for org.eclipse.jface.action IContributionItem setParent.

Prototype

void setParent(IContributionManager parent);

Source Link

Document

Sets the parent manager of this item

Usage

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

License:Open Source License

/**
 * Returns the correct tool bar for the given action id. If this action is
 * an adjunct type the it returns the toolbar manager from the cool bar
 * manager.//from   w  w w . j av a2 s.com
 * 
 * @param id
 *            the id of the action
 * @return the tool bar manager
 */
public IToolBarManager getToolBarManager(String actionId) {
    // Check if a tool bar manager for an adjunct type is being requested
    String toolBarId = actionSetId;
    boolean isAdjunctType = false;
    if (!actionId.equals(actionSetId)) {
        // Adjunct type
        toolBarId = actionId;
        isAdjunctType = true;
    }

    // Rereive the cool bar manager
    ICoolBarManager coolBarManager = getCastedParent().getCoolBarManager();
    if (coolBarManager == null) {
        return null;
    }

    // Check to see that there isn't already a tool bar created
    // and the tool bar being requested is not for an adjunct action
    if ((coolItemToolBarMgr != null) && (!isAdjunctType)) {
        return coolItemToolBarMgr;
    }

    // Search for toolBarId in the cool Bar manager
    IContributionItem cbItem = coolBarManager.find(toolBarId);
    // If there hasn't been a tool bar contribution item created for this
    // tool bar
    // id then create one. Otherwise retrieve the tool bar contribution
    // item
    if (cbItem instanceof IToolBarContributionItem) {

        IToolBarContributionItem tbcbItem = (IToolBarContributionItem) cbItem;
        coolItemToolBarMgr = tbcbItem.getToolBarManager();
        // If this not an adjuct type then we can cashe the tool bar
        // contribution type
        if (!isAdjunctType) {
            toolBarContributionItem = tbcbItem;
        }
    } else {

        coolItemToolBarMgr = actionBarConfigurer.createToolBarManager();

        // If this is not an adjunct type then create a tool bar
        // contribution item
        // we don't create one for an adjunct type because another action
        // set action bars contains one

        IContributionItem toolBarContributionItem = actionBarConfigurer
                .createToolBarContributionItem(coolItemToolBarMgr, toolBarId);

        toolBarContributionItem.setParent(coolItemToolBarMgr);
        toolBarContributionItem.setVisible(getActive());
        coolItemToolBarMgr.markDirty();

        // Now add the tool bar contribution Item to the cool bar manager
        IContributionItem refItem = findAlphabeticalOrder(IWorkbenchActionConstants.MB_ADDITIONS, toolBarId,
                coolBarManager);
        if (refItem != null) {
            coolBarManager.insertAfter(refItem.getId(), toolBarContributionItem);
        } else {
            coolBarManager.add(toolBarContributionItem);
        }
    }
    return coolItemToolBarMgr;
}