protected void filterVisuals() { if (getGraphControl() == null) { return; } Object[] filtered = getFilteredChildren(getInput()); SimpleGraphComparator comparator = new SimpleGraphComparator(); TreeSet filteredElements = new TreeSet(comparator); TreeSet unfilteredElements = new TreeSet(comparator); List connections = getGraphControl().getConnections(); List nodes = getGraphControl().getNodes(); if (filtered.length == 0) { // set everything to invisible. // @tag zest.bug.156528-Filters.check : should we only filter out // the nodes? for (Iterator i = connections.iterator(); i.hasNext(); ) { GraphConnection c = (GraphConnection) i.next(); c.setVisible(false); } for (Iterator i = nodes.iterator(); i.hasNext(); ) { GraphNode n = (GraphNode) i.next(); n.setVisible(false); } return; } for (Iterator i = connections.iterator(); i.hasNext(); ) { GraphConnection c = (GraphConnection) i.next(); if (c.getExternalConnection() != null) { unfilteredElements.add(c); } } for (Iterator i = nodes.iterator(); i.hasNext(); ) { GraphNode n = (GraphNode) i.next(); if (n.getData() != null) { unfilteredElements.add(n); } } for (int i = 0; i < filtered.length; i++) { Object modelElement = connectionsMap.get(filtered[i]); if (modelElement == null) { modelElement = nodesMap.get(filtered[i]); } if (modelElement != null) { filteredElements.add(modelElement); } } unfilteredElements.removeAll(filteredElements); // set all the elements that did not pass the filters to invisible, and // all the elements that passed to visible. while (unfilteredElements.size() > 0) { GraphItem i = (GraphItem) unfilteredElements.first(); i.setVisible(false); unfilteredElements.remove(i); } while (filteredElements.size() > 0) { GraphItem i = (GraphItem) filteredElements.first(); i.setVisible(true); filteredElements.remove(i); } }
void removeGraphModelConnection(Object obj) { GraphConnection connection = (GraphConnection) connectionsMap.get(obj); if (connection != null) { connectionsMap.remove(obj); if (!connection.isDisposed()) { connection.dispose(); } } }
GraphConnection addGraphModelConnection(Object element, GraphNode source, GraphNode target) { GraphConnection connection = this.getGraphModelConnection(element); if (connection == null) { connection = new GraphConnection((Graph) getControl(), SWT.NONE, source, target); this.connectionsMap.put(element, connection); connection.setData(element); } return connection; }
/** * Removes the given connection object from the layout algorithm and the model. * * @param connection */ public void removeRelationship(Object connection) { GraphConnection relationship = (GraphConnection) connectionsMap.get(connection); if (relationship != null) { // remove the relationship from the layout algorithm if (getLayoutAlgorithm() != null) { getLayoutAlgorithm().removeRelationship(relationship.getLayoutRelationship()); } // remove the relationship from the model relationship.dispose(); } }
public void unReveal(Object element) { Widget[] items = this.findItems(element); for (int i = 0; i < items.length; i++) { Widget item = items[i]; if (item instanceof GraphNode) { GraphNode graphModelNode = (GraphNode) item; graphModelNode.unhighlight(); } else if (item instanceof GraphConnection) { GraphConnection graphModelConnection = (GraphConnection) item; graphModelConnection.unhighlight(); } } }
/* * (non-Javadoc) * * @see org.eclipse.jface.viewers.Viewer#inputChanged(java.lang.Object, * java.lang.Object) */ protected void inputChanged(Object input, Object oldInput) { IStylingGraphModelFactory factory = getFactory(); factory.setConnectionStyle(getConnectionStyle()); factory.setNodeStyle(getNodeStyle()); // Save the old map so we can set the size and position of any nodes // that are the same Map oldNodesMap = nodesMap; Graph graph = (Graph) getControl(); graph.setSelection(new GraphNode[0]); Iterator iterator = nodesMap.values().iterator(); while (iterator.hasNext()) { GraphNode node = (GraphNode) iterator.next(); if (!node.isDisposed()) { node.dispose(); } } iterator = connectionsMap.values().iterator(); while (iterator.hasNext()) { GraphConnection connection = (GraphConnection) iterator.next(); if (!connection.isDisposed()) { connection.dispose(); } } nodesMap = new HashMap(); connectionsMap = new HashMap(); graph = factory.createGraphModel(graph); ((Graph) getControl()).setNodeStyle(getNodeStyle()); ((Graph) getControl()).setConnectionStyle(getConnectionStyle()); // check if any of the pre-existing nodes are still present // in this case we want them to keep the same location & size for (Iterator iter = oldNodesMap.keySet().iterator(); iter.hasNext(); ) { Object data = iter.next(); GraphNode newNode = (GraphNode) nodesMap.get(data); if (newNode != null) { GraphNode oldNode = (GraphNode) oldNodesMap.get(data); newNode.setLocation(oldNode.getLocation().x, oldNode.getLocation().y); if (oldNode.isSizeFixed()) { newNode.setSize(oldNode.getSize().width, oldNode.getSize().height); } } } applyLayout(); }
@Override public void selfStyleConnection(Object element, GraphConnection connection) { // Connections are not rendered in some cases when curved // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=373199 // Seems to be fixed connection.setLineWidth(0); connection.setTooltip(getTooltip(element)); connection.setLineColor(ColorConstants.black); PolylineConnection conn = (PolylineConnection) connection.getConnectionFigure(); if (element instanceof ISpecialisationRelationship) { conn.setTargetDecoration(SpecialisationConnectionFigure.createFigureTargetDecoration()); } else if (element instanceof ICompositionRelationship) { conn.setSourceDecoration(CompositionConnectionFigure.createFigureSourceDecoration()); } else if (element instanceof IAggregationRelationship) { conn.setSourceDecoration(AggregationConnectionFigure.createFigureSourceDecoration()); } else if (element instanceof IAssignmentRelationship) { conn.setSourceDecoration(AssignmentConnectionFigure.createFigureSourceDecoration()); conn.setTargetDecoration(AssignmentConnectionFigure.createFigureTargetDecoration()); } else if (element instanceof IRealisationRelationship) { conn.setTargetDecoration(RealisationConnectionFigure.createFigureTargetDecoration()); connection.setLineStyle(SWT.LINE_CUSTOM); conn.setLineDash(new float[] {4}); } else if (element instanceof ITriggeringRelationship) { conn.setTargetDecoration(TriggeringConnectionFigure.createFigureTargetDecoration()); } else if (element instanceof IFlowRelationship) { conn.setTargetDecoration(FlowConnectionFigure.createFigureTargetDecoration()); connection.setLineStyle(SWT.LINE_CUSTOM); conn.setLineDash(new float[] {6, 3}); } else if (element instanceof IUsedByRelationship) { conn.setTargetDecoration(UsedByConnectionFigure.createFigureTargetDecoration()); } else if (element instanceof IAccessRelationship) { conn.setTargetDecoration(AccessConnectionFigure.createFigureSourceDecoration()); conn.setTargetDecoration(AccessConnectionFigure.createFigureTargetDecoration()); connection.setLineStyle(SWT.LINE_CUSTOM); conn.setLineDash(new float[] {1.5f, 3}); } else if (element instanceof IInfluenceRelationship) { conn.setTargetDecoration(InfluenceConnectionFigure.createFigureTargetDecoration()); connection.setLineStyle(SWT.LINE_CUSTOM); conn.setLineDash(new float[] {6, 3}); } conn.setAntialias(SWT.ON); }
/* * (non-Javadoc) * * @see org.eclipse.jface.viewers.StructuredViewer#getRawChildren(java.lang.Object) */ protected Object[] getRawChildren(Object parent) { if (parent == getInput()) { // get the children from the model. LinkedList children = new LinkedList(); if (getGraphControl() != null) { List connections = getGraphControl().getConnections(); List nodes = getGraphControl().getNodes(); for (Iterator i = connections.iterator(); i.hasNext(); ) { GraphConnection c = (GraphConnection) i.next(); if (c.getExternalConnection() != null) { children.add(c.getExternalConnection()); } } for (Iterator i = nodes.iterator(); i.hasNext(); ) { GraphNode n = (GraphNode) i.next(); if (n.getData() != null) { children.add(n.getData()); } } return children.toArray(); } } return super.getRawChildren(parent); }
@Override protected Control createDialogArea(Composite parent) { // toolkit = new FormToolkit(parent.getDisplay()); // form = toolkit.createScrolledForm(parent); // form.setText("Dependency Graph UI Legend"); // form.getToolBarManager().add(new Action("Close Dialog", MavenEditorImages.CLEAR) { // public void run() { // close(); // } // }); // form.getToolBarManager().update(true); // form.getBody().setLayout(new TableWrapLayout()); // toolkit.decorateFormHeading(form.getForm()); Graph g = new Graph(parent, SWT.NONE) { public org.eclipse.swt.graphics.Point computeSize(int wHint, int hHint, boolean changed) { return new org.eclipse.swt.graphics.Point(260, 300); } }; g.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED); g.setEnabled(false); { GraphNode n1 = new GraphNode(g, SWT.NONE, " compile scope dependency "); n1.setLocation(10, 10); n1.setSize(240, 25); } { GraphNode n1 = new GraphNode(g, SWT.NONE, " non-compile scope dependency "); n1.setLocation(10, 40); n1.setSize(240, 25); n1.setBackgroundColor(colorTestBackground); } { GraphNode n1 = new GraphNode(g, SWT.NONE, " selected dependency "); n1.setLocation(10, 70); n1.setSize(240, 25); n1.setBackgroundColor(colorSelectedBackground); } { GraphNode n1 = new GraphNode(g, SWT.NONE, " selected non-compile "); n1.setLocation(10, 100); n1.setSize(240, 25); n1.setBackgroundColor(colorSelectedTestBackground); } { GraphNode n1 = new GraphNode(g, SWT.NONE, " "); GraphNode n2 = new GraphNode(g, SWT.NONE, " "); DependencyConnection c1 = new DependencyConnection(g, SWT.NONE, n1, n2); c1.setText("compile scope"); c1.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED | ZestStyles.CONNECTIONS_SOLID); n1.setLocation(10, 140); n2.setLocation(220, 140); } { GraphNode n1 = new GraphNode(g, SWT.NONE, " "); GraphNode n2 = new GraphNode(g, SWT.NONE, " "); n2.setBackgroundColor(colorTestBackground); GraphConnection c1 = new DependencyConnection(g, SWT.NONE, n1, n2); c1.setText("non-compile scope"); c1.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED | ZestStyles.CONNECTIONS_DOT); c1.setLineColor(colorTestRel); n1.setLocation(10, 170); n2.setLocation(220, 170); } { GraphNode n1 = new GraphNode(g, SWT.NONE, " "); GraphNode n2 = new GraphNode(g, SWT.NONE, " "); GraphConnection c1 = new DependencyConnection(g, SWT.NONE, n1, n2); c1.setText("resolved conflict"); c1.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED | ZestStyles.CONNECTIONS_SOLID); c1.setLineColor(colorRelResolved); n1.setLocation(10, 200); n2.setLocation(220, 200); } { GraphNode n1 = new GraphNode(g, SWT.NONE, " "); GraphNode n2 = new GraphNode(g, SWT.NONE, " "); n2.setBackgroundColor(colorSelectedBackground); GraphConnection c1 = new DependencyConnection(g, SWT.NONE, n1, n2); c1.setText("referenced from selected"); c1.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED | ZestStyles.CONNECTIONS_SOLID); c1.setLineColor(highlighted); c1.setLineWidth(3); n1.setLocation(10, 230); n2.setLocation(220, 230); } { GraphNode n1 = new GraphNode(g, SWT.NONE, " "); GraphNode n2 = new GraphNode(g, SWT.NONE, " "); n2.setBackgroundColor(colorSelectedTestBackground); GraphConnection c1 = new DependencyConnection(g, SWT.NONE, n1, n2); c1.setText("referenced from non-compile"); c1.setConnectionStyle(ZestStyles.CONNECTIONS_DIRECTED | ZestStyles.CONNECTIONS_DOT); c1.setLineColor(highlighted); c1.setLineWidth(3); n1.setLocation(10, 260); n2.setLocation(220, 260); } g.addFocusListener( new FocusAdapter() { public void focusLost(FocusEvent e) { close(); } }); return parent; }
public void setText(String string) { super.setText(string); updateConnection(); }