Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » GMF (Graphical Modeling Framework) » Creation of connections programatically
Creation of connections programatically [message #232219] Wed, 03 June 2009 12:57 Go to next message
Javier is currently offline JavierFriend
Messages: 57
Registered: July 2009
Member
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.
Re: Creation of connections programatically [message #232254 is a reply to message #232219] Wed, 03 June 2009 14:32 Go to previous message
Alexander Shatalin is currently offline Alexander ShatalinFriend
Messages: 2928
Registered: July 2009
Senior Member
Hello Javier,

> 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.
Try executing this command using .execute() method.
In general you can move all this loginc into appropriate ???CanonicalEditPolicy.

-----------------
Alex Shatalin
Previous Topic:Background color of nodes lost when converting to GMF 2.2
Next Topic:[Announce] GMF 2.2.0RC3 is available
Goto Forum:
  


Current Time: Sat Aug 10 07:16:18 GMT 2024

Powered by FUDForum. Page generated in 0.03163 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top