Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Getting anchors from Pictogram Element
Getting anchors from Pictogram Element [message #1289530] Wed, 09 April 2014 11:57 Go to next message
Filipe Ramos is currently offline Filipe RamosFriend
Messages: 18
Registered: December 2013
Junior Member
Hello,

I'm having some trouble trying to create a new connections programmatically.

I have two graphical objects and a connection between them. I then want to programmatically delete one of them (and the connection), create another one on it's place, and create the connection again.

I delete the graphical object with a delete feature, create another one with the add feature, but in order to create the connection, I need the anchors of the newly created object, and I can't see how to get them from the Pictogram Element returned from the add feature...

Am I doing this the right way? If so, how can I get the anchor?

Thanks.
Re: Getting anchors from Pictogram Element [message #1290628 is a reply to message #1289530] Thu, 10 April 2014 09:31 Go to previous messageGo to next message
Soeren M is currently offline Soeren MFriend
Messages: 77
Registered: September 2011
Member
Maybe I am missing sth, but if you add sth you should get the object?
This is not tested, but I would try sth like:

X eobject = XFactory.eINSTANCE.createX();
eobject.setID(...);
eobject.setDelayText(...);
eobject.setDescriptionText(...);
((ContainerShape) targetContainer).eResource().getContents().add(eobject);

AddContext addContext = new AddContext();
addContext.setNewObject(eobject);
addContext.setLocation(...);
addContext.setTargetContainer(...);

IAddFeature addFeature = fp.getAddFeature(addContext);
IAddFeature addFeature = fp.getAddFeature(addContext);
if (addFeature.canAdd(addContext)) {
    Pe pe = addFeature.add(addContext); //here you should get ur pe
}

Re: Getting anchors from Pictogram Element [message #1290911 is a reply to message #1290628] Thu, 10 April 2014 14:51 Go to previous messageGo to next message
Filipe Ramos is currently offline Filipe RamosFriend
Messages: 18
Registered: December 2013
Junior Member
Yes, I have the PE, and it contains 3 anchors, but how can I get them? It must be obvious, but I can´t figure it out... That´s what I do:

AddContext addContext = new AddContext();
addContext.setNewObject(...);
addContext.setTargetContainer(getDiagram());
addContext.setX(...);
addContext.setY(...);

IAddFeature addFeature = getFeatureProvider().getAddFeature(addContext);
if (addFeature.canAdd(addContext))
	PictogramElement addedElement = addFeature.add(addContext);

Anchor anchor1 = ...
Anchor anchor2 = ### PROBLEM ###

AddConnectionContext connectionContext = new AddConnectionContext(anchor1, anchor2);
connectionContext.setNewObject(...);
IAddFeature connectionAddFeature = getFeatureProvider().getAddFeature(connectionContext);
if (connectionAddFeature.canAdd(connectionContext))
	connectionAddFeature.add(connectionContext);


The problem is that anchor2 is a anchor from addedElement, but I don't know how to get it...

[Updated on: Thu, 10 April 2014 14:52]

Report message to a moderator

Re: Getting anchors from Pictogram Element [message #1291954 is a reply to message #1290911] Fri, 11 April 2014 11:24 Go to previous messageGo to next message
Soeren M is currently offline Soeren MFriend
Messages: 77
Registered: September 2011
Member
You can cast your Pe into a Shape or ContainerShape, but you should check before what it is.

If its a Shape, you can do sth like this:
Shape shape = (Shape) addFeature.add(addContext);
EList anchors = shape.getAnchors();
Re: Getting anchors from Pictogram Element [message #1296042 is a reply to message #1291954] Mon, 14 April 2014 19:38 Go to previous message
Filipe Ramos is currently offline Filipe RamosFriend
Messages: 18
Registered: December 2013
Junior Member
That worked Smile

Thanks!
Previous Topic:Newlines in source code
Next Topic:No undo for update feature
Goto Forum:
  


Current Time: Thu Apr 25 04:46:32 GMT 2024

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

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

Back to the top