List of usage examples for org.eclipse.jface.viewers IStructuredSelection isEmpty
public boolean isEmpty();
From source file:com.mentor.nucleus.bp.ui.graphics.actions.CanvasCopyAction.java
License:Open Source License
public static Object getImageDataForSelection(GraphicalEditor editor) { //// w w w . j a v a2 s . co m // Compute the required height and width to render boolean considerAll = false; IStructuredSelection selection = (IStructuredSelection) editor.getSite().getSelectionProvider() .getSelection(); if (!selection.isEmpty()) { if (selection.size() == 1 && selection.getFirstElement() instanceof DiagramEditPart) { // treat this as no selection considerAll = true; } } List<GraphicalEditPart> symbols = new ArrayList<GraphicalEditPart>(); if (considerAll) { symbols = GraphicalEditor.getAllSymbols((GraphicalViewer) editor.getAdapter(GraphicalViewer.class), editor.getModel().Hascontainersymbol()); } else { for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { Object next = iterator.next(); if (next instanceof GraphicalEditPart) { if (next instanceof DiagramEditPart) continue; else symbols.add((GraphicalEditPart) next); } } } Rectangle extentRectangle = GraphicalZoomManager.getExtentRectangle(symbols); // // Set up the canvas for drawing. Rectangle client = new Rectangle(extentRectangle.x, extentRectangle.y, extentRectangle.width, extentRectangle.height); Image canvasImage = new Image(editor.getCanvas().getDisplay(), new org.eclipse.swt.graphics.Rectangle(client.x, client.y, client.width, client.height)); GraphicalViewer viewer = (GraphicalViewer) editor.getAdapter(GraphicalViewer.class); PrintDiagramOperation.printImage(canvasImage, viewer, extentRectangle, editor.getModel().Hascontainersymbol(), PrintDiagramOperation.NO_FIT); return canvasImage.getImageData(); }
From source file:com.mentor.nucleus.bp.ui.graphics.editor.GraphicalEditor.java
License:Open Source License
/** * Fire up an editor/*from w w w . ja v a2 s.c o m*/ */ public static void handleOpen(Point location, Model_c model, IStructuredSelection selection) { if (!selection.isEmpty()) { Object current = selection.iterator().next(); if (current instanceof EditPart) { current = ((EditPart) current).getModel(); if (current instanceof FloatingText_c) { FloatingText_c text = (FloatingText_c) current; Connector_c connector = Connector_c.getOneGD_CONOnR8(text); if (connector != null) current = connector; Shape_c shape = Shape_c.getOneGD_SHPOnR27(text); if (shape != null) current = shape; } if (current instanceof Model_c) { current = ((Model_c) current).getRepresents(); } else if (current instanceof Shape_c) { GraphicalElement_c elem = GraphicalElement_c.getOneGD_GEOnR2((Shape_c) current); current = elem.getRepresents(); } else if (current instanceof Connector_c) { GraphicalElement_c elem = GraphicalElement_c.getOneGD_GEOnR2((Connector_c) current); current = elem.getRepresents(); } } // if a mouse event was given, and the selected element is a // model-class if (location != null && current instanceof ModelClass_c) { // find the graphical element that represents the selected // model-class final Object finalCurrent = current; GraphicalElement_c element = GraphicalElement_c.GraphicalElementInstance(model.getModelRoot(), new ClassQueryInterface_c() { public boolean evaluate(Object candidate) { return ((GraphicalElement_c) candidate).getRepresents() == finalCurrent; } }); // ask the shape associated with the above graphical-element // what // the mouse-event represents a double-click on, since the shape // may be displaying an icon which is a link to a different // model // element Shape_c shape = Shape_c.getOneGD_SHPOnR2(element); Graphelement_c graphElement = Graphelement_c.getOneDIM_GEOnR23(element); current = shape.Getrepresents((int) (location.x - graphElement.getPositionx()), (int) (location.y - graphElement.getPositiony())); } // see if the current element should open // something other than itself current = EditorUtil.getElementToEdit(current); String name = current.getClass().getName(); // // Get the registry // IExtensionRegistry reg = Platform.getExtensionRegistry(); // // Get all the plugins that have extended this point // IExtensionPoint extPt = reg.getExtensionPoint("com.mentor.nucleus.bp.core.editors"); //$NON-NLS-1$ IExtension[] exts = extPt.getExtensions(); // Repeat for each extension until we find a default editor for (int i = 0; i < exts.length; i++) { IConfigurationElement[] elems = exts[i].getConfigurationElements(); for (int j = 0; j < elems.length; j++) { // Find the editor elements if (elems[j].getName().equals("editor")) { //$NON-NLS-1$ IConfigurationElement[] edElems = elems[j].getChildren(); for (int k = 0; k < edElems.length; k++) { // // Is this editor the default for the current model // element ? // if (edElems[k].getName().equals("defaultFor") && //$NON-NLS-1$ edElems[k].getAttribute("class").equals(name)) { try { // // Get the class supplied for the input // // always use this bundle, other graphical // plug-ins // will provide their own open method Bundle bundle = Platform.getBundle(elems[j].getContributor().getName()); Class<?> inputClass = bundle.loadClass(elems[j].getAttribute("input")); //$NON-NLS-1$ Class<?>[] type = new Class[1]; type[0] = Object.class; // // Dynamically get the method // createInstance, the supplied class must // implement this // Method createInstance = inputClass.getMethod("createInstance", type); //$NON-NLS-1$ Object[] args = new Object[1]; args[0] = current; // // Invoke the method. // The method is static; no instance is // needed, so first argument is null // IEditorInput input = (IEditorInput) createInstance.invoke(null, args); // // pass the input to the Eclipse editor, // along with the class name supplied by // the extending plugin. // if (input != null) { PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .openEditor(input, elems[j].getAttribute("class")); //$NON-NLS-1$ } return; } catch (ClassNotFoundException e) { CanvasPlugin.logError("Input Class not found", e); //$NON-NLS-1$ } catch (NoSuchMethodException e) { CanvasPlugin.logError("Class does not implement static method createInstance", //$NON-NLS-1$ e); } catch (InvocationTargetException e) { CanvasPlugin.logError( "Exception occured on invocation of static method createInstance of the Target", //$NON-NLS-1$ e.getTargetException()); } catch (IllegalAccessException e) { CanvasPlugin.logError("Target does not support static method createInstance", //$NON-NLS-1$ e); } catch (PartInitException e) { CanvasPlugin.logError("Could not activate Editor", e); //$NON-NLS-1$ } } } } } } } }
From source file:com.mentor.nucleus.bp.ui.graphics.outline.GraphicalOutlinePage.java
License:Open Source License
/** * Fire up an editor//from w w w.j ava 2s .co m */ private void handleOpen() { IStructuredSelection sel = Selection.getInstance().getStructuredSelection(); if (sel.isEmpty()) { return; } Object current = (sel).iterator().next(); String name = current.getClass().getName(); // see if the current element should open // something other than itself current = EditorUtil.getElementToEdit(current); // // Get the registry // IExtensionRegistry reg = Platform.getExtensionRegistry(); // // Get all the plugins that have extended this point // IExtensionPoint extPt = reg.getExtensionPoint("com.mentor.nucleus.bp.core.editors"); IExtension[] exts = extPt.getExtensions(); // Repeat for each extension until we find a default editor for (int i = 0; i < exts.length; i++) { IConfigurationElement[] elems = exts[i].getConfigurationElements(); for (int j = 0; j < elems.length; j++) { // Find the editor elements if (elems[j].getName().equals("editor")) { IConfigurationElement[] edElems = elems[j].getChildren(); for (int k = 0; k < edElems.length; k++) { // // Is this editor the default for the current model // element ? // if (edElems[k].getName().equals("defaultFor") && edElems[k].getAttribute("class").equals(name)) { try { // // Get the class supplied for the input // Bundle bundle = Platform .getBundle(elems[j].getDeclaringExtension().getNamespaceIdentifier()); Class<?> inputClass = bundle.loadClass(elems[j].getAttribute("input")); //$NON-NLS-1$ Class<?>[] type = new Class[1]; type[0] = Object.class; // // Dynamically get the method createInstance, // the supplied class must implement this // Method createInstance = inputClass.getMethod("createInstance", type); //$NON-NLS-1$ Object[] args = new Object[1]; args[0] = current; // // Invoke the method. // The method is static; no instance is needed, // so first argument is null // IEditorInput input = (IEditorInput) createInstance.invoke(null, args); // // pass the input to the Eclipse editor, along // with the class name supplied by // the extending plugin. // if (input != null) { PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage() .openEditor(input, elems[j].getAttribute("class")); //$NON-NLS-1$ } return; } catch (ClassNotFoundException e) { CanvasPlugin.logError("Input Class not found", e); //$NON-NLS-1$ } catch (NoSuchMethodException e) { CanvasPlugin.logError("Class does not implement static method createInstance", e); //$NON-NLS-1$ } catch (InvocationTargetException e) { CanvasPlugin.logError( "Exception occured on invocation of static method createInstance of the Target", //$NON-NLS-1$ e.getTargetException()); } catch (IllegalAccessException e) { CanvasPlugin.logError("Target does not support static method createInstance", e); //$NON-NLS-1$ } catch (PartInitException e) { CanvasPlugin.logError("Could not activate Editor", e); //$NON-NLS-1$ } } } } } } }
From source file:com.mentor.nucleus.bp.ui.graphics.providers.CanvasEditorContextMenuProvider.java
License:Open Source License
public static boolean enableDelete(IStructuredSelection graphicalSelection) { boolean enableDel = false; List<Object> elements = new ArrayList<Object>(); IStructuredSelection selection = Selection.getInstance().getStructuredSelection(); if (!selection.isEmpty()) { if (graphicalSelection.getFirstElement() instanceof DiagramEditPart) return false; enableDel = true;//from w w w.j av a2s. c o m // Iterate through removing elements that are only graphical for (Iterator<?> iter = selection.iterator(); iter.hasNext();) { Object current = iter.next(); if (current instanceof GraphicalElement_c) { GraphicalElement_c ge = (GraphicalElement_c) current; if (ge.getRepresents() == null) { elements.add(current); Selection.getInstance().removeFromSelection(ge); } } } } selection = Selection.getInstance().getStructuredSelection(); if (!selection.isEmpty()) { // Check the remaining items against the usual DeleteAction, enableDel = DeleteAction.canDeleteAction(); } // Add the graphical only elements back to the selection for (int i = 0; i < elements.size(); ++i) { Selection.getInstance().addToSelection(elements.get(i)); } return enableDel; }
From source file:com.mercatis.lighthouse3.ui.environment.handlers.CollapseAllHandler.java
License:Apache License
public Object execute(ExecutionEvent event) throws ExecutionException { CommonNavigator navigator = (CommonNavigator) HandlerUtil.getActivePart(event); ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection == null || !(selection instanceof IStructuredSelection)) return null; IStructuredSelection structuredSelection = (IStructuredSelection) selection; if (!structuredSelection.isEmpty()) { navigator.getCommonViewer().collapseToLevel(structuredSelection.getFirstElement(), AbstractTreeViewer.ALL_LEVELS); }/*from ww w . j av a 2s .c om*/ return null; }
From source file:com.mercatis.lighthouse3.ui.environment.handlers.ExpandAllHandler.java
License:Apache License
public Object execute(ExecutionEvent event) throws ExecutionException { CommonNavigator navigator = (CommonNavigator) HandlerUtil.getActivePart(event); ISelection selection = HandlerUtil.getCurrentSelection(event); if (selection == null || !(selection instanceof IStructuredSelection)) return null; IStructuredSelection structuredSelection = (IStructuredSelection) selection; if (!structuredSelection.isEmpty()) { navigator.getCommonViewer().expandToLevel(structuredSelection.getFirstElement(), AbstractTreeViewer.ALL_LEVELS); }//from w w w . java 2 s .com return null; }
From source file:com.microsoft.tfs.client.common.ui.framework.diagnostics.ui.DataProviderTreeControl.java
License:Open Source License
public DataProviderTreeControl(final Composite parent, final int style, final DataProviderCollection dataProviderCollection) { super(parent, style); final FormLayout layout = new FormLayout(); layout.marginWidth = 0;/*from w w w. j a va 2s . c o m*/ layout.marginHeight = 0; setLayout(layout); final Sash sash = new Sash(this, SWT.VERTICAL); FormData data = new FormData(); data.top = new FormAttachment(0, 0); data.bottom = new FormAttachment(100, 0); data.left = new FormAttachment(33, 0); sash.setLayoutData(data); sash.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(final SelectionEvent e) { ((FormData) sash.getLayoutData()).left = new FormAttachment(0, e.x); sash.getParent().layout(); } }); treeViewer = new TreeViewer(this, SWT.BORDER); data = new FormData(); data.left = new FormAttachment(0, 0); data.top = new FormAttachment(0, 0); data.bottom = new FormAttachment(100, 0); data.right = new FormAttachment(sash, 0, SWT.LEFT); treeViewer.getTree().setLayoutData(data); treeViewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override public void selectionChanged(final SelectionChangedEvent event) { final IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (!selection.isEmpty() && selection.getFirstElement() instanceof DataProviderWrapper) { final DataProviderWrapper dataProvider = (DataProviderWrapper) selection.getFirstElement(); outputControl.setData(dataProvider); } else { outputControl.setData(null); } } }); outputControl = new DataProviderOutputControl(this, SWT.NONE); data = new FormData(); data.left = new FormAttachment(sash, 0, SWT.RIGHT); data.top = new FormAttachment(treeViewer.getTree(), 0, SWT.TOP); data.right = new FormAttachment(100, 0); data.bottom = new FormAttachment(100, 0); outputControl.setLayoutData(data); treeViewer.setContentProvider(new ContentProvider()); treeViewer.setLabelProvider(new LabelProvider()); treeViewer.setInput(dataProviderCollection); treeViewer.setExpandedElements(dataProviderCollection.getSortedCategories()); }
From source file:com.mobilesorcery.sdk.testing.internal.ui.UnittestView.java
License:Open Source License
void handleMenuAboutToShow(IMenuManager manager) { IStructuredSelection selection = (IStructuredSelection) testRun.getSelectionProvider().getSelection(); ITestSession session = testRun.getTestSession(); if (session instanceof IRelaunchableTestSession) { manager.add(new RerunAction()); manager.add(new Separator()); }//w w w . j a v a 2s . c o m if (!selection.isEmpty()) { ITest testElement = (ITest) selection.getFirstElement(); gotoLineAction.setSelection(selection); manager.add(gotoLineAction); if (session.getTestCount() > 0) { manager.add(new ExpandAllAction()); } } manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS)); manager.add(new Separator(IWorkbenchActionConstants.MB_ADDITIONS + "-end")); //$NON-NLS-1$ }
From source file:com.mountainminds.eclemma.internal.ui.coverageview.CopyAction.java
License:Open Source License
public void selectionChanged(IStructuredSelection selection) { setEnabled(!selection.isEmpty()); }
From source file:com.nabsys.nabeeplus.editors.ServerConfigEditor.java
private void genButtonSelectionListener() { btnSelection = new SelectionListener() { public void widgetSelected(SelectionEvent e) { if (e.widget == btnAddProtocol) { if (((Protocol) protocolTable.getInput()).getChildren().size() > 0 && ((Protocol) ((Protocol) protocolTable.getInput()).getChildren() .get(((Protocol) protocolTable.getInput()).getChildren().size() - 1)).getID() .equals("New")) return; new Protocol(protocolRoot, "New"); protocolTable.refresh(); setSendMessage("U", "PCL", "ID", "New", "New", null); setSendMessage("U", "PCL", "NAME", "New", "", null); setSendMessage("U", "PCL", "CLASS", "New", "", null); isModified = true;// w w w. j av a2 s.c o m firePropertyChange(PROP_DIRTY); } else if (e.widget == btnDelProtocol) { if (IMessageBox.Confirm(shell, NBLabel.get(0x0092)) == SWT.CANCEL) { return; } IStructuredSelection selection = (IStructuredSelection) protocolTable.getSelection(); if (selection.isEmpty()) return; Protocol protocol = ((Protocol) selection.getFirstElement()); setSendMessage("D", "PCL", "", protocol.getID(), "", null); protocol.remove(); protocolTable.refresh(); isModified = true; firePropertyChange(PROP_DIRTY); } else if (e.widget == btnAddPlugin) { if (((Plugin) pluginTable.getInput()).getChildren().size() > 0 && ((Plugin) ((Plugin) pluginTable.getInput()).getChildren() .get(((Plugin) pluginTable.getInput()).getChildren().size() - 1)).getID() .equals("New")) return; Plugin tmp = new Plugin(pluginRoot, "New"); tmp.setPluginType(PluginTypeArray.OTHER); pluginTable.refresh(); setSendMessage("U", "PLG", "ID", "New", "New", null); setSendMessage("U", "PLG", "NAME", "New", "", null); setSendMessage("U", "PLG", "TYPE", "New", "OTHER", null); isModified = true; firePropertyChange(PROP_DIRTY); } else if (e.widget == btnDelPlugin) { if (IMessageBox.Confirm(shell, NBLabel.get(0x0092)) == SWT.CANCEL) { return; } IStructuredSelection selection = (IStructuredSelection) pluginTable.getSelection(); if (selection.isEmpty()) return; Plugin plugin = ((Plugin) selection.getFirstElement()); setSendMessage("D", "PLG", "", plugin.getID(), "", null); plugin.remove(); pluginTable.refresh(); paramRoot.getChildren().removeAll(paramRoot.getChildren()); paramTable.refresh(); isModified = true; firePropertyChange(PROP_DIRTY); } else if (e.widget == btnAddParam) { if (paramTable.getData("PID") == null || ((String) paramTable.getData("PID")).equals("")) { IMessageBox.Error(shell, NBLabel.get(0x0184)); return; } if (((Param) paramTable.getInput()).getChildren().size() > 0 && ((Param) ((Param) paramTable.getInput()).getChildren() .get(((Param) paramTable.getInput()).getChildren().size() - 1)).getID() .equals("New")) return; new Param(paramRoot, "New"); paramTable.refresh(); setSendMessage("U", "PRM", "ID", "New", "New", (String) paramTable.getData("PID")); setSendMessage("U", "PRM", "VALUE", "New", "", (String) paramTable.getData("PID")); HashMap<String, String> tmpParam = paramMap.get((String) paramTable.getData("PID")); tmpParam.put("New", ""); isModified = true; firePropertyChange(PROP_DIRTY); } else if (e.widget == btnDelParam) { if (IMessageBox.Confirm(shell, NBLabel.get(0x0092)) == SWT.CANCEL) { return; } IStructuredSelection selection = (IStructuredSelection) paramTable.getSelection(); if (selection.isEmpty()) return; Param param = ((Param) selection.getFirstElement()); setSendMessage("D", "PRM", "", param.getID(), "", (String) paramTable.getData("PID")); param.remove(); paramTable.refresh(); HashMap<String, String> tmpParam = paramMap.get((String) paramTable.getData("PID")); tmpParam.remove(param.getID()); isModified = true; firePropertyChange(PROP_DIRTY); } /*else if(e.widget == importConfig) { importConfigFile(); } else if(e.widget == exportConfig) { exportConfigFile(); }*/ } public void widgetDefaultSelected(SelectionEvent e) { } }; }