Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » Updating graphical model in MultiEditor
Updating graphical model in MultiEditor [message #1452063] Fri, 24 October 2014 18:41 Go to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 524
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 #1455593 is a reply to message #1452063] Wed, 29 October 2014 14:37 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1883
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Alex,

there is no general answer to this question, as it highly depends on your scenario. E.g. having many nodes on a diagram would be an argument for doing dedicated node updates while complex (deeply nested) node structures would be an argument for doing a complete update. You may even mix different strategies inside one diagram if that makes sense in your tool.

Michael
Re: Updating graphical model in MultiEditor [message #1455783 is a reply to message #1455593] Wed, 29 October 2014 19:04 Go to previous messageGo to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 524
Registered: November 2009
Senior Member
Thanks Michael.

I started implementing the update mechanism and have some questions. I added my own UpdateFeature to feature provider. When I create a new editor with diagram my update feature is being called via handleAutoUpdateAtStartup(). However, when I change my model in the tree editor, nothing is being called. I am missing some additional implementations that are needed for this to work?
Re: Updating graphical model in MultiEditor [message #1456437 is a reply to message #1455783] Thu, 30 October 2014 11:08 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1883
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Alex,

hard to say without going into details. In case both editors use the same editing domain, the pure EMF model change should trigger a notification of the diagram which should again trigger a call of the update feature. In order to have that working automatically, you need to have the shape you want to update linked to the domain object you change in the tree editor.

In case both editors use different editing domains, you would need to save the EMF model in order to get the diagram updated (update is triggered via file change events in that case).

Michael
Re: Updating graphical model in MultiEditor [message #1456588 is a reply to message #1456437] Thu, 30 October 2014 14:07 Go to previous messageGo to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 524
Registered: November 2009
Senior Member
I think that's what is the problem. I have two different editing domains.
Re: Updating graphical model in MultiEditor [message #1693399 is a reply to message #1456588] Thu, 23 April 2015 18:51 Go to previous messageGo to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 524
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 #1693481 is a reply to message #1693399] Fri, 24 April 2015 13:03 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1883
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Alex,

have you tried the other way round? Using the Graphiti editing domain for
your tree?

This will create a new Graphiti-style editing domain:
GraphitiUi.getEmfService().createResourceSetAndEditingDomain()

Michael
Re: Updating graphical model in MultiEditor [message #1693527 is a reply to message #1693481] Fri, 24 April 2015 18:55 Go to previous messageGo to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 524
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

Re: Updating graphical model in MultiEditor [message #1693787 is a reply to message #1693527] Tue, 28 April 2015 11:26 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1883
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Alex,

in that case I'm afraid you have to compare the complete model. The resource
update notification does not give any details on what detail has changed.

Michael
Re: Updating graphical model in MultiEditor [message #1693826 is a reply to message #1693787] Tue, 28 April 2015 14:49 Go to previous messageGo to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 524
Registered: November 2009
Senior Member
Thanks Michael.

I see that GFWorkspaceCommandStackImpl which extends WorkspaceCommandStackImpl gets access to getMostRecentCommand(), doesn't that tell us exactly what changed? Mostly like I don't fully understand something, please correct me if I am wrong.

Alex
Re: Updating graphical model in MultiEditor [message #1693956 is a reply to message #1693826] Wed, 29 April 2015 13:28 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1883
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Alex,

ah yes, I forgot it's the same editing domain here. I haven't tried that,
but that could be an option here. Mapping the changes recorded in the
command stack entries to domain model or graphical model changes could be a
little tricky though...

Michael
Re: Updating graphical model in MultiEditor [message #1694508 is a reply to message #1693956] Tue, 05 May 2015 18:55 Go to previous messageGo to next message
Alex Kravets is currently offline Alex KravetsFriend
Messages: 524
Registered: November 2009
Senior Member
Thanks Michael,

When you say "tricky" what do you mean? Is this something I can do, or does it involve changes in the framework?

Regards,
Alex
Re: Updating graphical model in MultiEditor [message #1694551 is a reply to message #1694508] Wed, 06 May 2015 09:02 Go to previous message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1883
Registered: July 2009
Location: Walldorf, Germany
Senior Member
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
Previous Topic:Advanced Property Section
Next Topic:MultiText transparency + animations in Graphiti
Goto Forum:
  


Current Time: Sun Jan 21 13:01:54 GMT 2018

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

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