Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Change the default anchor on a connection
Change the default anchor on a connection [message #1229887] Fri, 10 January 2014 13:01 Go to next message
Fayçal Benaziz is currently offline Fayçal BenazizFriend
Messages: 7
Registered: December 2013
Junior Member
Hello,

For one of my project, I would to create a UML sequence diagram. But I have some difficulties to create a feature which permits to create a message between lifelines. Indeed when a connection starts, by default it's take the chopbox of a containershape (in the middle). So I tried to override the method attachedToSource(ICreateConnectionContext context), and create a dynamic anchor in my lifeline (in the source point). My anchor is well created but when I change the source anchor in the context, after the execution of this method, the source anchor is automatically changed into the previously anchor.

Do you know if there is a way to change the default anchor when a connection starts ?

regards,
F. Benaziz
Re: Change the default anchor on a connection [message #1231002 is a reply to message #1229887] Mon, 13 January 2014 15:25 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hi,

changing the anchor in attachedToSource may be too early. Until the
connection finally is created new context instances will be created and
since the anchor to use is stored there, the default chopbox anchor will be
used.

Have you tried to set the desired anchor in the create method?

Michael
Re: Change the default anchor on a connection [message #1262089 is a reply to message #1231002] Mon, 03 March 2014 08:50 Go to previous messageGo to next message
Fayçal Benaziz is currently offline Fayçal BenazizFriend
Messages: 7
Registered: December 2013
Junior Member
Hi,
Sorry, I didn't see that you had answered.
In the create method, I've tried and it works but aesthetically it's bad. Because at the beginning, the connection is still at the the center of the shape (and not from my anchor).
I'll try to find an issue, but thank you for your help.

Best regards,
F. Benaziz

[Updated on: Mon, 03 March 2014 14:05]

Report message to a moderator

Re: Change the default anchor on a connection [message #1262380 is a reply to message #1262089] Mon, 03 March 2014 15:23 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Probably you will need to combine both changes: set the source anchor in
attachedToSource to get the visualization right, and then changing the
source anchor again in the create method to get the connection created
correctly.

This happens because you cannot rely on getting the same context instance
passed to all the feature methods, it may be a new instance containing the
same (initial) information.

Michael
Re: Change the default anchor on a connection [message #1262455 is a reply to message #1262380] Mon, 03 March 2014 16:56 Go to previous messageGo to next message
Fayçal Benaziz is currently offline Fayçal BenazizFriend
Messages: 7
Registered: December 2013
Junior Member
I had the same idea as you but the attachedToSource doesn't seem to change the visualization.
I think this method doesn't work (or maybe i don't use it in the right way).
Re: Change the default anchor on a connection [message #1263571 is a reply to message #1262455] Tue, 04 March 2014 15:51 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Not sure, can you post your coding here?

Michael
Re: Change the default anchor on a connection [message #1264464 is a reply to message #1263571] Wed, 05 March 2014 08:41 Go to previous messageGo to next message
Fayçal Benaziz is currently offline Fayçal BenazizFriend
Messages: 7
Registered: December 2013
Junior Member
Here is my code below :

public void attachedToSource(ICreateConnectionContext contex) {

      PictogramElement pe = context.getSourcePictogramElement();

      ILocation loc = context.getSourceLocation();

      // I retrieve the diagram's editing domain
      TransactionalEditingDomain editingDomain = getDiagramBehavior().getEditingDomain();

      // I create my command which will create the anchor dynamically in the source pictogram element
      AddCommandAnchorMessage cmd = new AddCommandAnchorMessage(editingDomain, pe, loc);

      // I execute this command
      editingDomain.getCommandStack().execute(cmd);

      // I change the source anchor in the context
      ((CreateConnectionContext)context).setSourceAnchor(cmd.getAnchorCreated);
}


I can attest that the anchor is well-created but not used in the visualization.

[Updated on: Wed, 05 March 2014 08:42]

Report message to a moderator

Re: Change the default anchor on a connection [message #1264504 is a reply to message #1264464] Wed, 05 March 2014 09:19 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Hi,

this is tricky and I'm not sure how to solve...

The original intention behind the attached to source method was to allow
some non-metamodell-changing feedback at starting a connection, see the
initiating bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=329517 . With
some manual effort it is also possible to change the Graphiti metamodel and
visualize it (you have to care about undo these changes manually), but what
you intent to do goes even beyond.

At the attachedToSource point in time we have a mixture of information
rendered on the diagram: the actual Graphiti diagram plus the started
connection directly managed by the underlying GEF. Not sure if that latter
part is possible to update... Besides, the change of the context information
itself will not trigger any diagram update, that would need to triggered by
calling refresh on the diagram editor.

To see a working example of an attachedToSource implementation, you might
have a look into the Chess example, class CreateChessMoveFeature. But this
example works with decorators not the connection visualization itself.

Michael
Previous Topic:Disable Unto/Redo in graphical editor context menu
Next Topic:graphiti Plug-in Diagram editor
Goto Forum:
  


Current Time: Tue Apr 23 08:45:59 GMT 2024

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

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

Back to the top