I want to create a plugin which is able to modify the graph while it is executed.

I started using the statistics plugin template. Here is what it looks like :

Code: Select all

```
public void execute(GraphModel graphModel, AttributeModel attributeModel) {
Graph graph = graphModel.getGraphVisible();
graph.readLock();
try {
Progress.start(progressTicket, graph.getNodeCount());
// For edges that will be removed
Vector<Edge> edges=new Vector<Edge>();
int i=0;
for (Node m : graph.getNodes()) {
int m_inf_n=1;
for (Node n : graph.getNodes()) {
if(m_inf_n==1){// in order to test only one time each couple of nodes
if(!m.equals(n))
m_inf_n=0;
continue;
}
if(TEST){
Edge e=graphModel.factory().new Edge(m, n);
edges.add(e);
}
}
Progress.progress(progressTicket);
if (cancel) {
break;
}
}
graph.readUnlockAll();
graph.writeLock();
//Writing the new edges
for( Edge e : edges){
graph.addEdge(e);
}
graph.readUnlockAll();
} catch (Exception e) {
// print stack trace as report
StringWriter sw=new StringWriter();
PrintWriter pw=new PrintWriter(sw, true);
e.printStackTrace(pw);
pw.flush();
sw.flush();
res+= sw.toString();
} finally {
//Unlock graph
graph.readUnlockAll();
}
}
```

Am I editing the graph in a good manner ? Should I use an EdgeDraft instead ? Do I need to refresh some display ?

David