I experience some issues with JGraphX and mxGraphModel.
I convert a petri network described by a Hashmap> into a graph model. In order so I built the following loop. However it seems that when iterating over the childs of a node, it can find the existing cells in the model and add a newone with the same label.
The ligne v2=((mxGraphModel)(graph.getModel())).getCell(childVertex);
is not working:
The method return null even if a vertice with the same ID is present. Resulting multiple vertices with the same label and incorrect graph.
int j=0;
for(String vertex: dataPetri.keySet())
{
Object v1 =((mxGraphModel)(graph.getModel())).getCell(vertex);
Object v2;
//Add only if new vertex
if(v1 == null)
v1 = graph.insertVertex(parent, null, vertex, 100, 100*j, 40, 40, "whiteSpace=wrap;textOpacity=100");
else
System.out.println("//Found existing parent ////");
//Looking for links from this vertex
ArrayList<String> childs = dataPetri.get(vertex);
if(childs != null)
{
int i = 0;
for(String childVertex: childs)
{
v2=((mxGraphModel)(graph.getModel())).getCell(childVertex);
if(v2 == null)
v2 = graph.insertVertex(parent, null, childVertex, 100*i, 100, 40, 40, "whiteSpace=wrap;textOpacity=100");
else
System.out.println("/////////Found existing");
graph.insertEdge(parent, null, "", v1, v2);
++i;
}
}
++j;
}