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

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

Introduction

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

Prototype

void update(boolean force);

Source Link

Document

Updates this manager's underlying widget(s) with any changes which have been made to it or its items.

Usage

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 av a  2  s.  c  o  m*/
 * 
 * @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.ajdt.internal.ui.visualiser.AJDTMarkupProvider.java

License:Open Source License

/**
 * Activate the markup provider. /*from   ww w  .  j  a  v  a  2  s .  com*/
 */
public void activate() {
    if (VisualiserPlugin.menu != null) {
        resetColorMemoryAction = new Action() {
            public void run() {
                resetSavedColours();
                VisualiserPlugin.refresh();
            }

        };
        resetColorMemoryAction.setImageDescriptor(AspectJImages.RESET_COLOURS.getImageDescriptor());
        resetColorMemoryAction.setText(UIMessages.ResetColorMemory);
        resetColorMemoryAction.setId(resetColorMemoryID);
        hideErrorsAction = new Action() {
            public int getStyle() {
                return IAction.AS_CHECK_BOX;
            }

            public void run() {
                hideErrors = hideErrorsAction.isChecked();
                VisualiserPlugin.refresh();
            }
        };
        hideErrorsAction.setImageDescriptor(AspectJImages.HIDE_ERRORS.getImageDescriptor());
        hideErrorsAction.setToolTipText(UIMessages.HideErrors);
        hideWarningsAction = new Action() {
            public int getStyle() {
                return IAction.AS_CHECK_BOX;
            }

            public void run() {
                hideWarnings = hideWarningsAction.isChecked();
                VisualiserPlugin.refresh();
            }
        };
        hideWarningsAction.setImageDescriptor(AspectJImages.HIDE_WARNINGS.getImageDescriptor());
        hideWarningsAction.setToolTipText(UIMessages.HideWarnings);
        IActionBars menuActionBars = VisualiserPlugin.menu.getViewSite().getActionBars();
        IToolBarManager toolBarManager = menuActionBars.getToolBarManager();
        toolBarManager.add(hideErrorsAction);
        toolBarManager.add(hideWarningsAction);
        toolBarManager.update(true);
        IMenuManager menuManager = menuActionBars.getMenuManager();
        menuManager.add(new Separator());
        menuManager.add(resetColorMemoryAction);
    }
}

From source file:org.eclipse.ajdt.internal.ui.visualiser.AJDTMarkupProvider.java

License:Open Source License

/**
 * Deactivate/*from ww w. j a  v a  2  s  . c o  m*/
 */
public void deactivate() {
    super.deactivate();
    if (VisualiserPlugin.menu != null) {
        IActionBars menuActionBars = VisualiserPlugin.menu.getViewSite().getActionBars();
        IToolBarManager toolBarManager = menuActionBars.getToolBarManager();
        toolBarManager.removeAll();
        toolBarManager.update(true);
        IMenuManager menuManager = menuActionBars.getMenuManager();
        menuManager.remove(resetColorMemoryID);
        menuManager.update(true);
    }
}

From source file:org.eclipse.ant.internal.ui.views.AntView.java

License:Open Source License

private void fillMainToolBar() {
    IToolBarManager toolBarMgr = getViewSite().getActionBars().getToolBarManager();
    toolBarMgr.removeAll();//from  w  w w  . ja va2 s  . com

    toolBarMgr.add(addBuildFileAction);
    toolBarMgr.add(searchForBuildFilesAction);
    toolBarMgr.add(filterInternalTargetsAction);

    toolBarMgr.add(runTargetAction);
    toolBarMgr.add(removeProjectAction);
    toolBarMgr.add(removeAllAction);

    toolBarMgr.update(false);
}

From source file:org.eclipse.buildship.ui.view.execution.ExecutionPage.java

License:Open Source License

private void populateToolBar() {
    IActionBars actionBars = getSite().getActionBars();
    IToolBarManager toolbarManager = actionBars.getToolBarManager();
    toolbarManager.appendToGroup(MultiPageView.PAGE_GROUP,
            new ExpandTreeNodesAction(getPageControl().getViewer()));
    toolbarManager.appendToGroup(MultiPageView.PAGE_GROUP,
            new CollapseTreeNodesAction(getPageControl().getViewer()));
    toolbarManager.appendToGroup(MultiPageView.PAGE_GROUP, new ShowFilterAction(getPageControl()));
    toolbarManager.appendToGroup(MultiPageView.PAGE_GROUP, new Separator());
    toolbarManager.appendToGroup(MultiPageView.PAGE_GROUP, new SwitchToConsoleViewAction(this));
    toolbarManager.appendToGroup(MultiPageView.PAGE_GROUP, new Separator());
    toolbarManager.appendToGroup(MultiPageView.PAGE_GROUP, new RerunFailedTestsAction(this));
    toolbarManager.appendToGroup(MultiPageView.PAGE_GROUP, new Separator());
    toolbarManager.appendToGroup(MultiPageView.PAGE_GROUP, new CancelBuildExecutionAction(this));
    toolbarManager.appendToGroup(MultiPageView.PAGE_GROUP, new RerunBuildExecutionAction(this));
    toolbarManager.appendToGroup(MultiPageView.PAGE_GROUP, new RemoveTerminatedExecutionPageAction(this));
    toolbarManager.appendToGroup(MultiPageView.PAGE_GROUP, new RemoveAllTerminatedExecutionPagesAction(this));
    toolbarManager.update(true);
}

From source file:org.eclipse.cdt.visualizer.ui.VisualizerView.java

License:Open Source License

/** Updates tab name, toolbar, etc. from viewer. */
public void updateUI() {

    // Update tab name/tooltip
    // TODO: internationalize these default strings
    String name = "Visualizer View";
    String description = "Displays visualizations of launches.";
    if (m_viewer != null) {
        name = m_viewer.getVisualizerDisplayName();
        description = m_viewer.getVisualizerDescription();

    }/*from   w  ww. j a  v  a2  s  .  co m*/
    setTabName(name);
    setTabDescription(description);

    // Update toolbar & toolbar menu
    if (m_viewer != null) {
        IActionBars actionBars = getViewSite().getActionBars();

        // Allow presentation to set the displayed toolbar content, if any
        IToolBarManager toolBarManager = actionBars.getToolBarManager();
        toolBarManager.removeAll();
        m_viewer.populateToolBar(toolBarManager);
        toolBarManager.update(true);

        // Allow presentation to set the toolbar's menu content, if any
        IMenuManager menuManager = actionBars.getMenuManager();
        menuManager.removeAll();
        m_viewer.populateMenu(menuManager);
        menuManager.update(true);

        // Note: when context menu is invoked,
        // the poplateContextMenu() method is called by the view,
        // which in turn delegates to the current visualizer
        // to populate the context menu.

        // Propagate the changes
        actionBars.updateActionBars();
    }
}

From source file:org.eclipse.compare.internal.win32.WordMergeViewer.java

License:Open Source License

private void initializeToolbar(IToolBarManager toolBarManager) {
    toolBarManager.add(new Separator("modes")); //$NON-NLS-1$
    toolBarManager.add(new Separator("file")); //$NON-NLS-1$
    CompareConfiguration configuration = getConfiguration();
    // For now, only support saving if one side is editable
    if (configuration.isRightEditable() || configuration.isLeftEditable()
            && (configuration.isRightEditable() != configuration.isLeftEditable())) {
        saveAction = new Action() {
            public void run() {
                saveDocument();//from   ww  w .j av a 2  s .  com
            }
        };
        initAction(saveAction, getResourceBundle(), "action.save."); //$NON-NLS-1$
        toolBarManager.appendToGroup("file", saveAction); //$NON-NLS-1$
    }

    inplaceAction = new Action(CompareWin32Messages.WordMergeViewer_2, Action.AS_CHECK_BOX) {
        public void run() {
            toggleInplaceExternalState();
        }
    };
    initAction(inplaceAction, getResourceBundle(), "action.inplace."); //$NON-NLS-1$
    toolBarManager.appendToGroup("modes", inplaceAction); //$NON-NLS-1$

    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.
 * //  w ww  .j  ava 2s.  c om
 * @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.eclipsemonkey.ui.scriptableView.BrowserView.java

License:Open Source License

/*******************************************************************************************************************
 * Pulled from BrowserIntroPartImplementation
 ******************************************************************************************************************/

protected void addToolBarActions() {

    IActionBars actionBars = getViewSite().getActionBars();

    IToolBarManager toolBarManager = actionBars.getToolBarManager();
    actionBars.setGlobalActionHandler(ActionFactory.FORWARD.getId(), forwardAction);
    actionBars.setGlobalActionHandler(ActionFactory.BACK.getId(), backAction);
    toolBarManager.add(homeAction);/*from   ww w  .  j a v a2s.c om*/
    toolBarManager.add(backAction);
    toolBarManager.add(forwardAction);
    toolBarManager.update(true);
    actionBars.updateActionBars();
    updateNavigationActionsState();
}

From source file:org.eclipse.edt.ide.rui.visualeditor.internal.editor.EvEditorOutlinePage.java

License:Open Source License

/**
 * Called by the editor to show the outline page denoted by the static constant as defined above.
 *///from   w w w  .  jav a2s .  c o  m
public void showPage(int iPage) {
    if (_pageBook != null) {
        switch (iPage) {
        case DESIGN_PAGE:
            _pageBook.showPage(_controlDesign);
            break;
        case SOURCE_PAGE:
            _pageBook.showPage(_controlSource);
            break;
        case PREVIEW_PAGE:
            _pageBook.showPage(_controlPrevew);
            break;
        }
    }

    // Set the visibility of the source page's outline view tool bar controls
    // based on the page that is about to be shown
    //-----------------------------------------------------------------------
    IActionBars actionBars = getSite().getActionBars();
    if (actionBars == null)
        return;

    IToolBarManager toolBarManager = actionBars.getToolBarManager();
    if (toolBarManager == null)
        return;

    IContributionItem[] items = toolBarManager.getItems();
    if (items == null)
        return;

    for (int i = 0; i < items.length; ++i)
        items[i].setVisible(iPage == SOURCE_PAGE);

    toolBarManager.update(true);
}