Distinguish different types of connection in getAddFeature method [message #1073210] |
Wed, 24 July 2013 10:25 |
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.
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.03399 seconds