Event for cell add(jgraphx)

1.3k views Asked by At

I need to make a action when the user make a new cell(drag and drop a cell from editorPallete).

    graphComponent.addListener(mxEvent.ADD, new mxEventSource.mxIEventListener() {

  @Override
  public void invoke(Object sender, mxEventObject evt) {
    System.out.println("event add");
  }
} );

I do not receive any event for mxEvent.ADD, same result for mxEvent.ADD_CELLS.

1

There are 1 answers

0
BGuest On

You need to add the listener to the graph, not the graphComponent. You also need to use the CELLS_ADDED event instead of the ADD event. You can take a look at the api documentation for the mxGraph class to view a list of fired events for the class: http://jgraph.github.io/mxgraph/docs/js-api/files/view/mxGraph-js.html --> scroll down to the Events section

So your code should look something like this:

graphComponent.getGraph().addListener(mxEvent.CELLS_ADDED, new xEventSource.mxIEventListener() {

  @Override
  public void invoke(Object sender, mxEventObject evt) {
     System.out.println("event add");
  }
} );

Hope this helps,