I'm having problems copying a graph in jgraphX. The example given by the author doesnt appear to clone recursively the children of the default parent:
graph2.addCells(graph1.cloneCells(graph1.getChildCells(graph1.getDefaultParent())));
There is a method: mxGraphModel.cloneCells(vertexList, true) which claims to clone recursively, but it doesnt seem to work for me. I've tracked down the unexpected behaviour, and it seems to be coming from restoreClone. My cloned cells are not having their edges restored. The following code from mxGraphModel.java illustrates the problem:
protected void restoreClone(Object clone, Object cell, Map mapping) { if (clone instanceof mxICell) { mxICell mxc = (mxICell) clone; Object source = getTerminal(cell, true);
.getTerminal() is expecting an edge, and behaves accordingly, but the way restoreClone uses "cell" means that it is a vertex in this instance. So the terminal is null, and so "source" becomes null. Is this a bug? I'm wondering if the problem is that cloneCell() is recursive, while restoreClone is not recursive, and only restores the first level of cells?
Is there an easier way to just simply copy the whole graph in one go?