Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Add Connection automatik between two Anchor
Add Connection automatik between two Anchor [message #1403054] Sun, 20 July 2014 21:25 Go to next message
Pierre Kaptue is currently offline Pierre KaptueFriend
Messages: 6
Registered: May 2014
Junior Member
Hello everyone,
i am working on a project where i am confronted with 3 softwares:EMF,X-text und Graphiti. In essence, i would appreciate any help on how to transforn an Xtext-file into graphic using the software graphiti. To facilitate comprehension of the problem hier ist my Xtext-file:

compositeType nameofcompositetype {
role rolename1 with him Ports
role rolename2 with him Ports


association rolename1.Port1 <--> rolename2.port1;
association rolename2.port2 <--> rolename2.port2;
}

I have created a diagram-file in graphiti and have included in it (drag&drop) a compositetype(Object). From this Object, i can open a new diagram-file using a drilldow-feature. Wenn i open the new diagram-file i can inclube automatic the 2 rolenames, ap part of my Code ist:
IFeatureProvider fp = this.getFeatureProvider();
for(Role roleElt:addedCOT.getRoles()){
AddContext RoleAddContext = new AddContext();
RoleAddContext.setNewObject(roleElt);
RoleAddContext.setTargetContainer(containerShape);
RoleAddContext.setLocation(40+schrittx, 40+schritty);
RoleAddContext.setSize(50, 30);
fp.addIfPossible(RoleAddContext);
//schrittx=schrittx+100;
schritty=schritty+40;
}
The problem i have now is how to represent the connections (association in my Xtext-file) also automatic between the role. I have try so but i haven't no connection betwenn role:

AddConnectionContext assocContext = new AddConnectionContext(sourceAnchor, targetAnchor);
assocContext.setTargetContainer(containerShape);
assocContext.setNewObject(assoc);
fp.addIfPossible(assocContext);
}
I don't know if i schould create a pattern for connection?
I hope somebody hat some suggestions.

Best Regards

Pierre
Re: Add Connection automatik between two Anchor [message #1403705 is a reply to message #1403054] Fri, 25 July 2014 13:00 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Pierre,

you don't need to create a pattern for the connection (association), of
course that could be an option as for all objects.

Do you have an AbstractAddFeature subclass registered at your feature
provider for handling the addIfPossible for your assoc instance (check
getAddFeature method of your feature provider)? In case you haven't that is
the reason for not working.

Michael
Re: Add Connection automatik between two Anchor [message #1403764 is a reply to message #1403705] Sat, 26 July 2014 09:48 Go to previous messageGo to next message
Pierre Kaptue is currently offline Pierre KaptueFriend
Messages: 6
Registered: May 2014
Junior Member
Hello Michael,
Tanhk you for your Answer, that was helpful. I was check my getAddFeature method, and my problem was to call the right feature (in my case feature to Addassociation). And now it is working. My getAddFeature now is:
@Override
public IAddFeature getAddFeature(IAddContext context) {
// TODO: check for right domain object instances below
if (context instanceof IAddConnectionContext && context.getNewObject() instanceof Association ) {
return new FcTypesAddAssociationFeature(this);
} else if (context instanceof IAddConnectionContext && context.getNewObject() instanceof EReference) {
return new FcTypesAddEreferenceFeature (this);
}
return super.getAddFeature(context);
}
Now i want to make the same scenario with Ereference, but that is not working. In some condition i should create a connection automatically with Ereference not Association. In case of Ereference hier is my code:
EReference eReference = EcoreFactory.eINSTANCE.createEReference();
eReference.setLowerBound(0);
eReference.setUpperBound(1);

if (sourceAnchor == null || targetAnchor == null)
continue; // this should not happen if all roles are added first
AddConnectionContext assocContext = new AddConnectionContext(sourceAnchor, targetAnchor);
assocContext.setTargetContainer(containerShape);
assocContext.setNewObject(eReference);
fp.addIfPossible(assocContext);
I got this error in my console: Ereference is not contained in a resource. Of Course I tried to add a resource to Ereference like this:
if(eReference.eResource()==null)
getDiagram().eResource().getContents().add(eReference); And i have got a nullpointer hier.
what i have making wrong?

Best Regard

Pierre
Re: Add Connection automatik between two Anchor [message #1404221 is a reply to message #1403764] Wed, 30 July 2014 14:29 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1931
Registered: July 2009
Location: Walldorf, Germany
Senior Member
This looks as if you missed to add the ereference to an EMF resource after
you created it.

Michael
Previous Topic:Confusion about usage of generated model
Next Topic:Rotating AbstractText? Read this!
Goto Forum:
  


Current Time: Fri Apr 26 17:39:54 GMT 2024

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

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

Back to the top