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

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

Introduction

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

Prototype

IContributionItem[] getItems();

Source Link

Document

Returns all contribution items known to this manager.

Usage

From source file:msi.gama.gui.navigator.GamaNavigator.java

License:Open Source License

@Override
public void createPartControl(final Composite compo) {
    this.parent = GamaToolbarFactory.createToolbars(this, compo);

    super.createPartControl(parent);
    // getCommonViewer().getControl().setLayoutData(GamaToolbarFactory.getLayoutDataForChild());
    IToolBarManager toolbar = getViewSite().getActionBars().getToolBarManager();
    for (IContributionItem item : toolbar.getItems()) {
        if (item instanceof ActionContributionItem) {
            ActionContributionItem aci = (ActionContributionItem) item;
            IAction action = aci.getAction();
            if (action instanceof LinkEditorAction) {
                link = action;//  w  w w.  jav  a2s .  c  om
                toolbar.remove(aci);
            } else if (action instanceof org.eclipse.ui.internal.navigator.actions.CollapseAllAction) {
                collapse = action;
                toolbar.remove(aci);
            }

        }
    }
    // toolbar.removeAll();
    linkItem.setSelection(link.isChecked());
    try {
        IDecoratorManager mgr = PlatformUI.getWorkbench().getDecoratorManager();
        mgr.setEnabled("msi.gama.application.date.decorator", false);
    } catch (CoreException e) {
        e.printStackTrace();
    }
}

From source file:msi.gama.lang.gaml.ui.outline.GamlOutlinePage.java

@Override
protected void configureActions() {
    super.configureActions();

    IToolBarManager tbm = getSite().getActionBars().getToolBarManager();
    toolbar.wipe(SWT.RIGHT, true);/*from   w  ww.j  a  v a  2 s  .  com*/
    for (IContributionItem item : tbm.getItems()) {
        toolbar.item(item, SWT.RIGHT);
    }
    toolbar.refresh(true);
    tbm.removeAll();
    tbm.update(true);
}

From source file:net.sourceforge.sqlexplorer.connections.ConnectionsView.java

License:Open Source License

private void refreshToolbar() {
    IToolBarManager toolbar = getViewSite().getActionBars().getToolBarManager();
    IContributionItem[] items = toolbar.getItems();
    for (IContributionItem item : items) {
        if (item instanceof ActionContributionItem) {
            ActionContributionItem contrib = (ActionContributionItem) item;
            // MOD mzhao bug 12938, Avoid a ClassCastException. 2010-05-06.
            AbstractConnectionTreeAction contibAction = null;
            IAction action = contrib.getAction();
            if (action instanceof AbstractConnectionTreeAction) {
                contibAction = (AbstractConnectionTreeAction) action;
                action.setEnabled(contibAction.isAvailable());
            }//from   ww w  . j  a  v a 2 s. c o  m
            // ~
        }
    }
}

From source file:net.yatomiya.e4.ui.workbench.renderers.swt.ToolBarManagerRenderer.java

License:Open Source License

/**
 * @param menuManager//w  w w. jav a2s.  c  o m
 * @param toolBar
 */
public void reconcileManagerToModel(IToolBarManager menuManager, MToolBar toolBar) {
    List<MToolBarElement> modelChildren = toolBar.getChildren();
    HashSet<MToolItem> oldModelItems = new HashSet<>();
    for (MToolBarElement itemModel : modelChildren) {
        if (OpaqueElementUtil.isOpaqueToolItem(itemModel)) {
            oldModelItems.add((MToolItem) itemModel);
        }
    }

    IContributionItem[] items = menuManager.getItems();
    for (int src = 0, dest = 0; src < items.length; src++, dest++) {
        IContributionItem item = items[src];
        MToolBarElement element = getToolElement(item);
        if (element == null) {
            MToolItem legacyItem = OpaqueElementUtil.createOpaqueToolItem();
            legacyItem.setElementId(item.getId());
            legacyItem.setVisible(item.isVisible());
            OpaqueElementUtil.setOpaqueItem(legacyItem, item);
            linkModelToContribution(legacyItem, item);
            modelChildren.add(dest, legacyItem);
        } else if (OpaqueElementUtil.isOpaqueToolItem(element)) {
            MToolItem legacyItem = (MToolItem) element;
            oldModelItems.remove(legacyItem);
            if (modelChildren.size() > dest) {
                if (modelChildren.get(dest) != legacyItem) {
                    modelChildren.remove(legacyItem);
                    modelChildren.add(dest, legacyItem);
                }
            } else {
                modelChildren.add(legacyItem);
            }
        }
    }

    if (!oldModelItems.isEmpty()) {
        modelChildren.removeAll(oldModelItems);
        for (MToolItem model : oldModelItems) {
            Object obj = OpaqueElementUtil.getOpaqueItem(model);
            clearModelToContribution(model, (IContributionItem) obj);
        }
    }
}

From source file:org.cloudfoundry.ide.eclipse.internal.server.ui.editor.CloudFoundryApplicationsEditorPage.java

License:Open Source License

private void createRefreshAction() {
    IToolBarManager toolBarManager = sform.getToolBarManager();

    if (toolBarManager.getItems().length > 0) {
        toolBarManager.add(new Separator());
    }/*  ww w.  jav a 2s  .c om*/

    toolBarManager.add(new RefreshApplicationEditorAction(this));

    toolBarManager.update(true);
}

From source file:org.ebayopensource.vjet.eclipse.core.test.bug.BugVerifyTests.java

License:Open Source License

/**
 * verify bug 3161/*w w  w . j a  v  a  2 s .c om*/
 * 
 * @throws Exception
 */
public void test3161() throws Exception {
    VjoEditor vjoEditor = null;
    IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    try {
        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME);
        IFile file = project.getFile("src/Bug2533.js");

        //open vjoeditor and outline view
        vjoEditor = (VjoEditor) IDE.openEditor(workbenchPage, file);
        IViewPart viewPart = workbenchPage.showView("org.eclipse.ui.views.ContentOutline");

        //verify toolbar
        IToolBarManager toolBarManager = ((PartSite) viewPart.getSite()).getActionBars().getToolBarManager();
        IContributionItem[] contributionItems = toolBarManager.getItems();

        Set<String> labelSet = new HashSet<String>();
        for (int i = 0; i < contributionItems.length; i++) {
            if (!(contributionItems[i] instanceof SubContributionItem)) {
                continue;
            }
            ActionContributionItem actionContributionItem = (ActionContributionItem) ((SubContributionItem) contributionItems[i])
                    .getInnerItem();
            String toolTip = actionContributionItem.getAction().getToolTipText();
            labelSet.add(toolTip.trim());
        }

        assertTrue("Missing:Sort", labelSet.contains("Sort"));
        assertTrue("Missing:Hide Fields", labelSet.contains("Hide Fields"));
        assertTrue("Missing:Hide Static Fields and Methods",
                labelSet.contains("Hide Static Fields and Methods"));
        assertTrue("Missing:Hide Non-Public Members", labelSet.contains("Hide Non-Public Members"));
        assertTrue("Missing:Hide Local Types", labelSet.contains("Hide Local Types"));
    } finally {
        workbenchPage.closeEditor(vjoEditor, false);
    }
}

From source file:org.ebayopensource.vjet.eclipse.core.test.bug.BugVerifyTests.java

License:Open Source License

/**
 * verify bug 3239. two steps:/* www.j a va  2s .  co m*/
 * first, invoke vjo search in FRONT-END
 * second, verify tool bar
 * 
 * @throws Exception
 */
public void test3239() throws Exception {
    //open search view
    IWorkbenchPage workbenchPage = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
    IViewPart viewPart = workbenchPage.showView("org.eclipse.search.ui.views.SearchView");

    //fetech dltk element
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME);
    IFile file = project.getFile("src/Bug3239.js");
    ISourceModule sourceModule = getSourceModule(file.getFullPath().toString());

    IModelElement[] modelElements = ((ICodeAssist) sourceModule).codeSelect(131, 0);
    if (modelElements.length == 0)
        assertTrue("can not fetch dltk element", false);

    //create search query
    ISearchQueryFactory queryFactory = DLTKUILanguageManager.getSearchQueryFactory(VjoNature.NATURE_ID);
    ISearchQuery query = queryFactory.createQuery(createQuery(modelElements[0]));

    //run search in front-end
    IProgressService progressService = PlatformUI.getWorkbench().getProgressService();
    SearchUtil.runQueryInForeground(progressService, query);

    //verify search view toolbar
    IToolBarManager toolBarManager = ((PartSite) viewPart.getSite()).getActionBars().getToolBarManager();
    IContributionItem[] contributionItems = toolBarManager.getItems();
    Set<String> labelSet = new HashSet<String>();
    for (int i = 0; i < contributionItems.length; i++) {
        if (!(contributionItems[i] instanceof SubContributionItem))
            continue;

        if (!(((SubContributionItem) contributionItems[i]).getInnerItem() instanceof ActionContributionItem))
            continue;

        ActionContributionItem actionContributionItem = (ActionContributionItem) ((SubContributionItem) contributionItems[i])
                .getInnerItem();
        if (actionContributionItem.getAction() instanceof GroupAction)
            labelSet.add(actionContributionItem.getAction().getToolTipText());
    }
    assertTrue("Missing:Group by Project", labelSet.contains("Group by Project"));
    assertTrue("Missing:Group by Package", labelSet.contains("Group by Package"));
    assertTrue("Missing:Group by File", labelSet.contains("Group by File"));
    assertTrue("Missing:Group by Type", labelSet.contains("Group by Type"));
}

From source file:org.ebayopensource.vjet.eclipse.ui.VjetPartListener.java

License:Open Source License

public void partActivated(IWorkbenchPart part) {

    if (part instanceof VjoEditor) {
        VjoEditor editor = (VjoEditor) part;
        IModelElement module = editor.getInputModelElement();
        if (CodeassistUtils.isVjoSourceModule(module)) {
            try {
                boolean refresh = ((VjoSourceModule) module).refreshSourceFields();

                if (refresh) {
                    editor.refreshOutlinePage();
                }//ww w .j  a  v a  2  s  .c  o m
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }

    //      IWorkbenchPartSite site = part.getSite();
    //      if (DLTKUIPlugin.ID_SCRIPTEXPLORER.equals(site.getId())) {
    //         IContextService contextService = (IContextService) part.getSite()
    //               .getService(IContextService.class);
    //         m_activatedContext = contextService
    //               .activateContext("org.eclipse.dltk.mod.ui.scriptEditorScope");
    //      }

    //add by xingzhu, to fix bug 3332, change add exception action tooltip to 'Add Javascript Exception Breakpoint' 
    try {
        if (part instanceof IViewPart) {
            IToolBarManager toolBarManager = ((PartSite) (part.getSite())).getActionBars().getToolBarManager();
            IContributionItem[] items = toolBarManager.getItems();
            for (int i = 0; i < items.length; i++) {
                if ("org.eclipse.jdt.debug.ui.actions.AddException".equals(items[i].getId())) {
                    ActionContributionItem actionItem = (ActionContributionItem) items[i];
                    actionItem.getAction().setToolTipText("Add JavaScript Exception Breakpoint");
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}

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.// w ww .  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.ant.tests.ui.AntViewTests.java

License:Open Source License

private AddBuildFilesAction getAddBuildFilesAction(IToolBarManager toolBarMgr) {
    IContributionItem[] actions = toolBarMgr.getItems();
    if (actions != null && actions.length > 0) {
        for (int i = 0; i < actions.length; i++) {
            if (actions[i] instanceof ActionContributionItem) {
                ActionContributionItem actionItem = (ActionContributionItem) actions[i];
                if (actionItem.getAction() instanceof AddBuildFilesAction) {
                    return (AddBuildFilesAction) actionItem.getAction();
                }// www. j a va 2s .c o m
            }
        }
    }
    return null;
}