Updating graphical model in MultiEditor [message #1452063] |
Fri, 24 October 2014 14:41  |
Eclipse User |
|
|
|
I have an EMF model that is being displayed in MultiEditor. One view is a tree and another is a Graphiti editor, in which graphical and EMF model are separated. Model can be updated in a tree tab and when switched to Graphiti tab changes are applied to the graphical model. What is the best way of synchronizing Graphiti model? Should I be removing everything and recreating graphical model from EMF model or updating existing model and if yes then how? I suppose I can employ EContentAdapter is this case?
[Updated on: Fri, 24 October 2014 15:45] by Moderator
|
|
|
|
|
|
|
Re: Updating graphical model in MultiEditor [message #1693399 is a reply to message #1456588] |
Thu, 23 April 2015 14:51   |
Eclipse User |
|
|
|
I changed my tree editor to use TransactionalEditingDomain and was trying to use this domain in both tree editor and Graphiti. However, I noticed that domain from the TreeVewier and domain used by Graphiti are using two different CommandStacks - TransactionalCommandStackImpl and GFWorkspaceCommandStackImpl, respectively. As a result I am not able to reuse my domain in place of Graphiti's because as I can see from the code Graphiti relies on GFWorkspaceCommandStackImpl. So what I am doing now is passing my domain to editor that extends DiagramEditor to listen to model changes and update Diagram accordingly:
transactionalEditingDomain.getCommandStack().addCommandStackListener(new CommandStackListener() {
@Override
public void commandStackChanged(EventObject event) {
TransactionalCommandStack commandStack = (TransactionalCommandStack) event.getSource();
Command command = commandStack.getMostRecentCommand();
if(command instanceof CreateChildCommand){
AddComponentCommand addCommand = new AddComponentCommand(domain, (CreateChildCommand)command, emfResource, diagram, graphicalResource);
addCommand.execute();
}
if(command instanceof DeleteCommand){
DeleteComponentCommand addCommand = new DeleteComponentCommand(domain, (DeleteCommand)command, emfResource, diagram, graphicalResource);
addCommand.execute();
}
}
});
Is there a better way to do this? Feels like I am missing a piece in MVC here, or not using one correctly offered by Grphiti.
Thanks,
Alex
|
|
|
|
Re: Updating graphical model in MultiEditor [message #1693527 is a reply to message #1693481] |
Fri, 24 April 2015 14:55   |
Eclipse User |
|
|
|
Thanks Michael,
Got it working by using your suggestion. Still have a question about updating the actual Diagram. In AbstractUpdateFeature that I implement I see that update(...) method is being executed when I add something to the model in TreeViewer, great. In documentation for Update Feature I see that visual element is compared with model element, but there specific value is checked - pictogramName. When I have a model with many elements, how do I know what actually changed? In my TreeViewer I have a root with three children types in it, so if I add another child, how do I know what was added to the model? Do I need to compare whole visual model against data model and note the differences?
Edit Yes, that's exactly what's going on - model is updated (since it's the same domain) and model objects are compared with their Pictogram counterparts.
Thanks,
Alex
[Updated on: Mon, 27 April 2015 14:36] by Moderator
|
|
|
|
|
|
|
Re: Updating graphical model in MultiEditor [message #1694551 is a reply to message #1694508] |
Wed, 06 May 2015 05:02  |
Eclipse User |
|
|
|
Sorry, I meant for your implementation: I haven't tried that myself and
maybe I'm wrong, but sorting out which changes were done in the editor and
if they affect your domain model or simply the graphical representation.
Probably it is best to get hands-on and maybe it turns out not to be
tricky...
Michael
|
|
|
Powered by
FUDForum. Page generated in 0.05280 seconds