Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Question about Connections with EReference
Question about Connections with EReference [message #565791] Sat, 28 August 2010 08:30 Go to next message
Tijs Rademakers is currently offline Tijs Rademakers
Messages: 9
Registered: August 2010
Junior Member
Hi,

I'm working on a simple version of a BPMN 2.0 editor based on the EMF model of the BPMN2 subproject of MDT. In this EMF model you have for example a StartEvent and EndEvent that are eventually EObjects. I'm able to use the Graphiti tutorial example code together with these Start and End Event objects and that looks great.

But now I run into an issue with connecting a StartEvent with an EndEvent. According to the BPMN2 EMF model I should use a SequenceFlow, with is eventually also a EObject. Now I'm trying to create a Connection between a Start and End Event with a SequenceFlow. Everything goes well until the link method of the AbstractFeature class is invoked from the public PictogramElement add(IAddContext context) method in the TutorialCreateEReferenceFeature equivalent class. There I get a NullPointer on the following line (600) of the AbstractFeatureProvider class:

ResourceSet resourceSet = bo.eResource().getResourceSet();

In the tutorial a EReference instance is used to implement the Connection, and that's working okay ofcourse.
But can I also use a EMF object that extends EObject to implement such a Connection? Am I doing something wrong here?

Best regards,

Tijs
Re: Question about Connections with EReference [message #565812 is a reply to message #565791] Sun, 29 August 2010 15:19 Go to previous messageGo to next message
Tijs Rademakers is currently offline Tijs Rademakers
Messages: 9
Registered: August 2010
Junior Member
Hi,

I've worked a bit further with this and I just removed the link method call from my public PictogramElement add(IAddContext context) method and it works great.
I've looked at the code behind this link method, but I can't really figure out what I'm missing by not invoking it ;). Maybe somebody can help me with understanding this?

Thanks,

Tijs
Re: Question about Connections with EReference [message #565822 is a reply to message #565812] Mon, 30 August 2010 04:24 Go to previous messageGo to next message
Tim Kaiser is currently offline Tim Kaiser
Messages: 118
Registered: July 2009
Senior Member
Hi Tijs,

the problem with the null pointer is that the
EObject you want to link to the connection
is not contained in an EResource or the resource
of the EObject is not part of a ResourceSet.

Before linking your EObject you have to make sure that
1) it is contained by a resource
2) the resource is managed by a resource set
(you may use the resource set of the diagram, accessible via
diagram.eResource.getResourceSet())

The same issue would occur with shapes, that is, the issue is not specific for connections.

Best, Tim

ps: If you do not call the link method, a delete of the connection would
not delete the EObject you are visualizing, so i think this is not a good idea. This explains also why your EObject has to be contained in an EResource: the framework needs to know how it is serialized to be able to delete it.
Re: Question about Connections with EReference [message #565842 is a reply to message #565822] Mon, 30 August 2010 07:13 Go to previous message
Tijs Rademakers is currently offline Tijs Rademakers
Messages: 9
Registered: August 2010
Junior Member
Hi Tim,

Thanks!
Now that you explained this I looked back at my code and saw that I already added my SequenceFlow object to the ResourceSet of the diagram with the following line:

getDiagram().eResource().getContents().add(sequenceFlow);

So I uncommented the link method call, and it works like a breeze.

Thanks,

Tijs
Previous Topic:Question about Connections with EReference
Next Topic:How to write JUnit tests for Graphiti?
Goto Forum:
  


Current Time: Wed Jul 23 12:26:18 EDT 2014

Powered by FUDForum. Page generated in 0.02231 seconds