Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Distinguish different types of connection in getAddFeature method
Distinguish different types of connection in getAddFeature method [message #1073210] Wed, 24 July 2013 10:25 Go to next message
Fabio Messina is currently offline Fabio Messina
Messages: 9
Registered: July 2013
Junior Member
Hi all. I started moving my first steps in Graphiti and I'm developing my first example: an editor of library domain-related diagrams.

I started modeling my domain in EMF, with a simple ecore model.

index.php/fa/15688/0/

Then I derived the genmodel file and generated model code.

After that I started writing the graphiti-related classes following the tutorial (and also giving a look at the chess example code as well at the plug-in project code generated with the graphiti template).
Now, my doubt is about the getAddFeature method of my featureProvider

@Override
	public IAddFeature getAddFeature(IAddContext context) {
		if (context instanceof IAddConnectionContext) {
			return new AddWrittenByFeature(this);
		}
		else if (context.getNewObject() instanceof Author){
			return new AddAuthorFeature(this);
		}
		else if (context.getNewObject() instanceof Book){
			return new AddBookFeature(this);
		}
		// TODO Auto-generated method stub
		return super.getAddFeature(context);
	}


As you can see, I check the type of context.getNewObject() to return the appropriate AddFeature BUT this works regarding to business objects. How can I perform a similar check for connections?
At the moment this is not a trouble cause I have a single type of connection, and so I adopted the solution consisting in checking the context. But what if I had different types of connections? How can I distinguish them (and return the right addFeature)?

Further, another question about persistence: at the moment I edit diagrams of type "library" and save them in my workspace. But how about the persistence of the sole model? Business object, if I correctly understand, exist at runtime (they're created in the create method of createFeature).

public Object[] create(ICreateContext context) {
		String newAuthorName = ExampleUtil.askString("Insert author name",
				"Provide a name for the new author", "NewAuthor");

		Author author = GraphitilibraryFactory.eINSTANCE.createAuthor();

		// Add model element to resource.
		// We add the model element to the resource of the diagram for
		// simplicity's sake. Normally, a customer would use its own
		// model persistence layer for storing the business model separately.
		getDiagram().eResource().getContents().add(author);
		author.setName(newAuthorName);

		addGraphicalRepresentation(context, author);

		return new Object[] { author };

	}


How can I implement persistence? I would like to have my model saved apart as a simple xml file. GMF does this thing using a couple of files (the model and the diagram).
If I use Graphiti I have to implement persistence by myself?

Thank you for your attention and for responses. They're pretty newbie questions but, you see, I'm new at developing Eclipse plugins.

[Updated on: Wed, 24 July 2013 10:27]

Report message to a moderator

Re: Distinguish different types of connection in getAddFeature method [message #1073341 is a reply to message #1073210] Wed, 24 July 2013 14:49 Go to previous messageGo to next message
Michael Wenz is currently offline Michael Wenz
Messages: 1618
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Fabio,

distinguishing different connection types can be done just the same as for
different shapes. The IAddConnectionContext also has a getNewObject() method
that returns the BO (in case you have one and it is set). If that is not the
case you might derive the connection type from the connection endpoints
(getSourceAnchor(), getTargetAnchor()) or by setting properties in the
context (context is a PropertyBag).

Saving your domain data into a separate file can be done by creating your
own EMF resource in the resource set of the editor and adding your created
domain objects to that resource instead of the diagram resource. The forum
entry
http://www.eclipse.org/forums/index.php?t=msg&th=172247&start=0&S=acb08c1bf425f0ccb0106fb3a46a4bad
should give some hints.

Michael
Re: Distinguish different types of connection in getAddFeature method [message #1075280 is a reply to message #1073210] Mon, 29 July 2013 07:10 Go to previous message
Fabio Messina is currently offline Fabio Messina
Messages: 9
Registered: July 2013
Junior Member
Thank you Michael, that was very helpful.
Previous Topic:How to gracefully cancel a transaction?
Next Topic:Better movement inside an editor
Goto Forum:
  


Current Time: Sat Oct 25 10:27:07 GMT 2014

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

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