private void removeEdge(Edge edge, Graph graph) { graph.removeEdge(edge); } }
@Override public void actionPerformed(ActionEvent e) { //Get the current graph model GraphController gc = Lookup.getDefault().lookup(GraphController.class); GraphModel graphModel = gc.getGraphModel(); if (graphModel != null) { //Remove self loops int removed = 0; Graph graph = graphModel.getGraph(); graph.writeLock(); for (Edge edge : graph.getEdges().toArray()) { if (edge.isSelfLoop()) { graph.removeEdge(edge); removed++; } } graph.writeUnlock(); //Notification message NotifyDescriptor d = new NotifyDescriptor.Message(removed + " self-loop have been removed", NotifyDescriptor.INFORMATION_MESSAGE); DialogDisplayer.getDefault().notify(d); } else { //Error message NotifyDescriptor d = new NotifyDescriptor.Message("No active workspace", NotifyDescriptor.ERROR_MESSAGE); DialogDisplayer.getDefault().notify(d); } } }
@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; }
graph.removeEdge(e); } else { graph.removeEdge(f);