Updating graphical model in MultiEditor [message #1452063] |
Fri, 24 October 2014 18:41 |
Alex Kravets Messages: 561 Registered: November 2009 |
Senior Member |
|
|
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 19:45] Report message to a moderator
|
|
|
|
|
|
|
Re: Updating graphical model in MultiEditor [message #1693399 is a reply to message #1456588] |
Thu, 23 April 2015 18:51 |
Alex Kravets Messages: 561 Registered: November 2009 |
Senior Member |
|
|
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 18:55 |
Alex Kravets Messages: 561 Registered: November 2009 |
Senior Member |
|
|
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 18:36] Report message to a moderator
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05069 seconds