List of usage examples for org.eclipse.jface.action IContributionManager add
void add(IContributionItem item);
From source file:org.dawnsci.plotting.draw2d.swtxy.selection.SelectionRegionFactory.java
License:Open Source License
public static IContributionManager fillActions(final IContributionManager manager, final IRegion region, final XYRegionGraph xyGraph, final IPlottingSystem system) { manager.add(new Separator("org.dawb.workbench.plotting.system.region.start")); final Action sendToBack = new Action("Send '" + region.getName() + "' to back", Activator.getImageDescriptor("icons/RegionToBack.png")) { public void run() { region.toBack();//from www.jav a2 s . com } }; manager.add(sendToBack); final Action bringToFront = new Action("Bring '" + region.getName() + "' to front", Activator.getImageDescriptor("icons/RegionToFront.png")) { public void run() { region.toFront(); } }; manager.add(bringToFront); final Action delete = new Action("Delete '" + region.getName() + "'", Activator.getImageDescriptor("icons/RegionDelete.png")) { public void run() { xyGraph.removeRegion((AbstractSelectionRegion<?>) region); } }; if (region instanceof AbstractSelectionRegion) manager.add(delete); final Action copy = new Action("Copy '" + region.getName() + "'", Activator.getImageDescriptor("icons/RegionCopy.png")) { public void run() { staticBuffer = (AbstractSelectionRegion<?>) region; // We also copy the region as a pastable into workflows. ITransferService service = null; try { service = (ITransferService) ServiceManager.getService(ITransferService.class); } catch (Exception e) { logger.error("Cannot get ITransferService!", e); } if (service != null) { try { final Object transferable = service.createROISource(region.getName(), region.getROI()); if (transferable != null) Clipboard.getDefault().setContents(transferable); } catch (Exception ne) { logger.trace("Cannot set the copied region as a workflow actor!", ne); } } } }; if (region instanceof AbstractSelectionRegion) manager.add(copy); return manager; }
From source file:org.dawnsci.plotting.PlottingActionBarManager.java
License:Open Source License
public void registerGroup(String groupName, ManagerType type) { groupName = system.getPlotName() + "/" + groupName; if (getActionBars() != null) { IContributionManager man = null; if (type == ManagerType.TOOLBAR) { man = getActionBars().getToolBarManager(); } else {/*from w ww . ja v a 2s .c o m*/ man = getActionBars().getMenuManager(); } if (man.find(groupName) != null) { man.remove(groupName); } final Separator group = new Separator(groupName); man.add(group); } }
From source file:org.dawnsci.plotting.system.LightWeightPlotActions.java
License:Open Source License
/** * Also uses 'bars' field to add the actions * @param rightClick/*w w w. j a va 2 s. c om*/ */ protected void createAdditionalActions(final XYRegionGraph xyGraph, final IContributionManager rightClick) { if (datasetChoosingRequired) { // By index or using x final CheckableActionGroup group = new CheckableActionGroup(); plotIndex = new Action("Plot data as separate plots", IAction.AS_CHECK_BOX) { public void run() { PlottingSystemActivator.getPlottingPreferenceStore().setValue(PlottingConstants.PLOT_X_DATASET, false); setChecked(true); viewer.getSystem().setXFirst(false); viewer.getSystem().fireTracesAltered(new TraceEvent(xyGraph)); } }; plotIndex.setImageDescriptor(PlottingSystemActivator.getImageDescriptor("icons/plotindex.png")); plotIndex.setId(BasePlottingConstants.PLOT_INDEX); group.add(plotIndex); plotX = new Action("Plot using first data set as x-axis", IAction.AS_CHECK_BOX) { public void run() { PlottingSystemActivator.getPlottingPreferenceStore().setValue(PlottingConstants.PLOT_X_DATASET, true); setChecked(true); viewer.getSystem().setXFirst(true); viewer.getSystem().fireTracesAltered(new TraceEvent(xyGraph)); } }; plotX.setImageDescriptor(PlottingSystemActivator.getImageDescriptor("icons/plotxaxis.png")); plotX.setId(BasePlottingConstants.PLOT_X_AXIS); group.add(plotX); boolean xfirst = PlottingSystemActivator.getPlottingPreferenceStore() .getBoolean(PlottingConstants.PLOT_X_DATASET); if (xfirst) { plotX.setChecked(true); viewer.getSystem().setXFirst(true); } else { plotIndex.setChecked(true); viewer.getSystem().setXFirst(false); } final Action autoHideRegions = new Action("Automatically hide regions", IAction.AS_CHECK_BOX) { public void run() { viewer.getSystem().setAutoHideRegions(isChecked()); } }; autoHideRegions.setChecked(viewer.getSystem().isAutoHideRegions()); autoHideRegions.setToolTipText("Automatically hide regions when the plot dimensionality changes."); actionBarManager.registerAction(autoHideRegions, ActionType.ALL, ManagerType.MENUBAR); MenuAction filters = PlotFilterActions.getXYFilterActions(actionBarManager.getSystem()); actionBarManager.addXYSeparator(); actionBarManager.addXYAction(plotX); actionBarManager.addXYAction(plotIndex); actionBarManager.addXYSeparator(); actionBarManager.addXYAction(filters); actionBarManager.addXYSeparator(); actionBarManager.registerToolBarGroup(ToolbarConfigurationConstants.XYPLOT.getId()); actionBarManager.registerAction(ToolbarConfigurationConstants.XYPLOT.getId(), plotIndex, ActionType.XY); actionBarManager.registerAction(ToolbarConfigurationConstants.XYPLOT.getId(), plotX, ActionType.XY); if (rightClick != null) { rightClick.add(new Separator(plotIndex.getId() + ".group")); rightClick.add(new Separator(plotX.getId() + ".group")); rightClick.add(plotIndex); rightClick.add(plotX); rightClick.add(new Separator()); } } }
From source file:org.dawnsci.plotting.system.LightWeightPlotViewer.java
License:Open Source License
/** * /* www .j av a 2 s.c o m*/ * Problems: * 1. Line trace bounds extend over other line traces so the last line trace added, will * always be the figure that the right click detects. * * Useful things, visible, annotation, quick set to line or points, open configure page. * * @param manager * @param trace * @param xyGraph */ @Override public void fillTraceActions(final IContributionManager manager, final ITrace trace, final IPlottingSystem sys) { manager.add(new Separator("org.dawb.workbench.plotting.system.trace.start")); final String name = trace != null && trace.getName() != null ? trace.getName() : ""; if (trace instanceof ILineTrace) { // Does actually work for images but may confuse people. final Action visible = new Action("Hide '" + name + "'", PlottingSystemActivator.getImageDescriptor("icons/TraceVisible.png")) { public void run() { trace.setVisible(false); } }; manager.add(visible); if (trace instanceof LineTraceImpl) { final Action export = new Action("Export '" + name + "' to ascii (dat file)", PlottingSystemActivator.getImageDescriptor("icons/mask-export-wiz.png")) { public void run() { try { final ICommandService service = (ICommandService) PlatformUI.getWorkbench() .getService(ICommandService.class); final Command export = service .getCommand("org.dawnsci.plotting.export.line.trace.command"); final ExecutionEvent event = new ExecutionEvent(export, Collections.EMPTY_MAP, null, trace); export.executeWithChecks(event); } catch (Exception e) { e.printStackTrace(); } } }; manager.add(export); } } if (xyGraph != null) { if (SelectionRegionFactory.getStaticBuffer() != null) { final Action pasteRegion = new Action( "Paste '" + SelectionRegionFactory.getStaticBuffer().getName() + "'", PlottingSystemActivator.getImageDescriptor("icons/RegionPaste.png")) { public void run() { AbstractSelectionRegion<?> region = null; try { region = (AbstractSelectionRegion<?>) sys.createRegion( SelectionRegionFactory.getStaticBuffer().getName(), SelectionRegionFactory.getStaticBuffer().getRegionType()); region.sync(SelectionRegionFactory.getStaticBuffer().getBean()); } catch (Exception ne) { final String name = RegionUtils.getUniqueName("Region", sys); boolean ok = MessageDialog.openConfirm(Display.getDefault().getActiveShell(), "Cannot paste '" + SelectionRegionFactory.getStaticBuffer().getName() + "'", "A region with the name '" + SelectionRegionFactory.getStaticBuffer().getName() + "' already exists.\n\nWould you like to name the region '" + name + "'?"); if (ok) { try { region = (AbstractSelectionRegion<?>) sys.createRegion(name, SelectionRegionFactory.getStaticBuffer().getRegionType()); } catch (Exception e) { logger.error("Cannot create new region.", e); return; } } else { return; } } region.setROI(SelectionRegionFactory.getStaticBuffer().getROI().copy()); sys.addRegion(region); } }; manager.add(pasteRegion); } final Action addAnnotation = new Action("Add annotation to '" + name + "'", PlottingSystemActivator.getImageDescriptor("icons/TraceAnnotation.png")) { public void run() { final String annotName = AnnotationUtils.getUniqueAnnotation(name + " annotation ", sys); if (trace instanceof LineTraceImpl) { final LineTraceImpl lt = (LineTraceImpl) trace; xyGraph.addAnnotation(new Annotation(annotName, lt.getTrace())); } else { xyGraph.addAnnotation( new Annotation(annotName, xyGraph.primaryXAxis, xyGraph.primaryYAxis)); } } }; manager.add(addAnnotation); } if (trace instanceof ILineTrace) { final ILineTrace lt = (ILineTrace) trace; if (lt.getTraceType() != TraceType.POINT) { // Give them a quick change to points final Action changeToPoints = new Action("Plot '" + name + "' as scatter", PlottingSystemActivator.getImageDescriptor("icons/TraceScatter.png")) { public void run() { lt.setTraceType(TraceType.POINT); lt.setPointSize(8); lt.setPointStyle(PointStyle.XCROSS); } }; manager.add(changeToPoints); } else if (lt.getTraceType() != TraceType.SOLID_LINE) { final Action changeToLine = new Action("Plot '" + name + "' as line", PlottingSystemActivator.getImageDescriptor("icons/TraceLine.png")) { public void run() { lt.setTraceType(TraceType.SOLID_LINE); lt.setLineWidth(1); lt.setPointSize(1); lt.setPointStyle(PointStyle.NONE); } }; manager.add(changeToLine); } } if (xyGraph != null) { final Action configure = new Action("Configure '" + name + "'", PlottingSystemActivator.getImageDescriptor("icons/TraceProperties.png")) { public void run() { final XYRegionConfigDialog dialog = new XYRegionConfigDialog( Display.getDefault().getActiveShell(), xyGraph, getSystem().isRescale()); dialog.setPlottingSystem(sys); dialog.setSelectedTrace(trace); dialog.open(); } }; manager.add(configure); } manager.add(new Separator("org.dawb.workbench.plotting.system.trace.end")); }
From source file:org.dawnsci.plotting.system.PlotActionsManagerImpl.java
License:Open Source License
/** * Create export and print buttons in tool bar *///ww w . j a v a 2 s.c o m protected void createExportActions(IContributionManager toolbarManager) { if (toolbarManager == null) return; final IAction exportActionDropDown = getExportActions(); toolbarManager.add(exportActionDropDown); }
From source file:org.dawnsci.plotting.system.PlotActionsManagerImpl.java
License:Open Source License
@Override public void fillZoomActions(IContributionManager man) { IContributionItem action = system.getActionBars().getToolBarManager() .find(BasePlottingConstants.AUTO_SCALE); if (action != null) man.add(((ActionContributionItem) action).getAction()); for (final ZoomType zoomType : ZoomType.values()) { action = system.getActionBars().getToolBarManager().find(zoomType.getId()); if (action != null) man.add(((ActionContributionItem) action).getAction()); }/*from www . j av a 2 s.c o m*/ }
From source file:org.dawnsci.plotting.system.PlotActionsManagerImpl.java
License:Open Source License
@Override public void fillRegionActions(IContributionManager man) { IContributionItem action = system.getActionBars().getToolBarManager() .find(BasePlottingConstants.ADD_REGION); if (action != null) man.add(((ActionContributionItem) action).getAction()); action = system.getActionBars().getToolBarManager().find(BasePlottingConstants.REMOVE_REGION); if (action != null) man.add(((ActionContributionItem) action).getAction()); }
From source file:org.dawnsci.plotting.system.PlotActionsManagerImpl.java
License:Open Source License
@Override public void fillToolActions(IContributionManager man, ToolPageRole role) { // Find the drop down action for the role. final IContributionItem action = system.getActionBars().getToolBarManager().find(role.getId()); if (action != null) man.add(((ActionContributionItem) action).getAction()); }
From source file:org.dawnsci.plotting.tools.diffraction.DiffractionImageAugmenter.java
License:Open Source License
public void addBeamCenterAction(IContributionManager man) { man.add(beamCentre); }
From source file:org.dawnsci.processing.ui.slice.DataFileSliceView.java
License:Open Source License
private void createActions(IContributionManager rightClick) { final IAction run = new Action("Process all files", Activator.getImageDescriptor("icons/run_workflow.gif")) { public void run() { IOperation<? extends IOperationModel, ? extends OperationData>[] ops = getOperations(); if (ops != null) { final IOperation<? extends IOperationModel, ? extends OperationData>[] fop = ops; fileManager.setProcessingConversionInfo(new IProcessingConversionInfo() { @Override//from w w w .j a va 2s. co m public IOperation<? extends IOperationModel, ? extends OperationData>[] getOperationSeries() { return fop; } @Override public IExecutionVisitor getExecutionVisitor(String fileName) { return new HierarchicalFileExecutionVisitor(fileName); } @Override public ProcessingOutputType getProcessingOutputType() { return processingOutputType; } }); } ExtendedFileSelectionDialog fsd = new ExtendedFileSelectionDialog( Display.getCurrent().getActiveShell()); if (lastPath == null) { final File source = new File(fileManager.getFilePaths().get(0)); lastPath = source.getParent(); } fsd.setPath(lastPath); fsd.create(); if (fsd.open() == Dialog.CANCEL) return; lastPath = fsd.getPath(); File f = new File(lastPath); if (!f.canWrite()) { MessageBox dialog = new MessageBox(getViewSite().getShell(), SWT.ICON_ERROR | SWT.OK); dialog.setText("File save error!"); dialog.setMessage( "Could not save calibration file! (Do you have write access to this directory?)"); dialog.open(); return; } fileManager.setOutputPath(fsd.getPath()); ProgressMonitorDialog dia = new ProgressMonitorDialog(Display.getCurrent().getActiveShell()); try { dia.run(true, true, new IRunnableWithProgress() { @Override public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException { monitor.beginTask("Processing", getAmountOfWork(fileManager.getContext())); fileManager.getContext().setMonitor(new ProgressMonitorWrapper(monitor)); try { cservice.process(fileManager.getContext()); } catch (final Exception e) { Display.getDefault().asyncExec(new Runnable() { public void run() { MessageDialog.openError(DataFileSliceView.this.getViewSite().getShell(), "Error processing files!", e.getMessage()); } }); logger.error(e.getMessage(), e); } } }); } catch (InvocationTargetException e1) { logger.error(e1.getMessage(), e1); } catch (InterruptedException e1) { logger.error(e1.getMessage(), e1); } } }; getViewSite().getActionBars().getToolBarManager().add(run); getViewSite().getActionBars().getMenuManager().add(run); rightClick.add(run); final IAction clear = new Action("Clear selected file", Activator.getImageDescriptor("icons/delete.gif")) { public void run() { clearSelected(); } }; final IAction clearAll = new Action("Clear all files", Activator.getImageDescriptor("icons/deleteAll.gif")) { public void run() { fileManager.clear(); csw.disable(); eventManager.sendInitialDataUpdate(null); job = null; currentSliceLabel.setText("Current slice of data: [ - - - - -]"); try { input.reset(); output.reset(); } catch (Exception e1) { logger.error("Could not clear plotting systems"); } viewer.refresh(); } }; final IAction edit = new Action("Edit slice configuration", Activator.getImageDescriptor("icons/book-brown-setting.png")) { public void run() { fileManager.setUpContext(); } }; final IAction export = new OperationExportAction("Export to Workflow", Activator.getImageDescriptor("icons/flow.png")) { public IOperationContext createContext() { IOperationContext ocontext = oservice.createContext(); ocontext.setSeries(getOperations()); final String selectedPath = (String) ((IStructuredSelection) viewer.getSelection()) .getFirstElement(); if (selectedPath == null) { MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Please Choose File", "Please select a file to use with export.\n\nOne file only may be exported to workflows at a time."); return null; } ocontext.setFilePath(selectedPath); IConversionContext ccontext = fileManager.getContext(); if (ccontext == null) { MessageDialog.openWarning(Display.getDefault().getActiveShell(), "Please Choose File", "Please ensure that a slice and file have been chosen."); return null; } ocontext.setSlicing(ccontext.getSliceDimensions()); ocontext.setDatasetPath(ccontext.getDatasetNames().get(0)); return ocontext; } }; getViewSite().getActionBars().getToolBarManager().add(clear); getViewSite().getActionBars().getMenuManager().add(clear); rightClick.add(clear); getViewSite().getActionBars().getToolBarManager().add(clearAll); getViewSite().getActionBars().getMenuManager().add(clearAll); rightClick.add(clearAll); getViewSite().getActionBars().getToolBarManager().add(edit); getViewSite().getActionBars().getMenuManager().add(edit); rightClick.add(edit); getViewSite().getActionBars().getToolBarManager().add(new Separator()); getViewSite().getActionBars().getMenuManager().add(new Separator()); rightClick.add(new Separator()); getViewSite().getActionBars().getToolBarManager().add(export); getViewSite().getActionBars().getMenuManager().add(export); rightClick.add(export); }