1
1

I'm using Java and I want to call a method, whenever a new edge is created. That is, whenever my user creates an edge between the two nodes (with mouse), I want to show him a dialog for filling the information of that edge. How should I add a listener for edge creation to do that?

asked 23 Mar '11, 14:45

plusplus's gravatar image

plusplus
1313
accept rate: 0%

edited 23 Mar '11, 14:45

David's gravatar image

David
4.9k21831


Listen to mxEvent.CONNECT in mxConnectionHandler, eg.

\n
graphComponent.getConnectionHandler().addListener(mxEvent.CONNECT, new mxIEventListener()\n{\n  public void invoke(Object sender, mxEventObject evt)\n  {\n    System.out.println("edge="+evt.getProperty("cell"));\n  }\n});\n
link

answered 23 Mar '11, 23:06

Gaudenz's gravatar image

Gaudenz
80.1k1310
accept rate: 39%

Thanks very much. Just what I was looking for. \nWhere can I find the documentation for the rest of the event that are available?

(24 Mar '11, 20:53) plusplus

To not insert an edge you may want to override mxConnectionHandler.mouseReleased.

link

answered 05 Apr '11, 22:22

Gaudenz's gravatar image

Gaudenz
80.1k1310
accept rate: 39%

I've still got a question:

\n

I tried several event listener variations but didn't find a proper solution. Among other things, I also tried following listener:

\n
this.getGraphPanel().getGraph().addListener(mxEvent.ADD_CELLS, new     mxEventSource.mxIEventListener()\n            {\n        ....\n
\n

If the user creates a connection between two nodes then I'd like to react "before" this edge cell becomes inserted. And in this situation I'd like to be able to cancel this edge creation. All the event listeners who I have found were invoked "after" the creation.

\n

Is there already a possiblity to fulfill my requirements?

\n

Best regards

\n

PAX

link

answered 04 Apr '11, 10:15

Andreas%20PAX%20L%C3%BCck's gravatar image

Andreas PAX Lück
31
accept rate: 0%

I handled it by removing the edge myself. I know, it seems a little silly :p But after the insertion, I checked my conditions and if the edge was invalid, I would remove it by its

\n

Best,\nReza

link

answered 05 Apr '11, 21:12

plusplus's gravatar image

plusplus
1313
accept rate: 0%

Thanks for your approaches. They all seem to work.

\n

For the second solution you have to extend following classes:

\n
mxGraphComponent\nmxConnectionHandler\n
\n

In the first class you have to override following method in this way:

\n
@Override\nprotected mxConnectionHandler createConnectionHandler()\n{\n    return new ConnectionHandler(this);\n}\n
\n

And within the second class the meantioned mouse method:

\n
@Override\npublic void mouseReleased(final MouseEvent e)\n{\n    // add your code for the check here\n     super.mouseReleased(e);\n}\n
\n

In the very last step you have to use these modified classes instead of the original ones to create your graph editor UI:

\n
    ...\n    this.setGraphMgr(new mxGraph());\n    this.getGraphMgr().setModel(this.getGraphModel());\n    this.graphPanel = new GraphComponent(this.getGraphMgr());\n    ...\n
\n

Thanks for your quickly help!

\n

Best regards

\n

PAX

link

answered 06 Apr '11, 09:28

Andreas%20PAX%20L%C3%BCck's gravatar image

Andreas PAX Lück
31
accept rate: 0%

I have the same problem as in the first question, but I do not create the edges by dragging the mouse but programmatically by clicking a button and executing its action. Is there a way to react on creating edges programmatically? What event is fired and where do I have to listen to that event?

link

answered 04 Jan '13, 08:14

fachexot's gravatar image

fachexot
461210
accept rate: 11%

1

The events fired by mxGraph are listed in the API specification. Custom events can be fired using fireEvent.

(04 Jan '13, 08:19) Gaudenz

Thanks, now I found it in the Java API.

(04 Jan '13, 08:32) fachexot
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Tags:

×194
×100
×29
×22
×11

Asked: 23 Mar '11, 14:45

Seen: 5,434 times

Last updated: 04 Jan '13, 08:32