Example usage for org.eclipse.jface.action IToolBarManager insertAfter

List of usage examples for org.eclipse.jface.action IToolBarManager insertAfter

Introduction

In this page you can find the example usage for org.eclipse.jface.action IToolBarManager insertAfter.

Prototype

void insertAfter(String id, IAction action);

Source Link

Document

Inserts a contribution item for the given action after the item with the given id.

Usage

From source file:com.nokia.tools.ui.ide.ToolbarHider.java

License:Open Source License

private void setVisibleForListedIds(boolean visible) {
    CoolBar coolBar = getMainCoolBar();//from ww w .j a  v a2s. c om
    if (null == coolBar)
        return;
    for (CoolItem item : ((CoolBar) coolBar).getItems()) {
        if (item.getData() instanceof ToolBarContributionItem) {
            ToolBarContributionItem toolbaritem = ((ToolBarContributionItem) item.getData());

            IToolBarManager toolBarManager = toolbaritem.getToolBarManager();
            IContributionItem[] items = toolBarManager.getItems();
            for (int i = 0; i < items.length; i++) {
                if (shouldRemove(items[i])) {
                    if (items[i] instanceof Separator && !visible) {
                        // hiding separator is not enough, the actions added
                        // for the group will be shown anyway
                        RemovedGroup removed = new RemovedGroup();
                        removed.beforeId = i == 0 ? null : items[i - 1].getId();
                        removed.item = items[i];
                        removedGroups.add(removed);
                        toolBarManager.remove(items[i]);
                    } else {
                        toolBarManager.remove(items[i]);
                    }
                }
            }

            if (visible) {
                // restores the removed groups
                for (RemovedGroup group : removedGroups) {
                    if (group.beforeId != null) {
                        toolBarManager.insertAfter(group.beforeId, group.item);
                    } else {
                        toolBarManager.add(group.item);
                    }
                }
                removedGroups.clear();
            }
        }
    }
}

From source file:de.walware.ecommons.ui.mpbv.PageBookBrowserView.java

License:Open Source License

@Override
protected void contributeToActionBars(final IServiceLocator serviceLocator, final IActionBars actionBars,
        final HandlerCollection handlers) {
    super.contributeToActionBars(serviceLocator, actionBars, handlers);

    final IMenuManager menuManager = actionBars.getMenuManager();
    menuManager.add(new HandlerContributionItem(new CommandContributionItemParameter(serviceLocator, null,
            HandlerContributionItem.NO_COMMAND_ID, null, null, null, null, "Open in &external browser", null,
            null, HandlerContributionItem.STYLE_PUSH, null, false), handlers.get(OPEN_EXTERNAL_ID)));
    menuManager.add(new Separator("settings")); //$NON-NLS-1$
    menuManager.appendToGroup("settings", //$NON-NLS-1$
            new SimpleContributionItem("Preferences...", "P") {
                @Override/*  w  w  w . j  av a 2 s. c om*/
                protected void execute() throws ExecutionException {
                    final Shell shell = getSite().getShell();
                    final List<String> pageIds = new ArrayList<String>();
                    PageBookBrowserView.this.collectContextMenuPreferencePages(pageIds);
                    if (!pageIds.isEmpty() && (shell == null || !shell.isDisposed())) {
                        org.eclipse.ui.dialogs.PreferencesUtil.createPreferenceDialogOn(shell, pageIds.get(0),
                                pageIds.toArray(new String[pageIds.size()]), null).open();
                    }
                }
            });

    final IToolBarManager toolBarManager = actionBars.getToolBarManager();
    toolBarManager.insertBefore(SharedUIResources.ADDITIONS_MENU_ID, new Separator(BROWSERCONTROL_MENU_ID));
    toolBarManager
            .appendToGroup(BROWSERCONTROL_MENU_ID,
                    new HandlerContributionItem(new CommandContributionItemParameter(serviceLocator, null,
                            NAVIGATE_BACK_ID, HandlerContributionItem.STYLE_PUSH),
                            handlers.get(NAVIGATE_BACK_ID)));
    toolBarManager.appendToGroup(BROWSERCONTROL_MENU_ID,
            new HandlerContributionItem(new CommandContributionItemParameter(serviceLocator, null,
                    NAVIGATE_FORWARD_ID, HandlerContributionItem.STYLE_PUSH),
                    handlers.get(NAVIGATE_FORWARD_ID)));
    toolBarManager.insertAfter(BROWSERCONTROL_MENU_ID, new Separator(BOOKMARKS_MENU_ID));
    toolBarManager.appendToGroup(BOOKMARKS_MENU_ID,
            new SimpleContributionItem(
                    SharedUIResources.getImages().getDescriptor(SharedUIResources.LOCTOOL_FAVORITES_IMAGE_ID),
                    null, "Manage Bookmarks", null, SimpleContributionItem.STYLE_PULLDOWN) {
                @Override
                protected void execute() throws ExecutionException {
                    final ManageBookmarksDialog dialog = new ManageBookmarksDialog(PageBookBrowserView.this);
                    dialog.open();
                    fBookmarks.save();
                }

                @Override
                protected void dropDownMenuAboutToShow(final IMenuManager manager) {
                    manager.add(new HandlerContributionItem(new CommandContributionItemParameter(serviceLocator,
                            null, HandlerContributionItem.NO_COMMAND_ID, null, null, null, null,
                            "Create Bookmark", "C", null, HandlerContributionItem.STYLE_PUSH, null, false),
                            handlers.get(CREATE_BOOKMARK_ID)));
                    manager.add(new Separator());
                    manager.add(new ShowBookmarksDropdownContribution.OpenBookmarkContributionItem(
                            PageBookBrowserView.this, new BrowserBookmark("Home Page", getHomePageUrl()), null,
                            "H"));
                    manager.add(new Separator());
                    manager.add(new ShowBookmarksDropdownContribution(PageBookBrowserView.this));
                }
            });
}

From source file:de.walware.rj.eclient.graphics.PageBookRGraphicView.java

License:Open Source License

@Override
protected void contributeToActionBars(final IServiceLocator serviceLocator, final IActionBars actionBars,
        final HandlerCollection handlers) {
    super.contributeToActionBars(serviceLocator, actionBars, handlers);

    final IMenuManager menuManager = actionBars.getMenuManager();
    menuManager.add(new Separator("view"));
    final IViewDescriptor viewDescriptor = PlatformUI.getWorkbench().getViewRegistry()
            .find(getViewSite().getId());
    menuManager.add(new HandlerContributionItem(new CommandContributionItemParameter(serviceLocator, null,
            HandlerContributionItem.NO_COMMAND_ID, null, viewDescriptor.getImageDescriptor(), null, null,
            NLS.bind("Open Additional {0} View", viewDescriptor.getLabel()), "O", null,
            HandlerContributionItem.STYLE_PUSH, null, false), handlers.get(".OpenView")));
    menuManager.add(new Separator("save"));
    menuManager.add(new Separator(SharedUIResources.ADDITIONS_MENU_ID));

    menuManager.add(new Separator("settings")); //$NON-NLS-1$
    menuManager.add(new SimpleContributionItem("Preferences...", "P") {
        @Override/*  w w  w.  ja  v a  2 s  .c o m*/
        protected void execute() throws ExecutionException {
            final Shell shell = getViewSite().getShell();
            final String[] preferencePages = collectContextMenuPreferencePages();
            if (preferencePages.length > 0 && (shell == null || !shell.isDisposed())) {
                org.eclipse.ui.dialogs.PreferencesUtil
                        .createPreferenceDialogOn(shell, preferencePages[0], preferencePages, null).open();
            }
        }
    });

    final IToolBarManager toolBarManager = actionBars.getToolBarManager();
    toolBarManager.insertAfter("page_control.change_page", new PinPageAction()); //$NON-NLS-1$

    final IStatusLineManager lineManager = actionBars.getStatusLineManager();
    fPositionStatusLineItem = new StatusLineContributionItem(
            RGraphicCompositeActionSet.POSITION_STATUSLINE_ITEM_ID, 20);
    lineManager.add(fPositionStatusLineItem);
}

From source file:org.eclipse.emf.ecp.navigator.TreeView.java

License:Open Source License

private void createActions() {
    isLinkedWithEditor = getDialogSettings().getBoolean("LinkWithEditor");
    if (isLinkedWithEditor) {
        getSite().getPage().addPartListener(partListener);
    }/*w ww.ja v  a2s .  c o  m*/

    linkWithEditor = new Action("Link with editor", SWT.TOGGLE) {

        @Override
        public void run() {
            if (isLinkedWithEditor) {
                isLinkedWithEditor = false;
                getSite().getPage().removePartListener(partListener);
            } else {
                isLinkedWithEditor = true;
                getSite().getPage().addPartListener(partListener);
                IEditorPart editor = getSite().getPage().getActiveEditor();
                if (editor != null) {
                    editorActivated(editor);
                }
            }

            getDialogSettings().put("LinkWithEditor", this.isChecked());
        }

    };

    linkWithEditor.setImageDescriptor(Activator.getImageDescriptor("icons/link_with_editor.gif"));
    linkWithEditor.setToolTipText("Link with editor");
    linkWithEditor.setChecked(getDialogSettings().getBoolean("LinkWithEditor"));

    IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager();
    Separator additionsSeperator = new Separator("additions");
    additionsSeperator.setVisible(true);
    toolBarManager.add(additionsSeperator);
    toolBarManager.insertAfter("additions", linkWithEditor);

}

From source file:org.eclipse.help.ui.internal.views.SearchResultsPart.java

License:Open Source License

private void contributeToToolBar(IToolBarManager tbm) {
    /*//ww  w.  jav a  2  s  . c  o  m
     * removeAllAction = new Action() { public void run() { clearResults(); } };
     * removeAllAction.setImageDescriptor(HelpUIResources
     * .getImageDescriptor(IHelpUIConstants.IMAGE_REMOVE_ALL));
     * removeAllAction.setToolTipText("Remove all hits");
     * removeAllAction.setId("removeAll"); tbm.insertBefore("back",
     * removeAllAction); tbm.insertAfter("removeAll", new Separator());
     */

    boolean descOn = Platform.getPreferencesService().getBoolean(HelpBasePlugin.PLUGIN_ID,
            IHelpBaseConstants.P_KEY_SHOW_SEARCH_DESCRIPTION, false, null);
    boolean showCategories = Platform.getPreferencesService().getBoolean(HelpBasePlugin.PLUGIN_ID,
            IHelpBaseConstants.P_KEY_SHOW_SEARCH_CATEGORIES, false, null);
    showCategoriesAction = new Action() {
        public void run() {
            updateResultSections();
            IEclipsePreferences pref = InstanceScope.INSTANCE.getNode(HelpBasePlugin.PLUGIN_ID);
            pref.putBoolean(IHelpBaseConstants.P_KEY_SHOW_SEARCH_CATEGORIES, showCategoriesAction.isChecked());
            try {
                pref.flush();
            } catch (BackingStoreException e) {
            }
        }
    };
    showCategoriesAction
            .setImageDescriptor(HelpUIResources.getImageDescriptor(IHelpUIConstants.IMAGE_SHOW_CATEGORIES));
    showCategoriesAction.setChecked(showCategories);
    showCategoriesAction.setToolTipText(Messages.SearchResultsPart_showCategoriesAction_tooltip);
    showCategoriesAction.setId("categories"); //$NON-NLS-1$
    tbm.insertBefore("back", showCategoriesAction); //$NON-NLS-1$

    showDescriptionAction = new Action() {
        public void run() {
            updateResultSections();
            IEclipsePreferences pref = InstanceScope.INSTANCE.getNode(HelpBasePlugin.PLUGIN_ID);
            pref.putBoolean(IHelpBaseConstants.P_KEY_SHOW_SEARCH_DESCRIPTION,
                    showDescriptionAction.isChecked());
            try {
                pref.flush();
            } catch (BackingStoreException e) {
            }
        }
    };
    showDescriptionAction
            .setImageDescriptor(HelpUIResources.getImageDescriptor(IHelpUIConstants.IMAGE_SHOW_DESC));
    showDescriptionAction.setChecked(descOn);
    showDescriptionAction.setToolTipText(Messages.SearchResultsPart_showDescriptionAction_tooltip);
    showDescriptionAction.setId("description"); //$NON-NLS-1$
    tbm.insertAfter("categories", showDescriptionAction); //$NON-NLS-1$
    tbm.insertAfter("description", new Separator()); //$NON-NLS-1$
}

From source file:org.eclipse.remote.internal.console.TerminalConsolePage.java

License:Open Source License

@Override
public void init(IPageSite pageSite) {
    super.init(pageSite);
    IToolBarManager toolBarManager = pageSite.getActionBars().getToolBarManager();
    toolBarManager.insertBefore(IConsoleConstants.OUTPUT_GROUP, new GroupMarker(TOOLBAR_GROUP_ID));

    toolBarManager.appendToGroup(TOOLBAR_GROUP_ID, connectAction);
    toolBarManager.appendToGroup(TOOLBAR_GROUP_ID, disconnectAction);
    toolBarManager.appendToGroup(TOOLBAR_GROUP_ID, new ConsoleActionScrollLock(this));
    toolBarManager.appendToGroup(TOOLBAR_GROUP_ID, new CloseConsoleAction(terminalConsole));

    toolBarManager.insertAfter(TOOLBAR_GROUP_ID, new GroupMarker(CONTRIBUTIONS_GROUP_ID));

    addToolbarContributions(toolBarManager);
}

From source file:org.eclipse.sirius.diagram.ui.part.SiriusDiagramActionBarContributor.java

License:Open Source License

@Override
public void init(IActionBars bars) {
    disableActionBarUIUpdates();/*from w  w  w . j ava2s .  c  om*/

    try {
        super.init(bars);

        IToolBarManager toolBarManager = bars.getToolBarManager();
        toolBarManager.remove(ActionIds.MENU_COMPARTMENT);
        toolBarManager.remove(ActionIds.ACTION_COMPARTMENT_ALL);
        toolBarManager.remove(ActionIds.ACTION_COMPARTMENT_NONE);
        toolBarManager.remove(ActionIds.ACTION_HIDE_CONNECTION_LABELS);
        toolBarManager.remove(ActionIds.ACTION_SHOW_CONNECTION_LABELS);
        toolBarManager.remove(ActionIds.ACTION_SHOW_COMPARTMENT_TITLE);

        if (!isOldUIEnabled()) {
            // The actions create for the default GMF toolbar are no longer
            // useful. They must be removed from the toolbarManager and
            // disposed. This avoids unnecessary notifications and
            // calculations
            // on these actions.
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.CUSTOM_FONT_NAME);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.CUSTOM_FONT_COLOR);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.CUSTOM_FONT_SIZE);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_FONT_ITALIC);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_FONT_BOLD);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.CUSTOM_FILL_COLOR);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.CUSTOM_LINE_COLOR);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_MAKE_SAME_SIZE_BOTH);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_AUTOSIZE);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_COPY_APPEARANCE_PROPERTIES);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.CUSTOM_ZOOM);

            cleanOldToolBarGMFAction(toolBarManager, ActionIds.MENU_ARRANGE);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_ARRANGE_ALL);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_ARRANGE_SELECTION);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.MENU_ARRANGE_TOOLBAR);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_TOOLBAR_ARRANGE_ALL);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_TOOLBAR_ARRANGE_SELECTION);

            cleanOldToolBarGMFAction(toolBarManager, ActionIds.MENU_SELECT);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_SELECT_ALL_CONNECTIONS);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_SELECT_ALL_SHAPES);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.MENU_SELECT_TOOLBAR);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_TOOLBAR_SELECT_ALL_SHAPES);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_TOOLBAR_SELECT_ALL_CONNECTIONS);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_TOOLBAR_SELECT_ALL);

            cleanOldToolBarGMFAction(toolBarManager, ActionIds.MENU_ALIGN);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_ALIGN_BOTTOM);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_ALIGN_CENTER);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_ALIGN_LEFT);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_ALIGN_MIDDLE);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_ALIGN_RIGHT);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_ALIGN_TOP);

            cleanOldToolBarGMFAction(toolBarManager, ActionIds.MENU_ROUTER);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_ROUTER_OBLIQUE);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_ROUTER_RECTILINEAR);
            cleanOldToolBarGMFAction(toolBarManager, ActionIds.ACTION_ROUTER_TREE);
        } else {
            Bundle uiWorkbenchBundle = Platform.getBundle("org.eclipse.ui.workbench"); //$NON-NLS-1$
            Version junoStart = Version.parseVersion("3.103");
            // Version keplerStart = Version.parseVersion("3.105");

            if (uiWorkbenchBundle != null && uiWorkbenchBundle.getVersion().compareTo(junoStart) < 0) {
                // Do not reorder old ui toolbar for 4.x.
                IContributionItem arrange = toolBarManager.find(ActionIds.MENU_ARRANGE);
                IContributionItem diagram = toolBarManager.find(REFRESH_DIAGRAM);
                if (arrange != null && diagram != null) {
                    toolBarManager.remove(arrange);
                    toolBarManager.insertBefore(REFRESH_DIAGRAM, arrange);

                    IContributionItem select = toolBarManager.find(ActionIds.MENU_SELECT);
                    if (select != null) {
                        toolBarManager.remove(select);
                        toolBarManager.insertAfter(ActionIds.MENU_ARRANGE, select);

                        IContributionItem align = toolBarManager.find(ActionIds.MENU_ALIGN);
                        if (align != null) {
                            toolBarManager.remove(align);
                            toolBarManager.insertAfter(ActionIds.MENU_SELECT, align);
                            toolBarManager.insertAfter(ActionIds.MENU_ALIGN, new Separator());
                        }
                    }
                }

                IContributionItem setStyleItem = toolBarManager
                        .find(SetStyleToWorkspaceImageAction.SET_STYLE_TO_WORKSPACE_IMAGE_ACTION_ID);
                IContributionItem copyApparenceItem = toolBarManager
                        .find(ActionIds.ACTION_COPY_APPEARANCE_PROPERTIES);
                if (setStyleItem != null && copyApparenceItem != null) {
                    toolBarManager.remove(setStyleItem);
                    toolBarManager.insertBefore(ActionIds.ACTION_COPY_APPEARANCE_PROPERTIES, setStyleItem);
                }

                IContributionItem zoom = toolBarManager.find(ActionIds.CUSTOM_ZOOM);
                IContributionItem launchBehavior = toolBarManager.find(LAUNCH_BEHAVIOR);
                if (zoom != null && launchBehavior != null) {
                    toolBarManager.remove(zoom);
                    toolBarManager.insertAfter(LAUNCH_BEHAVIOR, zoom);
                }
            }
        }
    } finally {
        reenableActionBarUIUpdates();
    }
}

From source file:org.eclipse.tcf.te.ui.trees.AbstractTreeControl.java

License:Open Source License

/**
 * Create the toolbar items to be added to the toolbar. Override
 * to add the wanted toolbar items.//from   w w w . j  av  a 2  s.co  m
 * <p>
 * <b>Note:</b> The toolbar items are added from left to right.
 *
 * @param toolbarManager The toolbar to add the toolbar items too. Must not be <code>null</code>.
 */
public void createToolbarContributionItems(IToolBarManager toolbarManager) {
    toolbarManager.insertAfter("group.additions.control", new CollapseAllAction(this)); //$NON-NLS-1$
    configFilterAction = new ConfigFilterAction(this);
    toolbarManager.insertAfter("group.additions.control", configFilterAction); //$NON-NLS-1$
}

From source file:org.eclipse.tcf.te.ui.views.actions.NewActionProvider.java

License:Open Source License

@Override
public void fillActionBars(IActionBars actionBars) {
    // If none of the actions got created, there is nothing to do here
    if (newWizardCommandActionToolbar == null) {
        return;//from ww w  .j  a v a 2s .c  o  m
    }

    // Get the toolbar manager
    IToolBarManager toolbar = actionBars.getToolBarManager();

    // Check for the newWizard action in the toolbar. If found,
    // drop out immediately to avoid adding the items to the toolbar
    // again and again
    if (toolbar.find("org.eclipse.tcf.te.ui.command.newWizards") != null) { //$NON-NLS-1$
        return;
    }

    // Add the items to the toolbar
    toolbar.insertAfter(ICommonMenuConstants.GROUP_NEW, newWizardCommandActionToolbar);
}

From source file:org.eclipse.tm.te.ui.terminals.tabs.TabFolderToolbarHandler.java

License:Open Source License

/**
 * Fill in the context menu content within the given manager.
 *
 * @param manager The menu manager. Must not be <code>null</code>.
 *///from   w ww  .j  ava  2  s  .c  om
protected void doFillToolbar(IToolBarManager manager) {
    Assert.isNotNull(manager);

    // Note: For the toolbar, the actions are added from left to right!
    //       So we start with the additions marker here which is the most
    //       left contribution item.
    manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS));
    manager.add(new Separator("anchor")); //$NON-NLS-1$

    // Loop all actions and add them to the menu manager
    for (AbstractTerminalAction action : toolbarActions) {
        // Add a separator before the clear all action or if the action is a separator
        if (action instanceof TabScrollLockAction
                || (action instanceof AbstractAction && ((AbstractAction) action).isSeparator())) {
            manager.insertAfter("anchor", new Separator()); //$NON-NLS-1$
        }
        // Add the action itself
        manager.insertAfter("anchor", action); //$NON-NLS-1$
    }
}