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

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

Introduction

In this page you can find the example usage for org.eclipse.jface.action ICoolBarManager prependToGroup.

Prototype

void prependToGroup(String groupName, IAction action);

Source Link

Document

Adds a contribution item for the given action at the beginning of the group with the given name.

Usage

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

License:Open Source License

/**
 * Returns the tool bar manager. If items are added or removed from the
 * manager be sure to call <code>updateActionBars</code>. Overridden to
 * support CoolBars./*from  w  w  w .  jav  a  2s . co m*/
 * 
 * @return the tool bar manager
 */
public IToolBarManager getToolBarManager() {

    // by pass the sub coolBar and use the real cool bar.
    ICoolBarManager coolBarManager = getCastedParent().getCoolBarManager();
    if (coolBarManager == null) {
        return null;
    }

    // add the editor group if the app did not add it already,
    // otherwise the references to it below will fail
    if (coolBarManager.find(IWorkbenchActionConstants.GROUP_EDITOR) == null) {
        coolBarManager.add(new GroupMarker(IWorkbenchActionConstants.GROUP_EDITOR));
    }
    if (toolBarContributionItem == null) {
        IContributionItem foundItem = coolBarManager.find(type);
        if ((foundItem instanceof IToolBarContributionItem)) {
            toolBarContributionItem = (IToolBarContributionItem) foundItem;
            coolItemToolBarMgr = toolBarContributionItem.getToolBarManager();
            if (coolItemToolBarMgr == null) {
                coolItemToolBarMgr = new ToolBarManager2(SWT.FLAT);
                toolBarContributionItem = new ToolBarContributionItem2(coolItemToolBarMgr, type);
                // Add editor item to group
                coolBarManager.prependToGroup(IWorkbenchActionConstants.GROUP_EDITOR, toolBarContributionItem);
            }
        } else {
            coolItemToolBarMgr = new ToolBarManager2(SWT.FLAT);
            if ((coolBarManager instanceof ContributionManager)
                    && (foundItem instanceof PlaceholderContributionItem)) {
                PlaceholderContributionItem placeholder = (PlaceholderContributionItem) foundItem;
                toolBarContributionItem = createToolBarContributionItem(coolItemToolBarMgr, placeholder);
                // Restore from a placeholder
                ((ContributionManager) coolBarManager).replaceItem(type, toolBarContributionItem);
            } else {
                toolBarContributionItem = new ToolBarContributionItem2(coolItemToolBarMgr, type);
                // Add editor item to group
                coolBarManager.prependToGroup(IWorkbenchActionConstants.GROUP_EDITOR, toolBarContributionItem);
            }
        }
        ((ContributionManager) coolItemToolBarMgr).setOverrides(new Overrides());
        toolBarContributionItem.setVisible(getActive());
        coolItemToolBarMgr.markDirty();
    }

    return coolItemToolBarMgr;
}