List of usage examples for org.eclipse.jface.viewers IStructuredSelection iterator
@Override
public Iterator iterator();
From source file:com.mentor.nucleus.bp.ui.graphics.actions.CanvasCopyAction.java
License:Open Source License
public static Object getImageDataForSelection(GraphicalEditor editor) { ///*from www.j ava 2 s .c om*/ // 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.actions.CanvasCutAction.java
License:Open Source License
public static boolean selectionContainsOnlyCoreElements() { IStructuredSelection selection = (IStructuredSelection) Selection.getInstance().getStructuredSelection(); for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { Object selected = iterator.next(); if (!(selected instanceof NonRootModelElement)) { return false; }/*from w ww. java 2 s. c om*/ } return true; }
From source file:com.mentor.nucleus.bp.ui.graphics.actions.CanvasPasteAction.java
License:Open Source License
private List<NonRootModelElement> getDestinationsFromSelection(IStructuredSelection selection) { List<NonRootModelElement> destinations = new ArrayList<NonRootModelElement>(); for (Iterator<?> iterator = selection.iterator(); iterator.hasNext();) { Object selected = iterator.next(); if (selected instanceof EditPart) { EditPart part = (EditPart) selected; NonRootModelElement element = (NonRootModelElement) GraphicsUtil.getRepresentsFromEditPart(part); destinations.add(element);//from w w w .ja v a2 s . c o m } } return destinations; }
From source file:com.mentor.nucleus.bp.ui.graphics.actions.RestoreDefaultFillColorAction.java
License:Open Source License
@Override public void run(IAction action) { IStructuredSelection ss = (IStructuredSelection) selection; // UI guarantees selection type // do the following in a transaction for undo/redo support TransactionManager manager = TransactionManager.getSingleton(); Transaction transaction = null;//from w w w . j av a2 s. com try { transaction = manager.startTransaction("Restore Fill Color", new ModelRoot[] { Ooaofooa.getDefaultInstance(), Ooaofgraphics.getDefaultInstance() }); boolean changeMade = false; for (Iterator<?> iterator = ss.iterator(); iterator.hasNext();) { GraphicalEditPart part = (GraphicalEditPart) iterator.next(); // fill is supported for diagrams, shapes and connectors GraphicalElement_c element = null; if (part.getModel() instanceof Shape_c) { element = GraphicalElement_c.getOneGD_GEOnR2((Shape_c) part.getModel()); } if (part.getModel() instanceof Connector_c) { element = GraphicalElement_c.getOneGD_GEOnR2((Connector_c) part.getModel()); } Fillcolorstyle_c fcs = null; if (element != null) { fcs = Fillcolorstyle_c.getOneSTY_FCSOnR400(Elementstyle_c.getManySTY_SsOnR401(element)); Elementstyle_c es = Elementstyle_c.getOneSTY_SOnR400(fcs); fcs.unrelateAcrossR400From(es); es.unrelateAcrossR401From(element); fcs.delete(); es.delete(); changeMade = true; } else { fcs = Fillcolorstyle_c .getOneSTY_FCSOnR400(Elementstyle_c.getManySTY_SsOnR402((Model_c) part.getModel())); Elementstyle_c es = Elementstyle_c.getOneSTY_SOnR400(fcs); fcs.unrelateAcrossR400From(es); es.unrelateAcrossR402From((Model_c) part.getModel()); fcs.delete(); es.delete(); changeMade = true; } } if (!changeMade) { manager.cancelTransaction(transaction); } else { manager.endTransaction(transaction); } } catch (Exception e) { if (transaction != null) { manager.cancelTransaction(transaction); } CorePlugin.logError("Unable to process fill color transaction.", e); } }
From source file:com.mentor.nucleus.bp.ui.graphics.actions.RestoreDefaultLineColorAction.java
License:Open Source License
@Override public void run(IAction action) { IStructuredSelection ss = (IStructuredSelection) selection; // UI guarantees selection type // do the following in a transaction for undo/redo support TransactionManager manager = TransactionManager.getSingleton(); Transaction transaction = null;// ww w . j a v a 2 s. c o m try { transaction = manager.startTransaction("Restore Line Color", new ModelRoot[] { Ooaofooa.getDefaultInstance(), Ooaofgraphics.getDefaultInstance() }); boolean changeMade = false; for (Iterator<?> iterator = ss.iterator(); iterator.hasNext();) { GraphicalEditPart part = (GraphicalEditPart) iterator.next(); // line color is supported for diagrams, shapes and connectors GraphicalElement_c element = null; if (part.getModel() instanceof Shape_c) { element = GraphicalElement_c.getOneGD_GEOnR2((Shape_c) part.getModel()); } if (part.getModel() instanceof Connector_c) { element = GraphicalElement_c.getOneGD_GEOnR2((Connector_c) part.getModel()); } Linecolorstyle_c lcs = null; if (element != null) { lcs = Linecolorstyle_c.getOneSTY_LCSOnR400(Elementstyle_c.getManySTY_SsOnR401(element)); } else { lcs = Linecolorstyle_c .getOneSTY_LCSOnR400(Elementstyle_c.getManySTY_SsOnR402((Model_c) part.getModel())); } if (lcs != null) { Elementstyle_c es = Elementstyle_c.getOneSTY_SOnR400(lcs); lcs.unrelateAcrossR400From(es); es.unrelateAcrossR401From(element); lcs.delete(); es.delete(); changeMade = true; } else { // color will already be default continue; } } if (!changeMade) { manager.cancelTransaction(transaction); } else { manager.endTransaction(transaction); } } catch (Exception e) { if (transaction != null) { manager.cancelTransaction(transaction); } CorePlugin.logError("Unable to process fill color transaction.", e); } }
From source file:com.mentor.nucleus.bp.ui.graphics.actions.SetCustomFillColorAction.java
License:Open Source License
@Override public void run(IAction action) { if (selection instanceof IStructuredSelection) { // first have the user choose the color ColorDialog colorChooser = new ColorDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell()); RGB color = colorChooser.open(); if (color == null) { // user canceled return; }/*from ww w . ja v a 2 s .co m*/ IStructuredSelection ss = (IStructuredSelection) selection; // UI guarantees selection type // do the following in a transaction for undo/redo support TransactionManager manager = TransactionManager.getSingleton(); Transaction transaction = null; try { transaction = manager.startTransaction("Set Fill Color", new ModelRoot[] { Ooaofooa.getDefaultInstance(), Ooaofgraphics.getDefaultInstance() }); for (Iterator<?> iterator = ss.iterator(); iterator.hasNext();) { GraphicalEditPart part = (GraphicalEditPart) iterator.next(); // fill is supported for diagrams, shapes and connectors GraphicalElement_c element = null; if (part.getModel() instanceof Shape_c) { element = GraphicalElement_c.getOneGD_GEOnR2((Shape_c) part.getModel()); } if (part.getModel() instanceof Connector_c) { element = GraphicalElement_c.getOneGD_GEOnR2((Connector_c) part.getModel()); } Fillcolorstyle_c fcs = null; if (element != null) { fcs = Fillcolorstyle_c.getOneSTY_FCSOnR400(Elementstyle_c.getManySTY_SsOnR401(element)); } else { fcs = Fillcolorstyle_c .getOneSTY_FCSOnR400(Elementstyle_c.getManySTY_SsOnR402((Model_c) part.getModel())); } if (fcs == null) { // create fill style and associate with graphic fcs = new Fillcolorstyle_c(((NonRootModelElement) part.getModel()).getModelRoot()); fcs.setRed(color.red); fcs.setBlue(color.blue); fcs.setGreen(color.green); Elementstyle_c style = new Elementstyle_c( ((NonRootModelElement) part.getModel()).getModelRoot()); style.relateAcrossR400To(fcs); if (part.getModel() instanceof Model_c) { style.relateAcrossR402To((Model_c) part.getModel()); } else { style.relateAcrossR401To(element); } } else { fcs.setRed(color.red); fcs.setBlue(color.blue); fcs.setGreen(color.green); } } manager.endTransaction(transaction); } catch (Exception e) { if (transaction != null) { manager.cancelTransaction(transaction); } CorePlugin.logError("Unable to process fill color transaction.", e); } } }
From source file:com.mentor.nucleus.bp.ui.graphics.actions.SetCustomLineColorAction.java
License:Open Source License
@Override public void run(IAction action) { if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; if (ss.getFirstElement() instanceof DiagramEditPart) { // unsupported at this time return; }//from ww w .j a v a2 s. co m // first have the user choose the color ColorDialog colorChooser = new ColorDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell()); RGB color = colorChooser.open(); if (color == null) { // user canceled return; } // UI guarantees selection type // do the following in a transaction for undo/redo support TransactionManager manager = TransactionManager.getSingleton(); Transaction transaction = null; try { transaction = manager.startTransaction("Set Line Color", new ModelRoot[] { Ooaofooa.getDefaultInstance(), Ooaofgraphics.getDefaultInstance() }); for (Iterator<?> iterator = ss.iterator(); iterator.hasNext();) { GraphicalEditPart part = (GraphicalEditPart) iterator.next(); // fill is enabled for shapes and connectors GraphicalElement_c element = null; if (part.getModel() instanceof Shape_c) { Shape_c shape = (Shape_c) part.getModel(); element = GraphicalElement_c.getOneGD_GEOnR2(shape); } else if (part.getModel() instanceof Connector_c) { Connector_c connector = (Connector_c) part.getModel(); element = GraphicalElement_c.getOneGD_GEOnR2(connector); } Linecolorstyle_c lcs = Linecolorstyle_c .getOneSTY_LCSOnR400(Elementstyle_c.getManySTY_SsOnR401(element)); if (lcs == null) { // create fill style and associate with graphic lcs = new Linecolorstyle_c(element.getModelRoot()); lcs.setRed(color.red); lcs.setBlue(color.blue); lcs.setGreen(color.green); Elementstyle_c style = new Elementstyle_c(element.getModelRoot()); style.relateAcrossR400To(lcs); style.relateAcrossR401To(element); } else { lcs.setRed(color.red); lcs.setBlue(color.blue); lcs.setGreen(color.green); } } manager.endTransaction(transaction); } catch (Exception e) { if (transaction != null) { manager.cancelTransaction(transaction); } CorePlugin.logError("Unable to process fill color transaction.", e); } } }
From source file:com.mentor.nucleus.bp.ui.graphics.actions.SetFontAction.java
License:Open Source License
@Override public void run(IAction action) { if (selection instanceof IStructuredSelection) { // first have the user choose the color FontDialog fontDialog = new FontDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell()); FontData fontData = fontDialog.open(); if (fontData == null) { // user canceled return; }//from w ww .j a v a2 s .c o m IStructuredSelection ss = (IStructuredSelection) selection; // UI guarantees selection type // do the following in a transaction for undo/redo support TransactionManager manager = TransactionManager.getSingleton(); Transaction transaction = null; try { transaction = manager.startTransaction("Set Font Data", new ModelRoot[] { Ooaofooa.getDefaultInstance(), Ooaofgraphics.getDefaultInstance() }); for (Iterator<?> iterator = ss.iterator(); iterator.hasNext();) { GraphicalEditPart part = (GraphicalEditPart) iterator.next(); // fill is enabled for shapes and connectors GraphicalElement_c element = null; if (part.getModel() instanceof Shape_c) { Shape_c shape = (Shape_c) part.getModel(); element = GraphicalElement_c.getOneGD_GEOnR2(shape); } else if (part.getModel() instanceof Connector_c) { Connector_c connector = (Connector_c) part.getModel(); element = GraphicalElement_c.getOneGD_GEOnR2(connector); } Fontstyle_c fs = Fontstyle_c.getOneSTY_FSOnR400(Elementstyle_c.getOneSTY_SOnR401(element)); if (fs == null) { // create fill style and associate with graphic fs = new Fontstyle_c(element.getModelRoot()); fs.setFont_identifier(fontData.toString()); Elementstyle_c style = new Elementstyle_c(element.getModelRoot()); style.relateAcrossR400To(fs); style.relateAcrossR401To(element); } else { fs.setFont_identifier(fontData.toString()); } } manager.endTransaction(transaction); } catch (Exception e) { if (transaction != null) { manager.cancelTransaction(transaction); } CorePlugin.logError("Unable to process fill color transaction.", e); } } }
From source file:com.mentor.nucleus.bp.ui.graphics.actions.SetObliqueRoutingAction.java
License:Open Source License
@Override public void run(IAction action) { if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; for (Iterator<?> iterator = ss.iterator(); iterator.hasNext();) { ConnectorEditPart selected = (ConnectorEditPart) iterator.next(); DiagramEditPart diagramPart = (DiagramEditPart) selected.getViewer().getContents(); ((DecoratedPolylineConnection) selected.getFigure()) .internalSetConnectionRouter(diagramPart.getBendpointConnectionRouter()); selected.removeEditPolicy(EditPolicy.CONNECTION_BENDPOINTS_ROLE); selected.installEditPolicy(EditPolicy.CONNECTION_BENDPOINTS_ROLE, new ConnectorBendPointEditPolicy()); selected.removeEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); selected.installEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE, new ConnectorMoveEditPolicy(selected)); selected.getFigure().revalidate(); selected.storeRouterSetting(); selected.refresh();//from w w w. ja va 2 s . com } } }
From source file:com.mentor.nucleus.bp.ui.graphics.actions.SetRectilinearRoutingAction.java
License:Open Source License
@Override public void run(IAction action) { if (selection instanceof IStructuredSelection) { IStructuredSelection ss = (IStructuredSelection) selection; for (Iterator<?> iterator = ss.iterator(); iterator.hasNext();) { ConnectorEditPart selected = (ConnectorEditPart) iterator.next(); DiagramEditPart diagramPart = (DiagramEditPart) selected.getViewer().getContents(); ((DecoratedPolylineConnection) selected.getFigure()) .internalSetConnectionRouter(diagramPart.getRectilinearConnectionRouter()); selected.removeEditPolicy(EditPolicy.CONNECTION_BENDPOINTS_ROLE); selected.installEditPolicy(EditPolicy.CONNECTION_BENDPOINTS_ROLE, new GraphicsConnectionLineSegPolicy()); selected.removeEditPolicy(EditPolicy.PRIMARY_DRAG_ROLE); selected.storeRouterSetting(); selected.refresh();//from w ww .j av a 2 s .c o m } } }