2

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?

fig
  • 732
  • 1
  • 8
  • 14
  • 1
    Okay, in the end I had to do this by serialising the whole graph to an XML string, and then de-serialising it. The cloning just isnt reliable enough for use on deep graphs. – fig Jun 19 '13 at 14:43
  • Here are some related posts in the JGraphX forums - it seems to be acknowledged as a bug: http://forum.jgraph.com/questions/3521/1-5-1-10-bug-report?page=1#6571 http://forum.jgraph.com/questions/1590/paste-problem – fig Jul 09 '13 at 14:00

0 Answers0