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

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

Introduction

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

Prototype

IContributionItem remove(String id);

Source Link

Document

Removes and returns the contribution item with the given id from this manager.

Usage

From source file:org.dslforge.workspace.ui.BasicWorkspaceNavigatorActionGroup.java

License:Open Source License

@Override
protected void fillToolBar(IToolBarManager toolBar) {
    super.fillToolBar(toolBar);
    toolBar.remove(UP_ACTION_ID);
}

From source file:org.eclipse.acceleo.ui.interpreter.view.InterpreterView.java

License:Open Source License

/**
 * Switch this intepreter to the given language. This will also re-title and re-create the viewers of this
 * view./*from   ww w . j  a  v a 2  s.  c  om*/
 * 
 * @param selectedLanguage
 *            The language to which this interpreter should be switched.
 */
protected void selectLanguage(LanguageInterpreterDescriptor selectedLanguage) {
    if (currentLanguage == selectedLanguage) {
        return;
    }

    if (compilationThread != null && !compilationThread.isInterrupted()) {
        compilationThread.interrupt();
    }
    if (evaluationThread != null && !evaluationThread.isInterrupted()) {
        evaluationThread.interrupt();
    }

    /*
     * We need to remove all actions from the menu : it somehow freeze if we do not. The "trigger" for
     * this menu freeze is when we remove all messages from the message manager.
     */
    IContributionItem[] changeLanguageActions = getForm().getMenuManager().getItems();
    getMessageManager().removeAllMessages();

    // Dispose of the language specific actions
    IToolBarManager toolBarManager = getForm().getToolBarManager();
    IContributionItem[] items = toolBarManager.getItems();
    boolean dispose = false;
    for (int i = 0; i < items.length; i++) {
        IContributionItem item = items[i];
        if (dispose) {
            toolBarManager.remove(item);
            item.dispose();
        } else if (item instanceof Separator
                && LANGUAGE_SPECIFIC_ACTION_GROUP.equals(((Separator) item).getGroupName())) {
            dispose = true;
        }
    }

    getCurrentLanguageInterpreter().dispose();
    currentLanguageInterpreter = null;

    LanguageInterpreterDescriptor previousLanguage = getCurrentLanguageDescriptor();
    currentLanguage = selectedLanguage;

    // Change interpreter title
    getForm().setText(InterpreterMessages.getString("interpreter.view.title", //$NON-NLS-1$
            getCurrentLanguageDescriptor().getLabel()));

    // Change view's icon
    Image previousImage = null;
    if (previousLanguage != null && previousLanguage.getIcon() != null
            || getCurrentLanguageDescriptor().getIcon() != null) {
        previousImage = getTitleImage();
    }
    if (getCurrentLanguageDescriptor().getIcon() != null) {
        setTitleImage(getCurrentLanguageDescriptor().getIcon().createImage());
    } else if (previousLanguage != null && previousLanguage.getIcon() != null) {
        setTitleImage(InterpreterImages.getImageDescriptor(IInterpreterConstants.INTERPRETER_VIEW_DEFAULT_ICON)
                .createImage());
    }
    if (previousImage != null) {
        previousImage.dispose();
    }
    getForm().setImage(getTitleImage());

    if (expressionSection != null) {
        Composite expressionSectionBody = (Composite) expressionSection.getClient();
        expressionViewer.getControl().dispose();

        expressionViewer = createExpressionViewer(expressionSectionBody);
        GridData gridData = new GridData(GridData.FILL_BOTH);
        final int expressionHeight = 80;
        gridData.heightHint = expressionHeight;
        expressionViewer.getControl().setLayoutData(gridData);

        formToolkit.paintBordersFor(expressionSectionBody);

        expressionSectionBody.layout();
    }

    if (resultSection != null) {
        Composite resultSectionBody = (Composite) resultSection.getClient();
        resultViewer.getControl().dispose();

        resultViewer = createResultViewer(resultSectionBody);
        GridData gridData = new GridData(GridData.FILL_BOTH);
        resultViewer.getControl().setLayoutData(gridData);

        formToolkit.paintBordersFor(resultSectionBody);

        resultSectionBody.layout();
    }

    // Re-fill the menu now
    for (IContributionItem action : changeLanguageActions) {
        getForm().getMenuManager().add(action);
    }
    // re-fill the sections' toolbars
    populateExpressionSectionToolbar(expressionSection);
    populateResultSectionToolbar(resultSection);
    // Change the state of the link with editor action
    final IWorkbenchPage currentPage = getSite().getPage();
    if (currentPage != null) {
        IEditorPart currentEditor = currentPage.getActiveEditor();
        if (currentEditor == null) {
            linkWithEditorContextAction.setEnabled(false);
        } else {
            linkWithEditorContextAction
                    .setEnabled(getCurrentLanguageInterpreter().canLinkWithEditor(currentEditor));
        }
    } else {
        linkWithEditorContextAction.setEnabled(false);
    }
    // re-add language specific actions to the toolbar
    getCurrentLanguageInterpreter().addToolBarActions(this, toolBarManager);
    toolBarManager.update(true);
}

From source file:org.eclipse.datatools.enablement.rcp.ApplicationActionBarAdvisor.java

License:Open Source License

/**
 * Update the build actions on the toolbar and menu bar based on the current
 * state of autobuild. This method can be called from any thread.
 * //from   ww w.  j a v  a 2s.co m
 * @param immediately
 *            <code>true</code> to update the actions immediately,
 *            <code>false</code> to queue the update to be run in the
 *            event loop
 */
void updateBuildActions(boolean immediately) {
    // this can be triggered by property or resource change notifications
    Runnable update = new Runnable() {
        public void run() {
            if (isDisposed) {
                return;
            }
            IWorkspace workspace = ResourcesPlugin.getWorkspace();
            IProject[] projects = workspace.getRoot().getProjects();
            boolean enabled = BuildUtilities.isEnabled(projects, IncrementalProjectBuilder.INCREMENTAL_BUILD);
            //update menu bar actions in project menu
            buildAllAction.setEnabled(enabled);
            buildProjectAction.setEnabled(enabled);
            toggleAutoBuildAction.setChecked(workspace.isAutoBuilding());
            cleanAction.setEnabled(BuildUtilities.isEnabled(projects, IncrementalProjectBuilder.CLEAN_BUILD));

            //update the cool bar build button
            ICoolBarManager coolBarManager = getActionBarConfigurer().getCoolBarManager();
            IContributionItem cbItem = coolBarManager.find(IWorkbenchActionConstants.TOOLBAR_FILE);
            if (!(cbItem instanceof IToolBarContributionItem)) {
                // This should not happen
                IDEWorkbenchPlugin.log("File toolbar contribution item is missing"); //$NON-NLS-1$
                return;
            }
            IToolBarContributionItem toolBarItem = (IToolBarContributionItem) cbItem;
            IToolBarManager toolBarManager = toolBarItem.getToolBarManager();
            if (toolBarManager == null) {
                // error if this happens, file toolbar assumed to always exist
                IDEWorkbenchPlugin.log("File toolbar is missing"); //$NON-NLS-1$
                return;
            }
            //add the build button if build actions are enabled, and remove it otherwise
            boolean found = toolBarManager.find(buildAllAction.getId()) != null;
            if (enabled && !found) {
                toolBarManager.appendToGroup(IWorkbenchActionConstants.BUILD_GROUP, buildAllAction);
                toolBarManager.update(false);
                toolBarItem.update(ICoolBarManager.SIZE);
            } else if (buildAllAction != null && found && !enabled) {
                toolBarManager.remove(buildAllAction.getId());
                toolBarManager.update(false);
                toolBarItem.update(ICoolBarManager.SIZE);
            }
        }
    };
    if (immediately) {
        update.run();
    } else {
        // Dispatch the update to be run later in the UI thread.
        // This helps to reduce flicker if autobuild is being temporarily disabled programmatically.
        Shell shell = window.getShell();
        if (shell != null && !shell.isDisposed()) {
            shell.getDisplay().asyncExec(update);
        }
    }
}

From source file:org.eclipse.debug.internal.ui.views.launch.LaunchView.java

License:Open Source License

/**
 * Removes the toolbar actions contributed by this view from the toolbar 
 * manager.// w w w  .  j  a  va 2s.  c o  m
 * @param tbm
 */
protected void removeDebugToolbarActions(IToolBarManager tbm) {
    tbm.remove(new ActionContributionItem(getAction(RESUME)));
    tbm.remove(new ActionContributionItem(getAction(SUSPEND)));
    tbm.remove(new ActionContributionItem(getAction(TERMINATE)));
    tbm.remove(new ActionContributionItem(getAction(DISCONNECT)));

    tbm.remove(new ActionContributionItem(getAction(STEP_INTO)));
    tbm.remove(new ActionContributionItem(getAction(STEP_OVER)));
    tbm.remove(new ActionContributionItem(getAction(STEP_RETURN)));

    tbm.remove(new ActionContributionItem(getAction(DROP_TO_FRAME)));

    tbm.remove(new ActionContributionItem(getAction(TOGGLE_STEP_FILTERS)));
}

From source file:org.eclipse.eclipsemonkey.actions.RecreateMonkeyCoolbarAction.java

License:Open Source License

private void clearTheToolbar() {
    CoolBarManager manager = ((WorkbenchWindow) window).getCoolBarManager();
    if (manager != null) {
        for (Iterator iter = toolbars.values().iterator(); iter.hasNext();) {
            IToolBarManager element = (IToolBarManager) iter.next();
            IContributionItem[] items = element.getItems();
            for (int i = 0; i < items.length; i++) {
                element.remove(items[i]);
            }/*from w w  w  . ja  va  2  s  .c  o  m*/
        }
    }
}

From source file:org.eclipse.egit.ui.internal.repository.RepositoryPropertySourceProvider.java

License:Open Source License

private void checkChangeType(SourceType type) {
    // the different pages contribute different actions, so if we
    // change to a different page type, we need to clear them
    if (lastSourceType != type) {
        IToolBarManager mgr = myPage.getSite().getActionBars().getToolBarManager();
        boolean update = false;
        update = update | mgr.remove(RepositoryPropertySource.CHANGEMODEACTIONID) != null;
        update = update | mgr.remove(RepositoryPropertySource.SINGLEVALUEACTIONID) != null;
        update = update | mgr.remove(RepositoryPropertySource.EDITACTIONID) != null;
        update = update | mgr.remove(BranchPropertySource.EDITACTIONID) != null;
        if (update)
            mgr.update(false);/*from  ww  w . ja v  a 2  s  .c om*/
    }
    lastSourceType = type;
}

From source file:org.eclipse.egit.ui.internal.repository.RepositoryRemotePropertySource.java

License:Open Source License

/**
 * @param config//from   w  w  w  .j  av  a  2s. c om
 * @param remoteName
 * @param page
 *
 */
public RepositoryRemotePropertySource(StoredConfig config, String remoteName, PropertySheetPage page) {
    myConfig = config;
    myName = remoteName;
    IToolBarManager mgr = page.getSite().getActionBars().getToolBarManager();
    // we may have some contributions from the RepositoryPropertySource that
    // we should remove
    boolean update = false;
    update = update | mgr.remove(RepositoryPropertySource.CHANGEMODEACTIONID) != null;
    update = update | mgr.remove(RepositoryPropertySource.SINGLEVALUEACTIONID) != null;
    update = update | mgr.remove(RepositoryPropertySource.EDITACTIONID) != null;
    if (update)
        mgr.update(false);
}

From source file:org.eclipse.linuxtools.internal.valgrind.ui.ValgrindViewPart.java

License:Open Source License

public IValgrindToolView createDynamicContent(String description, String toolID) throws CoreException {
    setContentDescription(description);//from  w  w w  .  j a v  a  2s  .c om

    // remove tool specific toolbar controls
    IToolBarManager toolbar = getViewSite().getActionBars().getToolBarManager();
    if (dynamicActions != null) {
        for (ActionContributionItem item : dynamicActions) {
            toolbar.remove(item);
        }
    }

    // remove old view controls
    if (dynamicView != null) {
        dynamicView.dispose();
    }

    // remove old messages
    if (messages != null) {
        messagesViewer.getTreeViewer().setInput(null);
        messages = null;
    }

    for (Control child : dynamicViewHolder.getChildren()) {
        if (!child.isDisposed()) {
            child.dispose();
        }
    }

    if (toolID != null) {
        dynamicView = ValgrindUIPlugin.getDefault().getToolView(toolID);
        dynamicView.createPartControl(dynamicViewHolder);

        // create toolbar items
        IAction[] actions = dynamicView.getToolbarActions();
        if (actions != null) {
            dynamicActions = new ActionContributionItem[actions.length];
            for (int i = 0; i < actions.length; i++) {
                dynamicActions[i] = new ActionContributionItem(actions[i]);
                toolbar.appendToGroup(ValgrindUIPlugin.TOOLBAR_LOC_GROUP_ID, dynamicActions[i]);
            }
        }
    } else {
        dynamicView = null;
    }

    // remove old menu items
    IMenuManager menu = getViewSite().getActionBars().getMenuManager();
    menu.removeAll();
    // was content was created?
    hasDynamicContent = dynamicViewHolder.getChildren().length > 0;
    if (hasDynamicContent) {
        menu.add(showCoreAction);
        menu.add(showToolAction);
    }

    menu.update(true);
    toolbar.update(true);
    dynamicViewHolder.layout(true);

    return dynamicView;
}

From source file:org.eclipse.linuxtools.valgrind.ui.ValgrindViewPart.java

License:Open Source License

/**
 * Returns a refreshable view specific of a Valgrind tool.
 *
 * @param description     the content description
 * @param toolID          the Valgrind tool identifier
 * @return                the Valgrind tool view
 * @throws CoreException  the toolbar is disposed
 *///from w w  w.  j a va2 s  . c om
public IValgrindToolView createDynamicContent(String description, String toolID) throws CoreException {
    setContentDescription(description);

    // remove tool specific toolbar controls
    IToolBarManager toolbar = getViewSite().getActionBars().getToolBarManager();
    ToolBar tb = ((ToolBarManager) toolbar).getControl();
    if (tb == null || tb.isDisposed()) {
        throw new CoreException(new Status(IStatus.ERROR, RVMatchPlugin.PLUGIN_ID, "Toolbar is disposed")); //$NON-NLS-1$
    }

    if (dynamicActions != null) {
        for (ActionContributionItem item : dynamicActions) {
            toolbar.remove(item);
        }
    }

    // remove old view controls
    if (dynamicView != null) {
        dynamicView.dispose();
    }

    // remove old messages
    if (messages != null) {
        messagesViewer.getTreeViewer().setInput(null);
        messages = null;
    }

    for (Control child : dynamicViewHolder.getChildren()) {
        if (!child.isDisposed()) {
            child.dispose();
        }
    }

    if (toolID != null) {
        dynamicView = RVMatchPlugin.getDefault().getToolView(toolID);
        dynamicView.createPartControl(dynamicViewHolder);

        // create toolbar items
        IAction[] actions = dynamicView.getToolbarActions();
        if (actions != null) {
            dynamicActions = new ActionContributionItem[actions.length];
            for (int i = 0; i < actions.length; i++) {
                dynamicActions[i] = new ActionContributionItem(actions[i]);
                toolbar.appendToGroup(TOOLBAR_LOC_GROUP_ID, dynamicActions[i]);
            }
        }
    } else {
        dynamicView = null;
    }

    // remove old menu items
    IMenuManager menu = getViewSite().getActionBars().getMenuManager();
    menu.removeAll();
    // was content was created?
    hasDynamicContent = dynamicViewHolder.getChildren().length > 0;
    if (hasDynamicContent) {
        menu.add(showCoreAction);
        menu.add(showToolAction);
    }

    menu.update(true);
    toolbar.update(true);
    // Update to notify the workbench items have been changed
    getViewSite().getActionBars().updateActionBars();
    dynamicViewHolder.layout(true);

    return dynamicView;
}

From source file:org.eclipse.mylyn.internal.tasks.ui.views.TaskListView.java

License:Open Source License

public void setFocusedMode(boolean focusedMode) {
    if (this.focusedMode == focusedMode) {
        return;//from ww w .jav  a 2 s.c o  m
    }
    this.focusedMode = focusedMode;
    customDrawer.setFocusedMode(focusedMode);
    IToolBarManager manager = getViewSite().getActionBars().getToolBarManager();
    ToolBarManager toolBarManager = getToolBarManager(manager);
    try {
        if (toolBarManager != null) {
            toolBarManager.getControl().setRedraw(false);
        }
        if (focusedMode && isAutoExpandMode()) {
            manager.remove(FilterCompletedTasksAction.ID);
            manager.remove(CollapseAllAction.ID);
        } else if (manager.find(CollapseAllAction.ID) == null) {
            manager.prependToGroup(ID_SEPARATOR_CONTEXT, collapseAll);
            manager.prependToGroup(ID_SEPARATOR_CONTEXT, filterCompleteTask);
        }
        updateFilterEnablement();
        getViewSite().getActionBars().updateActionBars();
    } finally {
        if (toolBarManager != null) {
            toolBarManager.getControl().setRedraw(true);
        }
    }
}