Agosto Frio
Agosto Frio

Reputation: 21

Event listener for edge changing source/target (Jgraphx)

how do I get the event of changing the source or target of an edge? I can get when the edge first connect two nodes, but I can't find to the cases when the user changes the source or target of an already-created edge.

Upvotes: 1

Views: 1933

Answers (1)

Emmeran Seehuber
Emmeran Seehuber

Reputation: 111

I just found how to do this:

        graph.addListener(mxEvent.CELL_CONNECTED, new mxIEventListener() {
            @Override
            public void invoke(Object sender, mxEventObject evt) {
                mxCell connectionCell = (mxCell) evt.getProperty("edge");
                boolean source = (Boolean) evt.getProperty("source");
                                    /* source == true when source changed, source == false, when target changed). */
            }
        });

You will get a seperate event for the changes of source and target. I.E. on first connect you get two events; One with source == true, but the target of the edge is not yet set. And then with source == false. But you get the later only if there is a target.... (So if you want to remove dangling edges on first connect, you still have to use the mxEvent.CONNECT event on the ConnectonHandler of the mxGraphComponent)

Upvotes: 1

Related Questions