[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.modeling.gmf] Creation of connections programatically

Hello guys,

in my application, I want upon creation of certain nodes automatically create a connection pointing from an existing node to the new one.
These new nodes are added in the Canvas, so in the XXXEditPart (the one for the canvas) I'm controlling the event of adding that node (in method handleNotificationEvent(Notification notification)).


I implemented a class extending DeferredCreateConnectionViewCommand. When a new node is added, I create an instance of that command and execute it: the result works fine and the connection is right there. But this way of creating the connection has some problems:

- When I click on Undo the creation of the new node, the connection is also gone. But when I click redo, I get two connections pointing to the node: the one that existed, and a new one because an event of the type ADD to the canvas has been triggered again, so it is creation a command too. I get as many connections as the times I click undo/redo.

- If a delete the node, and then I click on Undo, I run into the same problem.

I tried several ways to solve this:
1 - In my command, handling doUndo() / doRedo() methods, but they aren't being called.
2 - In handleNotificationEvent(), upon the ADD event of the new edge, check its target and see if an Edge is already existing: right there I can't delete this new edge.


As alternative, I tried to create the Edge in the ViewFactory of the node:

Edge edge = getViewService().createEdge(EBKElementTypes.Link_4001,
node.getDiagram(), ((IHintedType)EBKElementTypes.Link_4001).getSemanticHint(),
-1, false, getPreferencesHint());
edge.setVisible(false);
View aux = (View)node.getDiagram().getChildren().get(0);
edge.setSource((View)node.getDiagram().getChildren().get(0));
edge.setTarget((View)node); //new node
edge.persist();
edge.setVisible(true);


The connection is created but shows up on the upper-left corner: after saving, closing and reopening the diagram, then it is correctly placed.

Anyone could give me a hint for solving this, or another method for creating the connection and not having problems with undo/redo mechanism?

Thank you guys,

javier.