List of usage examples for org.eclipse.jface.action IToolBarManager getItems
IContributionItem[] getItems();
From source file:com.nokia.tools.variant.editor.actionbars.CPFEditorActionBarContributor.java
License:Open Source License
/** * This method creates delegate for Create report button. This delegate sets * enable/disable state of the button./*from w w w.j a v a 2s .c o m*/ * */ @SuppressWarnings("restriction") private void createDelegateForReportAction() { EditorActionBars actionBars = (EditorActionBars) getActionBars(); SubCoolBarManager coolBarManager = (SubCoolBarManager) actionBars.getCoolBarManager(); IContributionManager parent = coolBarManager.getParent(); IContributionItem[] items = parent.getItems(); ToolBarContributionItem contributionItem = (ToolBarContributionItem) items[0]; IToolBarManager toolBarManager2 = contributionItem.getToolBarManager(); IContributionItem[] items2 = toolBarManager2.getItems(); PluginActionCoolBarContributionItem contributionItem3 = null; for (IContributionItem contributionItem2 : items2) { if (("com.nokia.tools.variant.report.actions.GenerateReportAction").equals(contributionItem2.getId())) { contributionItem3 = (PluginActionCoolBarContributionItem) contributionItem2; break; } } if (contributionItem3 == null) { return; } WWinPluginAction action = (WWinPluginAction) contributionItem3.getAction(); try { Method declaredMethod = PluginAction.class.getDeclaredMethod("createDelegate"); declaredMethod.setAccessible(true); declaredMethod.invoke(action); } catch (SecurityException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } }
From source file:com.sap.dirigible.ide.ui.rap.managers.CoolBarManager.java
License:Open Source License
public void update(final boolean force) { if ((isDirty() || force) && getControl2() != null) { refresh();// w w w .j av a 2s . co m boolean changed = false; /* * Make a list of items including only those items that are visible. * Separators are being removed. Because we use only one Toolbar all * ToolBarContributionItems will be extracted in their IContribution * Items. */ final IContributionItem[] items = getItems(); final List<IContributionItem> visibleItems = new ArrayList<IContributionItem>(items.length); for (int i = 0; i < items.length; i++) { final IContributionItem item = items[i]; if (item.isVisible()) { if (item instanceof IToolBarContributionItem) { IToolBarContributionItem toolbarItem = (IToolBarContributionItem) item; IToolBarManager toolBarManager = toolbarItem.getToolBarManager(); IContributionItem[] toolbarItems = toolBarManager.getItems(); for (int j = 0; j < toolbarItems.length; j++) { final IContributionItem toolItem = toolbarItems[j]; if (toolItem.isVisible() && !toolItem.isSeparator()) { visibleItems.add(toolItem); } } } } } /* * Make a list of ToolItem widgets in the tool bar for which there * is no current visible contribution item. These are the widgets to * be disposed. Dynamic items are also removed. */ ToolItem[] toolItems = toolbar.getItems(); final ArrayList<ToolItem> toolItemsToRemove = new ArrayList<ToolItem>(toolItems.length); for (int i = 0; i < toolItems.length; i++) { final Object data = toolItems[i].getData(); if ((data == null) || (!visibleItems.contains(data)) || ((data instanceof IContributionItem) && ((IContributionItem) data).isDynamic())) { toolItemsToRemove.add(toolItems[i]); } } // Dispose of any items in the list to be removed. for (int i = toolItemsToRemove.size() - 1; i >= 0; i--) { ToolItem toolItem = (ToolItem) toolItemsToRemove.get(i); if (!toolItem.isDisposed()) { Control control = toolItem.getControl(); if (control != null) { toolItem.setControl(null); control.dispose(); } toolItem.dispose(); } } // Add any new items by telling them to fill. toolItems = toolbar.getItems(); IContributionItem sourceItem; IContributionItem destinationItem; int sourceIndex = 0; int destinationIndex = 0; final Iterator<IContributionItem> visibleItemItr = visibleItems.iterator(); while (visibleItemItr.hasNext()) { sourceItem = visibleItemItr.next(); // Retrieve the corresponding contribution item from SWT's // data. if (sourceIndex < toolItems.length) { destinationItem = (IContributionItem) toolItems[sourceIndex].getData(); } else { destinationItem = null; } // The items match if they are equal or both separators. if (destinationItem != null) { if (sourceItem.equals(destinationItem)) { sourceIndex++; destinationIndex++; sourceItem.update(); continue; } else if ((destinationItem.isSeparator()) && (sourceItem.isSeparator())) { toolItems[sourceIndex].setData(sourceItem); sourceIndex++; destinationIndex++; sourceItem.update(); continue; } } // Otherwise, a new item has to be added. final int start = toolbar.getItemCount(); sourceItem.fill(toolbar, destinationIndex); final int newItems = toolbar.getItemCount() - start; // add the selection listener for the styling StylingSelectionAdapter listener = new StylingSelectionAdapter(HEADER_TOOLBAR_VARIANT); for (int i = 0; i < newItems; i++) { ToolItem item = toolbar.getItem(destinationIndex++); item.setData(sourceItem); item.addSelectionListener(listener); } changed = true; } // Remove any old widgets not accounted for. for (int i = toolItems.length - 1; i >= sourceIndex; i--) { final ToolItem item = toolItems[i]; if (!item.isDisposed()) { Control control = item.getControl(); if (control != null) { item.setControl(null); control.dispose(); } item.dispose(); changed = true; } } // Update wrap indices. only needed by a coolbar // updateWrapIndices(); // Update the sizes. for (int i = 0; i < items.length; i++) { IContributionItem item = items[i]; item.update(SIZE); } if (changed) { updateToolbarTabOrder(); } // We are no longer dirty. setDirty(false); styleToolItems(); toolbar.pack(); toolbar.layout(true, true); manageOverflow(); } }
From source file:com.sap.dirigible.ide.ui.rap.stacks.ViewStackPresentation.java
License:Open Source License
private void handleConfigurationButton() { boolean hasViewMenu = false; if (currentPart != null && currentPart instanceof PresentablePart) { PresentablePart part = (PresentablePart) currentPart; if (part.getPane() != null) { hasViewMenu = part.getPane().hasViewMenu(); IToolBarManager manager = getPartToolBarManager(); boolean hasViewActions = manager != null && manager.getItems().length > 0; if ((hasViewActions || hasViewMenu) && !allActionsVisible) { if (confButton != null) { // enable conf button confButton.setEnabled(true); String toolTip = CONFIGURE_THE_ACTIONS_AND_VIEWMENU_FROM + currentPart.getName(); confButton.setToolTipText(toolTip); }//w w w. j av a 2s .co m } else { if (confButton != null) { // disable conf button confButton.setEnabled(false); String toolTip = currentPart.getName() + HAS_NO_ACTIONS_OR_VIEWMENU_TO_CONFIGURE; confButton.setToolTipText(toolTip); } } } } }
From source file:com.sympedia.util.eclipse.ui.UiHelper.java
License:Open Source License
public static void removeNavigationActions(IToolBarManager manager) { for (IContributionItem contributionItem : manager.getItems()) { if (contributionItem instanceof ActionContributionItem) { IAction action = ((ActionContributionItem) contributionItem).getAction(); if (action instanceof BackAction || action instanceof ForwardAction || action instanceof UpAction) { manager.remove(contributionItem); }// www.ja va2 s . com } } }
From source file:dynamicrefactoring.interfaz.view.RefactoringCatalogBrowserView.java
License:Open Source License
/** * Registra las acciones referentes a la visualizacin de los contenedores * separados por el spliter./*from w w w . ja va 2 s.c o m*/ */ private void loadActionsPane() { //actionsPane actionsPane = new ArrayList<IAction>(); ArrayList<String> actionsPaneNames = new ArrayList<String>(); actionsPaneNames.add(ShowLeftPaneViewAction.ID); actionsPaneNames.add(ShowRightPaneViewAction.ID); actionsPaneNames.add(ShowLeftAndRightPaneViewAction.ID); IToolBarManager toolBarManager = getViewSite().getActionBars().getToolBarManager(); IContributionItem[] contributionItems = toolBarManager.getItems(); ActionContributionItem actionItem = null; IAction action = null; for (IContributionItem item : contributionItems) { if (item instanceof ActionContributionItem) { actionItem = (ActionContributionItem) item; action = actionItem.getAction(); if (actionsPaneNames.contains(action.getId())) { actionsPane.add(action); } } } }
From source file:fr.inria.soctrace.framesoc.ui.perspective.FramesocPart.java
License:Open Source License
/** * Enable/disable all the toolbar actions. * /* w w w . j a v a2 s .co m*/ * @param enabled * enable flag */ protected void enableActions(boolean enabled) { IActionBars actionBars = getViewSite().getActionBars(); IToolBarManager toolBar = actionBars.getToolBarManager(); for (IContributionItem item : toolBar.getItems()) { if (item instanceof ActionContributionItem) { ((ActionContributionItem) item).getAction().setEnabled(enabled); } } }
From source file:fr.labsticc.framework.ide.viewpart.AbstractEditorViewPart.java
License:Open Source License
private void fillToolBar(final Collection<IAction> p_actions) { final IActionBars bars = getViewSite().getActionBars(); final IToolBarManager manager = bars.getToolBarManager(); if (defaultToolBarItems == null) { defaultToolBarItems = manager.getItems(); }/* w w w . ja v a 2s .c o m*/ manager.removeAll(); if (p_actions == null) { for (final IContributionItem item : defaultToolBarItems) { manager.add(item); } } else { for (final IAction action : p_actions) { manager.add(action); } } manager.update(false); }
From source file:gda.rcp.ApplicationWorkbenchAdvisor.java
License:Open Source License
/** * This method adds a part listener which enables the text next to the icon in the views' toolbar. Also enables the * text for the views that are open during workbench window creation(for the default perspective). * //from w w w. j a v a2s . co m * @param workbenchWindow */ private void applyViewMenuText(final IWorkbenchWindow workbenchWindow) { if (GDAClientActivator.getDefault().getPreferenceStore().getBoolean(GdaRootPreferencePage.SHOW_MENU_TEXT)) { workbenchWindow.getPartService().addPartListener(new MenuDisplayPartListener()); IViewReference[] viewReferences = workbenchWindow.getActivePage().getViewReferences(); for (IViewReference vr : viewReferences) { IViewPart view = vr.getView(false); if (view != null) { IToolBarManager toolBarManager = view.getViewSite().getActionBars().getToolBarManager(); IContributionItem[] items = toolBarManager.getItems(); for (IContributionItem iContributionItem : items) { if (iContributionItem instanceof ActionContributionItem) { ActionContributionItem commandContributionItem = (ActionContributionItem) iContributionItem; commandContributionItem.setMode(ActionContributionItem.MODE_FORCE_TEXT); commandContributionItem.update(); } if (iContributionItem instanceof CommandContributionItem) { // As per https://bugs.eclipse.org/bugs/show_bug.cgi?id=256340 the // CommandContributionItem // doesn't expose the setMode() method. Therefore, setting the mode using reflection. CommandContributionItem commandContributionItem = (CommandContributionItem) iContributionItem; commandContributionItem.getData().mode = CommandContributionItem.MODE_FORCE_TEXT; commandContributionItem.getId(); Class<? extends CommandContributionItem> class1 = commandContributionItem.getClass(); try { Field field = class1.getDeclaredField("mode"); field.setAccessible(true); field.set(commandContributionItem, new Integer(1)); } catch (SecurityException e) { logger.error("Security exception - cant access private member", e); } catch (IllegalArgumentException e) { logger.error("IllegalArgumentException - Problem setting mode", e); } catch (IllegalAccessException e) { logger.error("IllegalAccessException - Problem setting mode", e); } catch (NoSuchFieldException e) { logger.error("NoSuchFieldException - Problem setting mode", e); } commandContributionItem.update(); } } if (toolBarManager instanceof ToolBarManager) { ToolBarManager tm = (ToolBarManager) toolBarManager; tm.getControl().pack(true); } } } workbenchWindow.getActivePage().savePerspective(); workbenchWindow.getActivePage().resetPerspective(); } }
From source file:gov.nasa.ensemble.core.plan.editor.search.PlanSearchResultPage.java
License:Open Source License
@Override protected void fillToolbar(IToolBarManager tbm) { super.fillToolbar(tbm); // removing the remove options from the view IContributionItem[] items = tbm.getItems(); for (IContributionItem item : items) { if (item instanceof ActionContributionItem) { IAction action = ((ActionContributionItem) item).getAction(); if (action instanceof RemoveAllMatchesAction) { item.setVisible(false);//w ww . j a v a 2 s .c o m } if (action instanceof RemoveSelectedMatchesAction) { item.setVisible(false); } } } }
From source file:gov.nasa.ensemble.core.plan.editor.search.PlanSearchResultPage.java
License:Open Source License
@Override public void createControl(Composite parent) { super.createControl(parent); IPageSite site = getSite();//from www.ja va2s . c o m IActionBars actionBars = site.getActionBars(); try { Field field = SubActionBars.class.getDeclaredField("parent"); field.setAccessible(true); Object object = field.get(actionBars); ViewActionBars bars = (ViewActionBars) object; IToolBarManager manager = bars.getToolBarManager(); IContributionItem[] items = manager.getItems(); for (IContributionItem item : items) { if (item instanceof ActionContributionItem) { IAction action = ((ActionContributionItem) item).getAction(); if (action instanceof PinSearchViewAction) { item.setVisible(false); } } } } catch (SecurityException e) { LogUtil.error(e); } catch (NoSuchFieldException e) { LogUtil.error(e); } catch (IllegalArgumentException e) { LogUtil.error(e); } catch (IllegalAccessException e) { LogUtil.error(e); } }