public Object getAdapter(Class adapter) { if (adapter == GraphicalViewer.class || adapter == EditPartViewer.class) return getGraphicalViewer(); else if (adapter == CommandStack.class) return getCommandStack(); else if (adapter == EditDomain.class) return getEditDomain(); else if (adapter == ActionRegistry.class) return getActionRegistry(); else if (adapter == IPropertySheetPage.class) return new PropertiesView(true); else if (adapter == IContentOutlinePage.class) { return new GW4EOutlinePage(); } else if (adapter == ZoomManager.class) return ((ScalableRootEditPart) getGraphicalViewer().getRootEditPart()).getZoomManager(); return super.getAdapter(adapter); }
/** {@inheritDoc} */ @Override public void createEditPolicies() { if (!((Shape) getModel()).getType().equals(Type.RELATIONSHIP_SHAPE_CHILD)) { // edit policy for handling requests of editing the shape name installEditPolicy(EditPolicy.DIRECT_EDIT_ROLE, new ORMNamedElementDirectEditPolicy()); installEditPolicy("Snap Feedback", new SnapFeedbackPolicy()); // edit policy, which handels requests for deleting the shape, which is controlled // through this edit part installEditPolicy(EditPolicy.COMPONENT_ROLE, new ORMShapeComponentEditPolicy(this)); // the ORMNodeGraphicalNodeEditPolicy shouldn't be installes for shapes from type // compartmenttype and group, where the user stepped into if (!(getParent() instanceof ScalableRootEditPart)) { installEditPolicy(EditPolicy.GRAPHICAL_NODE_ROLE, new ORMShapeGraphicalNodeEditPolicy()); } } }
@Override protected void configureToolBar(final IToolBarManager manager) { super.configureToolBar(manager); final IDiagramOutputActionFactory factory = JiveUIPlugin.getDefault() .getDiagramOutputActionFactory(); final ScalableRootEditPart root = (ScalableRootEditPart) viewer.getRootEditPart(); final IAction zoomIn = new ZoomInAction(root.getZoomManager()); final IAction zoomOut = new ZoomOutAction(root.getZoomManager()); final IUpdatableAction saveAs = factory.createDiagramExportAction(viewer); final IUpdatableAction print = factory.createPrintAction(viewer); addUpdatableAction(saveAs); addUpdatableAction(print); // reference: http://dev.eclipse.org/newslists/news.eclipse.platform/msg60866.html // register action handlers for zoom in and zoom out: final IHandlerService handlerService = (IHandlerService) getSite().getService( IHandlerService.class); handlerService.activateHandler(zoomIn.getActionDefinitionId(), new ActionHandler(zoomIn)); handlerService.activateHandler(zoomOut.getActionDefinitionId(), new ActionHandler(zoomOut)); manager.insertBefore(AbstractJiveView.GROUP_STEP_CONTROLS, new Separator( AbstractGraphicalJiveView.ZOOM_CONTROLS_GROUP)); manager.appendToGroup(AbstractGraphicalJiveView.ZOOM_CONTROLS_GROUP, saveAs); manager.appendToGroup(AbstractGraphicalJiveView.ZOOM_CONTROLS_GROUP, print); manager.appendToGroup(AbstractGraphicalJiveView.ZOOM_CONTROLS_GROUP, zoomIn); manager.appendToGroup(AbstractGraphicalJiveView.ZOOM_CONTROLS_GROUP, zoomOut); }
@Override protected void initializeViewer(final Composite parent) { parent.setLayout(new FillLayout()); // Create the viewer using the supplied parent viewer = createGraphicalViewer(); final Control c = viewer.createControl(parent); c.setBackground(ColorConstants.white); // Create and initialize the root edit part final ScalableRootEditPart root = new ScalableRootEditPart(); viewer.setRootEditPart(root); viewer.setEditDomain(new DefaultEditDomain(null)); // Create and initialize the edit part factory final EditPartFactory factory = createEditPartFactory(); viewer.setEditPartFactory(factory); // Register the viewer as a selection provider getSite().setSelectionProvider(viewer); }
@Override public void run() { if (file == null) return; log.trace("export product graph as image: {}", file); ScalableRootEditPart editPart = (ScalableRootEditPart) editor.getGraphicalViewer().getRootEditPart(); IFigure rootFigure = editPart.getLayer(LayerConstants.PRINTABLE_LAYERS); Rectangle bounds = rootFigure.getBounds(); Image img = new Image(null, bounds.width, bounds.height); GC imageGC = new GC(img); Graphics graphics = new SWTGraphics(imageGC); rootFigure.paint(graphics); ImageLoader imgLoader = new ImageLoader(); imgLoader.data = new ImageData[] { img.getImageData() }; imgLoader.save(file.getAbsolutePath(), SWT.IMAGE_PNG); }
public void activate() { super.activate(); ScalableRootEditPart root = (ScalableRootEditPart) getViewer().getRootEditPart(); ConnectionLayer connLayer = (ConnectionLayer) root.getLayer(LayerConstants.CONNECTION_LAYER); GraphicalEditPart contentEditPart = (GraphicalEditPart) root.getContents(); FanRouter router = new FanRouter(); router.setSeparation(100); ShortestPathConnectionRouter spRouter = new ShortestPathConnectionRouter(contentEditPart.getFigure()); router.setNextRouter(spRouter); connLayer.setConnectionRouter(router); GraphSelectionManager.ME.selectionPartChanged(this); }
public void selectionPartChanged(GraphPart part) { if (part == null) return; EditPart ep = part.getParent(); if (ep instanceof ScalableRootEditPart) { ScalableRootEditPart srep = (ScalableRootEditPart) ep; selection.setEditPartViewer(srep.getViewer()); } selection.setGpart(part); }
public Object getAdapter(Class adapter) { if(adapter == GraphicalViewer.class || adapter == EditPartViewer.class) { return getGraphicalViewer(); } else if(adapter == ZoomManager.class) { return ((ScalableRootEditPart) getGraphicalViewer().getRootEditPart()).getZoomManager(); } else if (adapter == IContentOutlinePage.class) { return getOverviewOutlinePage(); } return super.getAdapter(adapter); }
protected OverviewOutlinePage getOverviewOutlinePage() { if(null == overviewOutlinePage && null != getGraphicalViewer()) { RootEditPart rootEditPart = getGraphicalViewer().getRootEditPart(); if(rootEditPart instanceof ScalableRootEditPart) { overviewOutlinePage = new OverviewOutlinePage( (ScalableRootEditPart) rootEditPart); } } return overviewOutlinePage; }
protected void configureGraphicalViewer() { super.configureGraphicalViewer(); GraphicalViewer viewer = getGraphicalViewer(); ScalableRootEditPart root = new ScalableRootEditPart(); viewer.setRootEditPart(root); viewer.setEditPartFactory(new GraphEditPartFactory(viewer)); viewer.setContents("Loading graph... This can take several minutes"); ContextMenuProvider cmProvider = new RevisionGraphMenuProvider(viewer, this); viewer.setContextMenu(cmProvider); getSite().setSelectionProvider(viewer); IEditorInput input = getEditorInput(); if(input instanceof FileEditorInput) { FileEditorInput fileEditorInput = (FileEditorInput) input; showGraphFor(fileEditorInput.getFile()); } else if(input instanceof RevisionGraphEditorInput) { RevisionGraphEditorInput editorInput = (RevisionGraphEditorInput) input; showGraphFor(editorInput); } // zoom stuff ZoomManager zoomManager = ((ScalableRootEditPart) viewer.getRootEditPart()).getZoomManager(); IAction zoomIn = new ZoomInAction(zoomManager); IAction zoomOut = new ZoomOutAction(zoomManager); getActionRegistry().registerAction(zoomIn); getActionRegistry().registerAction(zoomOut); // keyboard getSite().getKeyBindingService().registerAction(zoomIn); // FIXME, deprecated getSite().getKeyBindingService().registerAction(zoomOut); // FIXME, deprecated List zoomContributions = Arrays.asList(new String[] { ZoomManager.FIT_ALL, ZoomManager.FIT_HEIGHT, ZoomManager.FIT_WIDTH }); zoomManager.setZoomLevelContributions(zoomContributions); // mouse wheel viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.MOD1), MouseWheelZoomHandler.SINGLETON); }
/** * {@inheritDoc} The refreshVisuals of this {@link EditPart} updates/adds the {@link Bendpoint}s * of a {@link Relation}. The content of this method should only be called when the * compartmenttype/group/rootmodel where this {@link Relation}s parentrolemodel(for the cases * compartmenttype/group) belongs to is the current opened(content of the viewer) * compartmenttype/group/rootmodel. The test of getSource() != null and getTarget() != null is * needed, because it exist cases where this method is called and getSource() or getTarget() * returns null. * */ @Override protected void refreshVisuals() { if ((getSource() != null && getTarget() != null) && (testRootModel() || testGroup() && getSource().getParent().getParent().getParent() instanceof ScalableRootEditPart || getRoot() .getContents() instanceof ORMCompartmentEditPart)) { Connection connection = getConnectionFigure(); connection.setVisible(true); List<RelativePoint> relativePoints = ((Relation) getModel()).getBendpoints(); // the bendpoints are added as RelativeBendpoint, because the position of the bendpoints // must change when the position of the source or target of the relation changes or the the // figure of the content of the viewer has expandable and collapsable elements ArrayList<RelativeBendpoint> figureConstraint = new ArrayList<RelativeBendpoint>(); for (int i = 0; i < relativePoints.size(); i++) { RelativeBendpoint rbp = new RelativeBendpoint(getConnectionFigure()); // p.x = width p.y = height Point pSource = relativePoints.get(i).getDistances().get(0); Point pTarget = relativePoints.get(i).getDistances().get(1); Dimension dim1 = new Dimension(pSource.getX(), pSource.getY()); Dimension dim2 = new Dimension(pTarget.getX(), pTarget.getY()); rbp.setRelativeDimensions(dim1, dim2); figureConstraint.add(rbp); } connection.setRoutingConstraint(figureConstraint); } else { getConnectionFigure().setVisible(false); } }
/** * {@inheritDoc} In case of this {@link ORMCompartmentEditPart} that would * be the figure of a {@link Model}. If the figure of the {@link Model} or * the rolePart is added to this compartment depends on which version of the * compartment figure is used also if the user has steped into thr * compartment or not. ( the adding of segment figures is handelt through * calling * {@link ORMShapeWithSegmentEditPart#addChildVisual(EditPart, index)}. */ @Override protected void addChildVisual(final EditPart childEditPart, final int index) { super.addChildVisual(childEditPart, index); IFigure contentPane = null; if (childEditPart.getModel() instanceof Model && rolePart == null) { // when figure is Version 2 if (getParent() instanceof ScalableRootEditPart) { contentPane = ((ORMCompartmentV2Figure) getFigure()) .getBasicRec(); contentPane.add(((ORMModelEditPart) childEditPart).getFigure(), BorderLayout.CENTER); rmed = (ORMModelEditPart) childEditPart; } // when figure is Version 1 else { contentPane = ((ORMCompartmentV1Figure) getFigure()) .getBasicRec(); Model rm = (Model) ((ORMModelEditPart) childEditPart) .getModel(); rolePart = new PartFigure(); addNamesToRolePart(rm); contentPane.add(rolePart); rmed = (ORMModelEditPart) childEditPart; } } }
/** {@inheritDoc} */ @Override public List<Relation> getModelSourceConnections() { if (!(getParent() instanceof ScalableRootEditPart)) { Shape model = (Shape) getModel(); return model.getOutgoingRelations(); } return new ArrayList<Relation>(); }
/** {@inheritDoc} */ @Override public List<Relation> getModelTargetConnections() { if (!(getParent() instanceof ScalableRootEditPart)) { Shape model = (Shape) getModel(); return model.getIncomingRelations(); } return new ArrayList<Relation>(); }
/** {@inheritDoc} */ @Override public void notifyChanged(final Notification notification) { refreshChildren(); refreshVisuals(); Shape shape = (Shape) getModel(); if (shape.getContainer() != null) { Shape parent = shape.getContainer().getParent(); if (parent != null) { // for synchronsation with role list of the Shape from type compartmenttype in above // layer // of the tree if (getParent().getParent() instanceof ORMCompartmentEditPart) { ((ORMCompartmentEditPart) getParent().getParent()).refreshVisuals(); } // for synchronsation with compartment list of the Group in above layer of the tree if (getParent().getParent() instanceof ORMShapeWithoutSegmentEditPart && parent.getType().equals(Type.GROUP)) { ((ORMShapeWithoutSegmentEditPart) getParent().getParent()).refreshVisuals(); } } } if (!(getParent() instanceof ScalableRootEditPart)) { refreshSourceConnections(); refreshTargetConnections(); } }
/** * Returns the zoom manager of the specified viewer. * * @param viewer * the viewer to get the zoom manager from * @return the zoom manager */ protected ZoomManager getZoomManager(GraphicalViewer viewer) { // get zoom manager from root edit part RootEditPart rootEditPart = viewer.getRootEditPart(); ZoomManager zoomManager = null; if (rootEditPart instanceof ScalableFreeformRootEditPart) { zoomManager = ((ScalableFreeformRootEditPart) rootEditPart).getZoomManager(); } else if (rootEditPart instanceof ScalableRootEditPart) { zoomManager = ((ScalableRootEditPart) rootEditPart).getZoomManager(); } return zoomManager; }
@Override @SuppressWarnings("rawtypes") public Object getAdapter(final Class type) { if (type == ZoomManager.class) return ((ScalableRootEditPart) getGraphicalViewer().getRootEditPart()).getZoomManager(); if (type == IContentOutlinePage.class) { outline = new OutlinePage(model); outline.setEditDomain(getEditDomain()); outline.setSelectionSynchronizer(getSelectionSynchronizer()); return outline; } return super.getAdapter(type); }
private Image createImage() { try { ScalableRootEditPart root = (ScalableRootEditPart) sankeyDiagram.getGraphicalViewer().getRootEditPart(); IFigure figure = root.getLayer(LayerConstants.PRINTABLE_LAYERS); Rectangle bounds = figure.getBounds(); Image img = new Image(null, bounds.width, bounds.height); GC imageGC = new GC(img); Graphics graphics = new SWTGraphics(imageGC); figure.paint(graphics); return img; } catch (Exception e) { log.error("Could not create image", e); return null; } }
@Override protected void configureGraphicalViewer() { ArrayList<String> zoomContributions; // configure viewer super.configureGraphicalViewer(); MenuManager menu = SankeyMenu.create(this); getGraphicalViewer().setContextMenu(menu); GraphicalViewer viewer = getGraphicalViewer(); viewer.setEditPartFactory(new SankeyEditPartFactory()); ScalableRootEditPart rootEditPart = new ScalableRootEditPart(); viewer.setRootEditPart(rootEditPart); ZoomManager zoomManager = rootEditPart.getZoomManager(); // append zoom actions to action registry getActionRegistry().registerAction(new ZoomInAction(zoomManager)); getActionRegistry().registerAction(new ZoomOutAction(zoomManager)); zoomContributions = new ArrayList<>(); zoomContributions.add(ZoomManager.FIT_ALL); zoomContributions.add(ZoomManager.FIT_HEIGHT); zoomContributions.add(ZoomManager.FIT_WIDTH); zoomManager.setZoomLevelContributions(zoomContributions); // create key handler KeyHandler keyHandler = new KeyHandler(); keyHandler.put(KeyStroke.getPressed('+', SWT.KEYPAD_ADD, 0), getActionRegistry().getAction(GEFActionConstants.ZOOM_IN)); keyHandler.put(KeyStroke.getPressed('-', SWT.KEYPAD_SUBTRACT, 0), getActionRegistry().getAction(GEFActionConstants.ZOOM_OUT)); viewer.setKeyHandler(keyHandler); viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.NONE), MouseWheelZoomHandler.SINGLETON); }
@Override protected void configureGraphicalViewer() { super.configureGraphicalViewer(); getGraphicalViewer().setEditPartFactory(new EditPartFactory()); ScalableRootEditPart root = new ScalableRootEditPart(); getGraphicalViewer().setRootEditPart(root); List<String> contributions = new ArrayList<String>(); contributions.add(ZoomManager.FIT_ALL); root.getZoomManager().setZoomLevelContributions(contributions); root.getZoomManager().setZoomLevels(ZOOM_LEVELS); }
protected void configureGraphicalViewer() { super.configureGraphicalViewer(); double[] zoomLevels; List<String> zoomContributions; GraphicalViewer viewer = getGraphicalViewer(); viewer.setEditPartFactory(gw4eEditPartFactory); keyHandler = new KeyHandler(); keyHandler.put(KeyStroke.getPressed(SWT.DEL, 127, 0), getActionRegistry().getAction(ActionFactory.DELETE.getId())); keyHandler.put(KeyStroke.getPressed(SWT.F2, 0), getActionRegistry().getAction(GEFActionConstants.DIRECT_EDIT)); keyHandler.put(KeyStroke.getPressed('+', SWT.KEYPAD_ADD, 0), getActionRegistry().getAction(GEFActionConstants.ZOOM_IN)); keyHandler.put(KeyStroke.getPressed('-', SWT.KEYPAD_SUBTRACT, 0), getActionRegistry().getAction(GEFActionConstants.ZOOM_OUT)); getGraphicalViewer().setKeyHandler(new GraphicalViewerKeyHandler(getGraphicalViewer()).setParent(keyHandler)); ScalableRootEditPart rootEditPart = new ScalableRootEditPart(); viewer.setRootEditPart(rootEditPart); ZoomManager manager = rootEditPart.getZoomManager(); getActionRegistry().registerAction(new ZoomInAction(manager)); getActionRegistry().registerAction(new ZoomOutAction(manager)); zoomLevels = new double[] { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 10.0, 20.0 }; manager.setZoomLevels(zoomLevels); zoomContributions = new ArrayList<String>(); zoomContributions.add(ZoomManager.FIT_ALL); zoomContributions.add(ZoomManager.FIT_HEIGHT); zoomContributions.add(ZoomManager.FIT_WIDTH); manager.setZoomLevelContributions(zoomContributions); getActionRegistry().registerAction(new ToggleGridAction(getGraphicalViewer())); getActionRegistry().registerAction(new ToggleSnapToGeometryAction(getGraphicalViewer())); getActionRegistry().registerAction(new ClearEdgeBendpointLayoutAction(this)); ContextMenuProvider provider = new ContextMenuProvider(this, viewer, getActionRegistry()); viewer.setContextMenu(provider); }
protected void okPressed() { settings.put(LAST_OUTPUT, fileTypeCombo.getSelectionIndex()); BusyIndicator.showWhile(Display.getDefault(), new Runnable() { public void run() { GraphicalViewer viewer = editor.getViewer(); ScalableRootEditPart rootEditPart = (ScalableRootEditPart)viewer.getEditPartRegistry().get(LayerManager.ID); IFigure rootFigure = ((LayerManager)rootEditPart).getLayer(LayerConstants.PRINTABLE_LAYERS); Rectangle rootFigureBounds = rootFigure.getBounds(); Control figureCanvas = viewer.getControl(); GC figureCanvasGC = new GC(figureCanvas); Image img = new Image(null, rootFigureBounds.width, rootFigureBounds.height); GC imageGC = new GC(img); imageGC.setBackground(figureCanvasGC.getBackground()); imageGC.setForeground(figureCanvasGC.getForeground()); imageGC.setFont(figureCanvasGC.getFont()); imageGC.setLineStyle(figureCanvasGC.getLineStyle()); imageGC.setLineWidth(figureCanvasGC.getLineWidth()); // imageGC.setXORMode(figureCanvasGC.getXORMode()); Graphics imgGraphics = new SWTGraphics(imageGC); rootFigure.paint(imgGraphics); ImageData[] imgData = new ImageData[1]; imgData[0] = img.getImageData(); ImageLoader imgLoader = new ImageLoader(); imgLoader.data = imgData; String extension; if (fileTypeCombo.getText().equals("JPEG")) extension = "jpg"; else extension = fileTypeCombo.getText().toLowerCase(); String fileName = null; if (!fileText.getText().trim().endsWith("." + extension)) fileName = fileText.getText().trim() + "." + extension; else fileName = fileText.getText().trim(); int imageType = SWT.IMAGE_BMP; switch (fileTypeCombo.getSelectionIndex()) { case BMP: imageType = SWT.IMAGE_BMP; break; case JPEG: imageType = SWT.IMAGE_JPEG; break; case PNG: imageType = SWT.IMAGE_PNG; break; default: break; } imgLoader.save(fileName, imageType); figureCanvasGC.dispose(); imageGC.dispose(); img.dispose(); } }); super.okPressed(); }
public OverviewOutlinePage(ScalableRootEditPart rootEditPart) { super(); this.rootEditPart = rootEditPart; }
/** * Creates the default root editpart. Called during construction. */ protected void createDefaultRoot() { setRootEditPart(new ScalableRootEditPart()); }
void configureGraphicalViewer() { viewer.setEditPartFactory(new AppEditPartFactory()); ScalableRootEditPart rootEditPart = new ScalableRootEditPart(); viewer.setRootEditPart(rootEditPart); }
private ScalableRootEditPart getRootEditPart() { return (ScalableRootEditPart) viewer.getRootEditPart(); }
private ScalableRootEditPart getRootEditPart() { return (ScalableRootEditPart) editor.getGraphicalViewer().getRootEditPart(); }
private ScalableRootEditPart getRootEditPart() { return (ScalableRootEditPart) getGraphicalViewer().getRootEditPart(); }
public MiniView(Shell shell, SankeyDiagram diagram) { super(shell); viewer = diagram.getGraphicalViewer(); part = (ScalableRootEditPart) viewer.getRootEditPart(); }