List of usage examples for org.eclipse.jface.action IContributionManager add
void add(IContributionItem item);
From source file:org.eclipse.scanning.device.ui.util.ViewUtil.java
License:Open Source License
/** * /* w w w . ja v a2 s . co m*/ * @param id * @param manager * @param actions */ public static void addGroup(String id, IContributionManager manager, IAction... actions) { manager.add(new Separator(id)); for (IAction action : actions) { if (action == null) continue; manager.add(action); } }
From source file:org.eclipse.scanning.event.ui.view.ConsumerView.java
License:Open Source License
private void createActions() { final IContributionManager man = getViewSite().getActionBars().getToolBarManager(); final Action refresh = new Action("Refresh", Activator.getDefault().getImageDescriptor("icons/arrow-circle-double-135.png")) { public void run() { viewer.refresh();/*from ww w.ja va 2 s .c o m*/ } }; man.add(refresh); final Action stop = new Action("Stop consumer", Activator.getDefault().getImageDescriptor("icons/terminate.png")) { public void run() { if (viewer.getSelection() == null || viewer.getSelection().isEmpty()) return; HeartbeatBean bean = (HeartbeatBean) ((IStructuredSelection) viewer.getSelection()) .getFirstElement(); boolean ok = MessageDialog.openConfirm(getSite().getShell(), "Confirm Stop", "If you stop this consumer it will have to be restarted by an administrator.\n\n" + "Are you sure that you want to do this?\n\n" + "(NOTE: Long running jobs can be terminated without stopping the consumer!)"); if (!ok) return; boolean notify = MessageDialog.openQuestion(getSite().getShell(), "Warn Users", "Would you like to warn users before stopping the consumer?\n\n" + "If you say yes, a popup will open on users clients to warn about the imminent stop."); if (notify) { final AdministratorMessage msg = new AdministratorMessage(); msg.setTitle("'" + bean.getConsumerName() + "' will shutdown."); msg.setMessage("'" + bean.getConsumerName() + "' is about to shutdown.\n\n" + "Any runs corrently running may loose progress notification,\n" + "however they should complete.\n\n" + "Runs yet to be started will be picked up when\n" + "'" + bean.getConsumerName() + "' restarts."); try { final IPublisher<AdministratorMessage> send = service .createPublisher(new URI(Activator.getJmsUri()), IEventService.ADMIN_MESSAGE_TOPIC); send.broadcast(msg); } catch (Exception e) { logger.error("Cannot notify of shutdown!", e); } } final KillBean kbean = new KillBean(); kbean.setMessage("Requesting a termination of " + bean.getConsumerName()); kbean.setConsumerId(bean.getConsumerId()); try { final IPublisher<KillBean> send = service.createPublisher(new URI(Activator.getJmsUri()), IEventService.CMD_TOPIC); send.broadcast(kbean); } catch (Exception e) { logger.error("Cannot terminate consumer " + bean.getConsumerName(), e); } } }; man.add(stop); final MenuManager menuMan = new MenuManager(); menuMan.add(refresh); menuMan.add(stop); viewer.getControl().setMenu(menuMan.createContextMenu(viewer.getControl())); }
From source file:org.eclipse.scanning.event.ui.view.StatusQueueView.java
License:Open Source License
private void createActions() throws Exception { final IContributionManager toolMan = getViewSite().getActionBars().getToolBarManager(); final IContributionManager dropDown = getViewSite().getActionBars().getMenuManager(); final MenuManager menuMan = new MenuManager(); final Action openResults = new Action("Open results for selected run", Activator.getImageDescriptor("icons/results.png")) { public void run() { openResults(getSelection()); }//from ww w.j av a2 s . c om }; toolMan.add(openResults); toolMan.add(new Separator()); menuMan.add(openResults); menuMan.add(new Separator()); dropDown.add(openResults); dropDown.add(new Separator()); this.up = new Action("Less urgent (-1)", Activator.getImageDescriptor("icons/arrow-090.png")) { public void run() { final StatusBean bean = getSelection(); try { queueConnection.reorder(bean, -1); } catch (EventException e) { ErrorDialog.openError(getViewSite().getShell(), "Cannot move " + bean.getName(), "'" + bean.getName() + "' cannot be moved in the submission queue.", new Status(IStatus.ERROR, "org.eclipse.scanning.event.ui", e.getMessage())); } refresh(); } }; up.setEnabled(false); toolMan.add(up); menuMan.add(up); dropDown.add(up); this.down = new Action("More urgent (+1)", Activator.getImageDescriptor("icons/arrow-270.png")) { public void run() { final StatusBean bean = getSelection(); try { queueConnection.reorder(getSelection(), +1); } catch (EventException e) { ErrorDialog.openError(getViewSite().getShell(), "Cannot move " + bean.getName(), e.getMessage(), new Status(IStatus.ERROR, "org.eclipse.scanning.event.ui", e.getMessage())); } refresh(); } }; down.setEnabled(false); toolMan.add(down); menuMan.add(down); dropDown.add(down); this.pause = new Action("Pause job.\nPauses a running job.", IAction.AS_CHECK_BOX) { public void run() { pauseJob(); } }; pause.setImageDescriptor(Activator.getImageDescriptor("icons/control-pause.png")); pause.setEnabled(false); pause.setChecked(false); toolMan.add(pause); menuMan.add(pause); dropDown.add(pause); this.pauseConsumer = new Action("Pause " + getPartName() + " Queue.\nDoes not pause running job.", IAction.AS_CHECK_BOX) { public void run() { togglePausedConsumer(this); } }; pauseConsumer.setImageDescriptor(Activator.getImageDescriptor("icons/control-pause-red.png")); pauseConsumer.setChecked(isQueuePaused(getSubmissionQueueName())); toolMan.add(pauseConsumer); menuMan.add(pauseConsumer); dropDown.add(pauseConsumer); this.pauseMonitor = service.createSubscriber(getUri(), EventConstants.CMD_TOPIC); pauseMonitor.addListener(new IBeanListener<PauseBean>() { @Override public void beanChangePerformed(BeanEvent<PauseBean> evt) { pauseConsumer.setChecked(isQueuePaused(getSubmissionQueueName())); } }); this.remove = new Action("Stop job or remove if finished", Activator.getImageDescriptor("icons/control-stop-square.png")) { public void run() { stopJob(); } }; remove.setEnabled(false); toolMan.add(remove); menuMan.add(remove); dropDown.add(remove); this.rerun = new Action("Rerun...", Activator.getImageDescriptor("icons/rerun.png")) { public void run() { rerunSelection(); } }; rerun.setEnabled(false); toolMan.add(rerun); menuMan.add(rerun); dropDown.add(rerun); this.edit = new Action("Edit...", Activator.getImageDescriptor("icons/modify.png")) { public void run() { editSelection(); } }; edit.setEnabled(false); toolMan.add(edit); menuMan.add(edit); dropDown.add(edit); toolMan.add(new Separator()); menuMan.add(new Separator()); final Action showAll = new Action("Show other users results", IAction.AS_CHECK_BOX) { public void run() { showEntireQueue = isChecked(); viewer.refresh(); } }; showAll.setImageDescriptor(Activator.getImageDescriptor("icons/spectacle-lorgnette.png")); toolMan.add(showAll); menuMan.add(showAll); dropDown.add(showAll); toolMan.add(new Separator()); menuMan.add(new Separator()); dropDown.add(new Separator()); final Action refresh = new Action("Refresh", Activator.getImageDescriptor("icons/arrow-circle-double-135.png")) { public void run() { reconnect(); } }; toolMan.add(refresh); menuMan.add(refresh); dropDown.add(refresh); final Action configure = new Action("Configure...", Activator.getImageDescriptor("icons/document--pencil.png")) { public void run() { PropertiesDialog dialog = new PropertiesDialog(getSite().getShell(), idProperties); int ok = dialog.open(); if (ok == PropertiesDialog.OK) { idProperties.clear(); idProperties.putAll(dialog.getProps()); reconnect(); } } }; toolMan.add(configure); menuMan.add(configure); dropDown.add(configure); final Action clearQueue = new Action("Clear Queue") { public void run() { try { purgeQueues(); } catch (EventException e) { e.printStackTrace(); logger.error("Canot purge queues", e); } } }; menuMan.add(new Separator()); dropDown.add(new Separator()); menuMan.add(clearQueue); dropDown.add(clearQueue); viewer.getControl().setMenu(menuMan.createContextMenu(viewer.getControl())); }
From source file:org.eclipse.sirius.editor.editorPlugin.ContributionActionBarContributor.java
License:Open Source License
/** * This populates the specified <code>manager</code> with * {@link org.eclipse.jface.action.ActionContributionItem}s based on the * {@link org.eclipse.jface.action.IAction}s contained in the * <code>actions</code> collection, by inserting them before the specified * contribution item <code>contributionID</code>. If <code>ID</code> is * <code>null</code>, they are simply added. *//*w w w. j a v a 2s. c o m*/ protected void populateManager(IContributionManager manager, Collection<IAction> actions, String contributionID) { if (actions != null) { for (Iterator<IAction> i = actions.iterator(); i.hasNext();) { IAction action = i.next(); if (contributionID != null) { manager.insertBefore(contributionID, action); } else { manager.add(action); } } } }
From source file:org.eclipse.sirius.editor.tools.api.menu.AbstractMenuBuilder.java
License:Open Source License
/** * Populate the menumanager with the given actions. * /*from www .j a v a 2s . c o m*/ * @param manager * manager to populate. * @param actions * actions to populate. * @param contributionID * the Id for the contribution. */ protected void populateManager(final IContributionManager manager, final Collection actions, final String contributionID) { if (actions != null) { List<IAction> sortedActions = Lists.newArrayList(Iterables.filter(actions, IAction.class)); Comparator<IAction> comparator = new Comparator<IAction>() { @Override public int compare(IAction a1, IAction a2) { int diff = getPriority(a1) - getPriority(a2); if (diff == 0) { // if both actions have no priority associated, or if // they have the same priority, we compare the text diff = Collator.getInstance().compare(a1.getText(), a2.getText()); } return diff; } }; Collections.sort(sortedActions, comparator); for (final IAction action : sortedActions) { if (contributionID != null) { manager.insertBefore(contributionID, action); } else { manager.add(action); } } } manager.update(true); }
From source file:org.eclipse.team.internal.ui.synchronize.actions.DirectionFilterActionGroup.java
License:Open Source License
public void fillMenu(IContributionManager manager) { for (Iterator it = actions.iterator(); it.hasNext();) { DirectionFilterAction action = (DirectionFilterAction) it.next(); manager.add(action); }/*from w ww .j ava2 s. c o m*/ }
From source file:org.eclipse.team.internal.ui.synchronize.SynchronizeModelManager.java
License:Open Source License
private void appendToMenu(String groupId, IContributionManager menu) { for (Iterator iter = toggleModelProviderActions.iterator(); iter.hasNext();) { if (groupId == null) { menu.add((Action) iter.next()); } else {// ww w. j av a 2s. c o m menu.appendToGroup(groupId, (Action) iter.next()); } } }
From source file:org.eclipse.ui.texteditor.BasicTextEditorActionContributor.java
License:Open Source License
/** * The <code>item</code> is {@link IContributionManager#add(IContributionItem) added} to * <code>menu</code> if no item with the same id currently exists. If there already is an * contribution item with the same id, the new item gets * {@link IContributionManager#insertAfter(String, IContributionItem) inserted after} it. * * @param menu the contribution manager/* www . ja va 2 s.com*/ * @param item the contribution item * @since 3.2 */ private void addOrInsert(IContributionManager menu, IContributionItem item) { String id = item.getId(); if (menu.find(id) == null) menu.add(item); else menu.insertAfter(id, item); }
From source file:org.eclipse.wb.internal.core.gef.policy.layout.absolute.actions.AnchorsActionsSupport.java
License:Open Source License
public void fillAnchorsActions(IContributionManager manager, IAbstractComponentInfo widget, boolean isHorizontal) { if (isHorizontal) { manager.add(new SetAlignmentAction(widget, GefMessages.AnchorsActionsSupport_leftAlignment, "h/menu/left.gif", IPositionConstants.LEFT)); manager.add(new SetAlignmentAction(widget, GefMessages.AnchorsActionsSupport_rightAlignment, "h/menu/right.gif", IPositionConstants.RIGHT)); manager.add(new MakeResizeableAction(widget, GefMessages.AnchorsActionsSupport_makeResizableHorizontal, "h/menu/both.gif", isHorizontal)); } else {/*from w w w . j a v a2 s . co m*/ manager.add(new SetAlignmentAction(widget, GefMessages.AnchorsActionsSupport_topAlignment, "v/menu/top.gif", IPositionConstants.TOP)); manager.add(new SetAlignmentAction(widget, GefMessages.AnchorsActionsSupport_bottomAlignment, "v/menu/bottom.gif", IPositionConstants.BOTTOM)); manager.add(new MakeResizeableAction(widget, GefMessages.AnchorsActionsSupport_makeResizableVertical, "v/menu/both.gif", isHorizontal)); } }
From source file:org.eclipse.wb.internal.core.model.util.factory.FactoryActionsSupport.java
License:Open Source License
/** * Contributes "factory" actions for this component. * //from ww w . j a va2 s . c o m * @param manager * the {@link IContributionManager} to add action to. */ private void contribute(IContributionManager manager) throws Exception { // factories from same package { IPackageFragment currentPackage = (IPackageFragment) m_editor.getModelUnit().getParent(); // check all methods in all factories List<ICompilationUnit> factoryUnits = FactoryDescriptionHelper.getFactoryUnits(m_editor, currentPackage); for (ICompilationUnit unit : factoryUnits) { String typeName = unit.findPrimaryType().getFullyQualifiedName(); addApplyActions(manager, typeName); } } // previous factories manager.add(new Separator()); { String[] previousTypeNames = getPreviousTypeNames(m_component); for (String typeName : previousTypeNames) { if (m_editor.getJavaProject().findType(typeName) != null) { addApplyActions(manager, typeName); } } } manager.add(new FactorySelectAction(m_component)); // create factory manager.add(new Separator()); manager.add(new FactoryCreateAction(m_component)); }