@Override public Edge createEdge(String id, Node source, Node target, boolean directed, Object typeLabel, Graph graph) { Edge newEdge = buildEdge(graph, id, source, target, directed, typeLabel); try { if (graph.addEdge(newEdge)) {//The edge will be created if it does not already exist. return newEdge; } } catch (Exception e) { Logger.getLogger("").log( Level.SEVERE, "Error when adding edge [id = {0}, source = {1}, target = {2}, directed = {3}, typeLabel = {4}] to the graph. Exception message: {5}", new Object[]{id, source.getId(), target.getId(), directed, typeLabel, e.getMessage()} ); } return null; }
graph.addEdge(edge);
if (n != m && graph.getEdge(n, m) == null) { Edge e = graphModel.factory().newEdge(n, m); graph.addEdge(e);
graph.addEdge(edge);
graph.addEdge(e);
@Override public void clickNodes(Node[] nodes) { //Get mouse position float[] position3d = VizController.getInstance().getGraphIO().getMousePosition3d(); //Get current graph GraphController gc = Lookup.getDefault().lookup(GraphController.class); Graph graph = gc.getGraphModel().getGraph(); GraphFactory factory = gc.getGraphModel().factory(); //Add node Node node = factory.newNode(); node.setX(position3d[0]); node.setY(position3d[1]); node.setSize(10f); graph.addNode(node); //Add edges with the clicked nodes for (Node n : nodes) { Edge edge = factory.newEdge(node, n); graph.addEdge(edge); } } }};
@Override public Graph filter(Subgraph[] graphs) { if (graphs.length > 1) { throw new IllegalArgumentException("Not Filter accepts a single graph in parameter"); } Graph graph = graphs[0]; Graph mainGraph = graph.getView().getGraphModel().getGraph(); for (Edge e : mainGraph.getEdges()) { Node source = e.getSource(); Node target = e.getTarget(); if (graph.contains(source) && graph.contains(target)) { Edge edgeInGraph = graph.getEdge(source, target, e.getType()); if (edgeInGraph == null) { //The edge is not in graph graph.addEdge(e); } else { //The edge is in the graph graph.removeEdge(edgeInGraph); } } } return graph; }
@Override public Graph filter(Subgraph[] graphs) { if (graphs.length > 1) { throw new IllegalArgumentException("Not Filter accepts a single graph in parameter"); } Graph graph = graphs[0]; Graph mainGraph = graph.getView().getGraphModel().getGraph(); for (Node n : mainGraph.getNodes().toArray()) { if (!graph.contains(n)) { //The node n is not in graph graph.addNode(n); } else { //The node n is in graph graph.removeNode(n); } } for (Edge e : mainGraph.getEdges()) { Node source = e.getSource(); Node target = e.getTarget(); if (graph.contains(source) && graph.contains(target)) { Edge edgeInGraph = graph.getEdge(source, target, e.getType()); if (edgeInGraph == null) { graph.addEdge(e); } } } return graph; }