/* * (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(); }
/** * Adds a new relationship given the connection. It will use the content provider to determine the * source and destination nodes. * * @param connection The connection data object. */ public void addRelationship(Object connection) { IStylingGraphModelFactory modelFactory = getFactory(); if (connectionsMap.get(connection) == null) { if (modelFactory.getContentProvider() instanceof IGraphContentProvider) { IGraphContentProvider content = ((IGraphContentProvider) modelFactory.getContentProvider()); Object source = content.getSource(connection); Object dest = content.getDestination(connection); // create the new relationship modelFactory.createConnection(getGraphControl(), connection, source, dest); } else { throw new UnsupportedOperationException(); } } }
/** * Creates a new relationship between the source node and the destination node. If either node * doesn't exist then it will be created. * * @param connection The connection data object. * @param srcNode The source node data object. * @param destNode The destination node data object. */ public void addRelationship(Object connection, Object srcNode, Object destNode) { // create the new relationship IStylingGraphModelFactory modelFactory = getFactory(); modelFactory.createConnection(getGraphControl(), connection, srcNode, destNode); }