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

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

Introduction

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

Prototype

IContributionItem find(String id);

Source Link

Document

Finds the contribution item with the given id.

Usage

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

License:Open Source License

public void contributeToActionsBars(final IServiceLocator serviceLocator, final IActionBars actionBars) {
    fActionBars.add(actionBars);//from  www .  j  av  a  2  s.  c  o  m

    final IToolBarManager toolBar = actionBars.getToolBarManager();
    if (toolBar.find(CONTEXT_MENU_GROUP_ID) == null) {
        toolBar.insertBefore(SharedUIResources.ADDITIONS_MENU_ID, new Separator(CONTEXT_MENU_GROUP_ID));
    }
    if (toolBar.find(SIZE_MENU_GROUP_ID) == null) {
        toolBar.insertBefore(SharedUIResources.ADDITIONS_MENU_ID, new Separator(SIZE_MENU_GROUP_ID));
    }

    final ImageRegistry rGraphicsImageRegistry = RGraphicsPlugin.getDefault().getImageRegistry();

    toolBar.appendToGroup(CONTEXT_MENU_GROUP_ID, new HandlerContributionItem(
            new CommandContributionItemParameter(serviceLocator, null, HandlerContributionItem.NO_COMMAND_ID,
                    null, rGraphicsImageRegistry.getDescriptor(RGraphicsPlugin.IMG_LOCTOOL_LOCATOR_DONE), null,
                    null, "Stop Locator", null, null, HandlerContributionItem.STYLE_PUSH, null, true),
            fHandlerCollection.get(LOCATOR_DONE_COMMAND_ID)));
    toolBar.appendToGroup(CONTEXT_MENU_GROUP_ID, new HandlerContributionItem(
            new CommandContributionItemParameter(serviceLocator, null, HandlerContributionItem.NO_COMMAND_ID,
                    null, rGraphicsImageRegistry.getDescriptor(RGraphicsPlugin.IMG_LOCTOOL_LOCATOR_CANCEL),
                    null, null, "Cancel Locator", null, null, HandlerContributionItem.STYLE_PUSH, null, true),
            fHandlerCollection.get(LOCATOR_CANCEL_COMMAND_ID)));
}

From source file:fr.inria.linuxtools.tmf.ui.views.uml2sd.handlers.Zoom.java

License:Open Source License

/**
 * Set action check state of a view action for a given action ID.
 *
 * @param id The action ID// w w w  . ja  va 2  s.co  m
 * @param checked true to check the action, false to uncheck the action
 */
protected void setActionChecked(String id, boolean checked) {
    if (getView() != null) {
        IActionBars bar = getView().getViewSite().getActionBars();
        if (bar == null) {
            return;
        }
        IToolBarManager barManager = bar.getToolBarManager();
        if (barManager == null) {
            return;
        }
        IContributionItem nextPage = barManager.find(id);
        if (nextPage instanceof ActionContributionItem) {
            IAction action = ((ActionContributionItem) nextPage).getAction();
            if (action != null) {
                action.setChecked(checked);
            }
        }
    }
}

From source file:fr.inria.linuxtools.tmf.ui.views.uml2sd.SDView.java

License:Open Source License

/**
 * Updates the view coolbar buttons state according to the value return by: -
 * ISDExtendedActionBarProvider.hasNextPage()<br>
 * - ISDExtendedActionBarProvider.hasPrevPage()<br>
 *
 */// w  w  w .j  av a2 s  .c  o m
public void updateCoolBar() {
    if (fSdPagingProvider != null) {
        IActionBars bar = getViewSite().getActionBars();
        if (bar == null) {
            return;
        }
        IToolBarManager barManager = bar.getToolBarManager();
        if (barManager == null) {
            return;
        }
        IContributionItem nextPage = barManager.find(NextPage.ID);
        if (nextPage instanceof ActionContributionItem) {
            IAction nextPageAction = ((ActionContributionItem) nextPage).getAction();
            if (nextPageAction instanceof NextPage) {
                ((NextPage) nextPageAction).setEnabled(fSdPagingProvider.hasNextPage());
            }
        }

        IContributionItem prevPage = barManager.find(PrevPage.ID);
        if (prevPage instanceof ActionContributionItem) {
            IAction prevPageAction = ((ActionContributionItem) prevPage).getAction();
            if (prevPageAction instanceof PrevPage) {
                ((PrevPage) prevPageAction).setEnabled(fSdPagingProvider.hasPrevPage());
            }
        }

        IContributionItem firstPage = barManager.find(FirstPage.ID);
        if (firstPage instanceof ActionContributionItem) {
            IAction firstPageAction = ((ActionContributionItem) firstPage).getAction();
            if (firstPageAction instanceof FirstPage) {
                ((FirstPage) firstPageAction).setEnabled(fSdPagingProvider.hasPrevPage());
            }
        }

        IContributionItem lastPage = barManager.find(LastPage.ID);
        if (lastPage instanceof ActionContributionItem) {
            IAction lastPageAction = ((ActionContributionItem) lastPage).getAction();
            if (lastPageAction instanceof LastPage) {
                ((LastPage) lastPageAction).setEnabled(fSdPagingProvider.hasNextPage());
            }
        }

        updatePagesMenuItem(bar);
    }
}

From source file:msi.gama.lang.gaml.ui.editor.GamlMarkOccurrenceActionContributor.java

@Override
public void contributeActions(final XtextEditor editor) {
    super.contributeActions(editor);
    final IToolBarManager toolBarManager = editor.getEditorSite().getActionBars().getToolBarManager();
    final IContributionItem item = toolBarManager.find(getAction().getId());
    if (item != null) {
        toolBarManager.remove(item);/*from w w  w  .  ja  v a  2s .com*/
    }

}

From source file:name.nirav.evariablesview.ui.AttachSearchFeature.java

License:Open Source License

private void attach(IWorkbenchPart part) {
    if (part instanceof IViewPart) {
        IViewPart view = (IViewPart) part;
        if (!view.getViewSite().getId().equals(IDebugUIConstants.ID_VARIABLE_VIEW))
            return;
        IToolBarManager manager = view.getViewSite().getActionBars().getToolBarManager();
        if (manager.find(ID_SEARCH_VARIABLES) != null)
            return;
        manager.appendToGroup("variableGroup",
                new SearchVariableCustomContributionItem(ID_SEARCH_VARIABLES, (VariablesView) view));
        manager.update(true);/*from w w w  . ja va2 s.  c o  m*/
        view.getViewSite().getActionBars().updateActionBars();
    }
}

From source file:net.bioclipse.jseditor.editors.JsEditor.java

License:Open Source License

private void fillLocalToolBar(IToolBarManager manager) {
    if (manager.find(runRhinoScriptActionPulldown.getId()) == null) {
        manager.add(runRhinoScriptActionPulldown);
    }/*w  w w.  ja v  a  2  s  .  c  o m*/
}

From source file:org.csstudio.scan.ui.plot.ScanPlotView.java

License:Open Source License

/** Update toolbar to display selectors for the devices shown in the plot */
void updateToolbar() {
    final String[] devices = model.getYDevices();
    final IToolBarManager toolbar = getViewSite().getActionBars().getToolBarManager();
    // Add/update Y axis selectors
    for (int i = 0; i < devices.length; ++i) {
        final ActionContributionItem item = (ActionContributionItem) toolbar
                .find(DeviceSelectorAction.ID_Y + i);
        final DeviceSelectorAction selector;
        if (item != null)
            selector = (DeviceSelectorAction) item.getAction();
        else {//from w  w w.j  a v a  2  s .  c  o m
            selector = DeviceSelectorAction.forYAxis(model, i, plot);
            toolbar.insertBefore(DeviceSelectorAction.ID_ADD, selector);
            toolbar.update(true);
        }
        selector.setSelection(devices[i]);
    }
    // Remove extra Y selectors, if there are any
    int i = devices.length;
    ActionContributionItem item = (ActionContributionItem) toolbar.find(DeviceSelectorAction.ID_Y + i);
    while (item != null) {
        final DeviceSelectorAction selector = (DeviceSelectorAction) item.getAction();
        if (devices.length <= 0)
            selector.setSelection(""); //$NON-NLS-1$
        else {
            toolbar.remove(item);
            toolbar.update(true);
        }
        ++i;
        item = (ActionContributionItem) toolbar.find(DeviceSelectorAction.ID_Y + i);
    }

    y_removal.setEnabled(devices.length > 1);
}

From source file:org.dawnsci.breadcrumb.navigation.views.AbstractNavigationView.java

License:Open Source License

protected void createActions() {

    final IToolBarManager man = getViewSite().getActionBars().getToolBarManager();
    final MenuManager menuMan = new MenuManager();

    man.add(new Separator("breadcrumb.group"));

    Action add = new Action("Add another breadcrumb search",
            Activator.getImageDescriptor("icons/ui-tooltip--plus.png")) {
        public void run() {
            addBreadcrumb();/*from w w w  . ja  v a2 s .  c o  m*/
        }
    };
    man.add(add);

    man.add(new Separator("refresh.group"));
    menuMan.add(new Separator("refresh.group"));

    Action refresh = new Action("Refresh table", Activator.getImageDescriptor("icons/refresh_16x16.png")) {
        public void run() {
            refreshDataCollections();
        }
    };
    man.add(refresh);

    refresh = new Action("Refresh connection", Activator.getImageDescriptor("icons/refresh_red.png")) {
        public void run() {
            boolean ok = MessageDialog.openConfirm(Display.getDefault().getActiveShell(),
                    "Confirm Full Refresh",
                    "Are you sure that you would like to do a complete refresh?\n\nThis will loose your selected visit(s) and ask you to start again.");
            if (!ok)
                return;
            connectionManager.logoff();
            connectionManager.connect();
        }
    };
    man.add(refresh);

    // Actions to search data collection table
    for (INavigationDelegateMode mode : pages.keySet()) {
        INavigationDelegate delegate = pages.get(mode);
        if (delegate instanceof AbstractTableDelegate) {
            ((AbstractTableDelegate) delegate).createActions(getViewSite().getActionBars().getToolBarManager(),
                    menuMan);
        }
    }

    // Actions to log in and log out
    connectionManager.createLogActions(getViewSite().getActionBars().getToolBarManager());

    man.add(new Separator("preference.group"));
    menuMan.add(new Separator("preference.group"));

    if (getPreferencePageId() != null) {
        Action ispyPref = new Action("Preferences... (Connection and polling)",
                Activator.getImageDescriptor("icons/data.gif")) {
            @Override
            public void run() {
                PreferenceDialog pref = PreferencesUtil.createPreferenceDialogOn(
                        PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), getPreferencePageId(),
                        null, null);
                if (pref != null)
                    pref.open();
            }
        };
        man.add(ispyPref);
        getViewSite().getActionBars().getMenuManager().add(ispyPref);
    }

    Action prefs = new Action("Image Preferences... (For data collection images in gallery)",
            Activator.getImageDescriptor("icons/data.gif")) {
        @Override
        public void run() {
            PreferenceDialog pref = PreferencesUtil.createPreferenceDialogOn(
                    PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell(), ViewConstants.PAGE_ID,
                    null, null);
            if (pref != null)
                pref.open();
        }
    };

    getViewSite().getActionBars().getMenuManager().add(prefs);
    menuMan.add(prefs);

    man.add(new SpacerContributionItem(50));

    final CheckableActionGroup grp = new CheckableActionGroup();
    for (final INavigationDelegateMode mode : getDefaultNavigationMode().allValues()) {
        if (mode.isInToolbar()) {
            final Action action = new Action(mode.getLabel(), IAction.AS_CHECK_BOX) {
                public void run() {
                    navigationMode = mode;
                    final INavigationDelegate prov = pages.get(mode);
                    if (prov != null) {
                        setActiveUI(prov.getControl(), mode);
                        selectionChanged(null);
                        // TODO Might want to leave selection so that do not loose plots one day.
                        prov.getSelectionProvider().setSelection(prov.getSelectionProvider().getSelection());
                    }
                }
            };
            action.setId(mode.getId());
            action.setImageDescriptor(mode.getIcon());

            final ActionContributionItem item = new ActionContributionItem(action);
            if (Activator.getDefault().getPreferenceStore().getBoolean(NavigationConstants.SHOW_MODE_LABEL)) {
                item.setMode(ActionContributionItem.MODE_FORCE_TEXT);
            }
            man.add(item);
            grp.add(action);
            action.setChecked(navigationMode == mode);
        }
    }
    man.add(new Separator("tablemode.group"));
    menuMan.add(new Separator("tablemode.group"));

    Activator.getDefault().getPreferenceStore().addPropertyChangeListener(new IPropertyChangeListener() {

        @Override
        public void propertyChange(PropertyChangeEvent event) {
            if (NavigationConstants.SHOW_MODE_LABEL.equals(event.getProperty())) {
                boolean isShowLabel = Activator.getDefault().getPreferenceStore()
                        .getBoolean(NavigationConstants.SHOW_MODE_LABEL);
                int modeCode = isShowLabel ? ActionContributionItem.MODE_FORCE_TEXT : 0;
                for (final INavigationDelegateMode mode : getDefaultNavigationMode().allValues()) {
                    final IContributionItem item = man.find(mode.getId());
                    if (item instanceof ActionContributionItem) {
                        ((ActionContributionItem) item).setMode(modeCode);
                    }
                }
                man.update(true);
            }
        }
    });

    for (INavigationDelegateMode mode : pages.keySet()) {
        INavigationDelegate delegate = pages.get(mode);
        if (delegate instanceof AbstractTableDelegate) {
            ((AbstractTableDelegate) delegate).setMenu(menuMan);
        }
    }

}

From source file:org.dawnsci.spectrum.ui.views.TraceProcessPage.java

License:Open Source License

public Composite createPartControl(Composite parent) {

    //Create table
    viewer = CheckboxTableViewer.newCheckList(parent, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);
    viewer.setContentProvider(new ViewContentProvider());
    TableViewerColumn viewerColumn = new TableViewerColumn(viewer, SWT.NONE);
    viewerColumn.setLabelProvider(new ViewLabelProvider());

    TableColumnLayout tableColumnLayout = new TableColumnLayout();
    tableColumnLayout.setColumnData(viewerColumn.getColumn(), new ColumnWeightData(1));
    parent.setLayout(tableColumnLayout);

    ColumnViewerToolTipSupport.enableFor(viewer);

    //Get plotting system from PlotView, use it to create file manager
    IWorkbenchPage page = getView().getSite().getPage();
    IViewPart view = page.findView("org.dawnsci.spectrum.ui.views.SpectrumPlot");
    system = (IPlottingSystem) view.getAdapter(IPlottingSystem.class);
    manager = new SpectrumFileManager(system);

    viewer.setInput(manager);/* ww w  . j  a  va  2  s  .c  om*/

    manager.addFileListener(new ISpectrumFileListener() {

        @Override
        public void fileLoaded(final SpectrumFileOpenedEvent event) {
            Display.getDefault().syncExec(new Runnable() {
                @Override
                public void run() {
                    viewer.refresh();
                    viewer.setSelection(new StructuredSelection(event.getFile()), true);
                    viewer.setChecked(event.getFile(), true);
                }
            });
        }
    });

    processMenuManager = new ProcessMenuManager(viewer, manager, system);

    getView().getSite().setSelectionProvider(viewer);

    //Set up drag-drop
    DropTargetAdapter dropListener = new DropTargetAdapter() {
        @Override
        public void drop(DropTargetEvent event) {
            Object dropData = event.data;
            if (dropData instanceof TreeSelection) {
                TreeSelection selectedNode = (TreeSelection) dropData;
                Object obj[] = selectedNode.toArray();
                for (int i = 0; i < obj.length; i++) {
                    if (obj[i] instanceof IFile) {
                        IFile file = (IFile) obj[i];
                        manager.addFile(file.getRawLocation().toOSString());
                    }
                }
            } else if (dropData instanceof String[]) {
                for (String path : (String[]) dropData) {
                    manager.addFile(path);
                }
            }
        }
    };

    DropTarget dt = new DropTarget(viewer.getControl(), DND.DROP_MOVE | DND.DROP_DEFAULT | DND.DROP_COPY);
    dt.setTransfer(new Transfer[] { TextTransfer.getInstance(), FileTransfer.getInstance(),
            ResourceTransfer.getInstance(), LocalSelectionTransfer.getTransfer() });
    dt.addDropListener(dropListener);

    // Create the help context id for the viewer's control
    PlatformUI.getWorkbench().getHelpSystem().setHelp(viewer.getControl(), "org.dawnsci.spectrum.viewer");
    makeActions();
    hookContextMenu();
    //hookDoubleClickAction();
    contributeToActionBars();

    //hook up delete key to remove from list
    viewer.getTable().addKeyListener(new KeyListener() {

        @Override
        public void keyReleased(KeyEvent e) {
        }

        @Override
        public void keyPressed(KeyEvent e) {
            if (e.keyCode == SWT.DEL) {
                removeAction.run();
            }
        }
    });

    //Highlight trace on selection
    viewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {

            List<ISpectrumFile> list = SpectrumUtils
                    .getSpectrumFilesList((IStructuredSelection) event.getSelection());
            for (ISpectrumFile file : manager.getFiles()) {
                if (list.contains(file)) {
                    file.setSelected(true);
                } else {
                    file.setSelected(false);
                }
            }
        }
    });

    viewer.addCheckStateListener(new ICheckStateListener() {

        @Override
        public void checkStateChanged(CheckStateChangedEvent event) {
            // TODO Auto-generated method stub
            Object ob = event.getElement();

            if (ob instanceof ISpectrumFile) {
                if (event.getChecked()) {
                    ((ISpectrumFile) ob).setShowPlot(true);
                } else {
                    ((ISpectrumFile) ob).setShowPlot(false);
                }
            }
        }
    });

    //set axis as tight
    List<IAxis> axes = system.getAxes();
    for (IAxis axis : axes)
        axis.setAxisAutoscaleTight(true);
    system.setColorOption(ColorOption.BY_NAME);

    // Currently we do not want the run actions visible
    final IToolBarManager man = getView().getViewSite().getActionBars().getToolBarManager();
    if (man.find(IAlgorithmProcessContext.RUN_ID_STUB) != null)
        man.find(IAlgorithmProcessContext.RUN_ID_STUB).setVisible(false);
    if (man.find(IAlgorithmProcessContext.STOP_ID_STUB) != null)
        man.find(IAlgorithmProcessContext.STOP_ID_STUB).setVisible(false);

    return viewer.getTable();
}

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 w w w .  j  ava2s  .  c  o  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);
        }
    }
}