@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 void run() { Graph graph = graphModel.getGraph(); boolean runListener = false; graph.writeLock(); try { runListener = initObserver(); } finally { graph.writeUnlock(); graph.readUnlockAll(); } if (!runListener) { runListener = observer.hasGraphChanged(); } if (runListener) { graph.readLock(); try { listener.run(); } finally { graph.readUnlockAll(); } } }
graph.writeLock(); try { GraphView view = graphModel.createView();
if (graphModel != null) { graph = graphModel.getGraphVisible(); graph.writeLock();
graphModel.getGraph().writeLock(); try { graph = graphModel.getGraphVisible();