private static void changeIcon(final IMenuManager menu, final IContributionItem item, final ImageDescriptor image) { if (item instanceof ActionContributionItem) { ((ActionContributionItem) item).getAction().setImageDescriptor(image); } else if (item instanceof CommandContributionItem) { final CommandContributionItemParameter data = ((CommandContributionItem) item).getData(); data.commandId = ((CommandContributionItem) item).getCommand().getId(); data.icon = image; final CommandContributionItem newItem = new CommandContributionItem(data); newItem.setId(item.getId()); menu.insertAfter(item.getId(), newItem); menu.remove(item); item.dispose(); } else if (item instanceof ActionSetContributionItem) { changeIcon(menu, ((ActionSetContributionItem) item).getInnerItem(), image); } else if (item instanceof MenuManager) { ((MenuManager) item).setImageDescriptor(image); } }
/** * Asserts that the context menu for the current navigator selection does not contain any duplicates. * * That is, two menu items that represent an action of the same class. */ private void assertContextMenuNoActionDuplicates() { MenuManager menu = new MenuManager(); projectExplorer.getNavigatorActionService().fillContextMenu(menu); List<ActionContributionItem> actionContributions = Arrays.asList(menu.getItems()).stream() .filter(i -> i instanceof ActionContributionItem) .map(i -> ((ActionContributionItem) i)) .collect(Collectors.toList()); Map<String, ActionContributionItem> contributionNameMap = new HashMap<>(); for (ActionContributionItem item : actionContributions) { ActionContributionItem mapItem = contributionNameMap.putIfAbsent(item.getAction().getText(), item); if (mapItem != null) { IAction mapAction = mapItem.getAction(); IAction otherAction = item.getAction(); // Double check if action is of the same type if (mapAction.getClass().equals(otherAction.getClass())) { fail("Action '" + mapAction.getClass().getSimpleName() + "' is contributed twice to the context menu: " + mapAction.toString() + " " + otherAction.toString()); } } } }
/** * Returns the menu contribution titles of the project navigator context menu. * * This only includes {@link ActionContributionItem}s and {@link MenuManager}s. */ private List<String> getContextMenuContributions() { MenuManager menu = new MenuManager(); projectExplorer.getNavigatorActionService().fillContextMenu(menu); return Arrays.asList(menu.getItems()).stream() .map(i -> { if (i instanceof ActionContributionItem) { // use action name return ((ActionContributionItem) i).getAction().getText(); } else if (i instanceof MenuManager) { // use sub-menu title return ((MenuManager) i).getMenuText(); } else { // null for other types of contributions return null; } }) .filter(t -> null != t) // remove mnemonics (e.g. Close &Project -> Close Project)) .map(text -> LegacyActionTools.removeMnemonics(text)) .collect(Collectors.toList()); }
/** * This removes from the specified <code>manager</code> all {@link org.eclipse.jface.action.ActionContributionItem}s * based on the {@link org.eclipse.jface.action.IAction}s contained in the <code>actions</code> collection. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void depopulateManager(IContributionManager manager, Collection<? extends IAction> actions) { if (actions != null) { IContributionItem[] items = manager.getItems(); for (int i = 0; i < items.length; i++) { // Look into SubContributionItems // IContributionItem contributionItem = items[i]; while (contributionItem instanceof SubContributionItem) { contributionItem = ((SubContributionItem)contributionItem).getInnerItem(); } // Delete the ActionContributionItems with matching action. // if (contributionItem instanceof ActionContributionItem) { IAction action = ((ActionContributionItem)contributionItem).getAction(); if (actions.contains(action)) { manager.remove(contributionItem); } } } } }
/** * This removes from the specified <code>manager</code> all {@link org.eclipse.jface.action.ActionContributionItem}s * based on the {@link org.eclipse.jface.action.IAction}s contained in the <code>actions</code> collection. * <!-- begin-user-doc --> * <!-- end-user-doc --> * @generated */ protected void depopulateManager(IContributionManager manager, Collection<? extends IAction> actions) { if (actions != null) { IContributionItem[] items = manager.getItems(); for (int i = 0; i < items.length; i++) { // Look into SubContributionItems // IContributionItem contributionItem = items[i]; while (contributionItem instanceof SubContributionItem) { contributionItem = ((SubContributionItem) contributionItem) .getInnerItem(); } // Delete the ActionContributionItems with matching action. // if (contributionItem instanceof ActionContributionItem) { IAction action = ((ActionContributionItem) contributionItem) .getAction(); if (actions.contains(action)) { manager.remove(contributionItem); } } } } }
public BaseFolderImplementation ( final int index, final String label, final MenuManager mgr ) { this.summaryInformation = new SummaryInformation ( Collections.<String, DataValue> emptyMap () ); this.index = index; this.label = label; this.mgr = mgr; this.dumpAction = new Action ( "Dump summaries for: " + this.label ) { @Override public void run () { BaseFolderImplementation.this.summaryInformation.dump ( System.out ); }; }; this.contribution = new ActionContributionItem ( this.dumpAction ); }
/** * This removes from the specified <code>manager</code> all {@link org.eclipse.jface.action.ActionContributionItem}s * based on the {@link org.eclipse.jface.action.IAction}s contained in the <code>actions</code> collection. * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ protected void depopulateManager(IContributionManager manager, Collection<? extends IAction> actions) { if (actions != null) { IContributionItem[] items = manager.getItems(); for (int i = 0; i < items.length; i++) { // Look into SubContributionItems // IContributionItem contributionItem = items[i]; while (contributionItem instanceof SubContributionItem) { contributionItem = ((SubContributionItem) contributionItem).getInnerItem(); } // Delete the ActionContributionItems with matching action. // if (contributionItem instanceof ActionContributionItem) { IAction action = ((ActionContributionItem) contributionItem).getAction(); if (actions.contains(action)) { manager.remove(contributionItem); } } } } }
private void setToolbarButtonTextMode() { final boolean hideText = getHideTextOnButtonsOption(); final String toggleButtonText = hideText ? Messages.getString("PendingChangesView.ShowToolbarText") //$NON-NLS-1$ : Messages.getString("PendingChangesView.HideToolbarText"); //$NON-NLS-1$ toggleButtonTextAction.setText(toggleButtonText); final int contributionMode = hideText ? 0 : ActionContributionItem.MODE_FORCE_TEXT; workspaceActionContribution.setMode(contributionMode); checkinActionContribution.setMode(contributionMode); shelveActionContribution.setMode(contributionMode); unshelveActionContribution.setMode(contributionMode); resolveConflictsActionContribution.setMode(contributionMode); getViewSite().getActionBars().getToolBarManager().update(false); }
private void setCheckedItem(final IMenuManager menuManager) { for (final IContributionItem item : menuManager.getItems()) { if (item instanceof ActionContributionItem) { /* * Actions at the top level are navigation actions. Set the * check mark for the action associated with the current * navigation item. Clear the check mark for all others. */ final ActionContributionItem actionContributionItem = (ActionContributionItem) item; final String actionID = actionContributionItem.getAction().getId(); actionContributionItem.getAction().setChecked( actionID != null && actionID.equals(currentNavItem.getID())); } } }
protected Menu getSubActionMenu(final Control parent) { if (subActionMenu != null) { return subActionMenu; } subActionMenu = new Menu(parent); for (final Iterator<IAction> it = subActions.iterator(); it.hasNext();) { final IAction subAction = it.next(); final ActionContributionItem aci = new ActionContributionItem(subAction); aci.fill(subActionMenu, -1); final MenuItem menuItem = subActionMenu.getItem(subActionMenu.getItemCount() - 1); menuItem.addSelectionListener(menuItemSelectionListener); } return subActionMenu; }
public void fireAuthEnable( boolean enabled){ IToolBarManager toolbar = this.getViewSite().getActionBars().getToolBarManager(); IContributionItem[] items = toolbar.getItems(); for (IContributionItem it : items) { if (it instanceof ActionContributionItem) { ActionContributionItem aci = (ActionContributionItem) it; if (aci.getAction() instanceof AuthenticationAction) { AuthenticationAction aa = (AuthenticationAction) aci.getAction(); String img = null; if (enabled) { img = CoreImages.AUTH_ENABLED; } else { img = CoreImages.AUTH; } aa.setImageDescriptor(ImageDescriptor.createFromImage(ResourceUtils.getImage(CoreConstants.PLUGIN_UI, img))); } } } }
public void fireProxyEnable( boolean enabled){ IToolBarManager toolbar = this.getViewSite().getActionBars().getToolBarManager(); IContributionItem[] items = toolbar.getItems(); for (IContributionItem it : items) { if (it instanceof ActionContributionItem) { ActionContributionItem aci = (ActionContributionItem) it; if (aci.getAction() instanceof ProxyAction) { ProxyAction aa = (ProxyAction) aci.getAction(); String img = null; if (enabled) { img = CoreImages.PROXY_ENABLED; } else { img = CoreImages.PROXY; } aa.setImageDescriptor(ImageDescriptor.createFromImage(ResourceUtils.getImage(CoreConstants.PLUGIN_UI, img))); } } } }
@Override protected void fillCoolBar(ICoolBarManager coolBar) { IToolBarManager toolBar = new ToolBarManager(SWT.FLAT | SWT.RIGHT); coolBar.add(new ToolBarContributionItem(toolBar, "standard")); //$NON-NLS-1$ // For the Back and Forward actions, force their text to be shown on the toolbar, // not just their image. For the remaining actions, the ActionContributionItem // is created implicitly with the default presentation mode. ActionContributionItem backCI = new ActionContributionItem(backAction); backCI.setMode(ActionContributionItem.MODE_FORCE_TEXT); toolBar.add(backCI); ActionContributionItem forwardCI = new ActionContributionItem(forwardAction); forwardCI.setMode(ActionContributionItem.MODE_FORCE_TEXT); toolBar.add(forwardCI); toolBar.add(stopAction); toolBar.add(refreshAction); }