0

I'm trying to figure out how to implement the above functionality? i.e. If I have a vertex already in my graph, and I drag another vertex from my palette (I've derived my app from the Java BasicGraphEditor example), I'd like to automatically create an edge from the drop target to the dropped cell.

The current implementation creates a group, which I do NOT want.

Any suggestions?

Thanks!

Rogan Dawes
  • 350
  • 2
  • 9

1 Answers1

0

Ok, it seems that this is a solution to the above question.

Extend mxGraphComponent, and implement the following method:

        public Object[] importCells(Object[] cells, double dx, double dy, Object target, Point location) {
        if (target == null && cells.length == 1 && location != null) {
            target = getCellAt(location.x, location.y);

            if (target instanceof mxICell && cells[0] instanceof mxICell) {
                mxICell targetCell = (mxICell) target;
                mxICell dropCell = (mxICell) cells[0];

                if (targetCell.isVertex() == dropCell.isVertex()) {
                    // make target null, otherwise we create a group
                    cells = super.importCells(cells, dx, dy, null, location);

                    Object parent = graph.getModel().getParent(target);
                    // we cloned it, so update the reference
                    dropCell = (mxICell) cells[0];
                    graph.insertEdge(parent, null, "", target, dropCell);

                    graph.setSelectionCell(dropCell);

                    return null;
                }
            }
        }

        return super.importCells(cells, dx, dy, target, location);
    }
Rogan Dawes
  • 350
  • 2
  • 9