Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » Graphiti » recommended way to group updates?(Or, making the command stack cleaner when multiple diagram elements reflect one business object)
recommended way to group updates? [message #891688] Mon, 25 June 2012 13:55 Go to next message
Ed Swartz is currently offline Ed SwartzFriend
Messages: 3
Registered: June 2012
Location: Austin, TX
Junior Member

I was playing with the (quite enlightening) Graphiti tutorial and came across a behavior I hadn't seen described elsewhere.

The issue is, when I have multiple pictogram elements representing the same business object, and I issue a command that changes the business object, then by default, only the initial pictogram element is updated.

(For example, in the tutorial, drag the same EClass multiple times into the diagram, then use the direct editing feature to change the label of one of the diagrams. Only one will change and the others will become disconnected/invalid until manually updated.)

I initially tried implementing IDiagramTypeProvider.isAutoUpdateAtRuntime() to return true, and this successfully updated all the pictogram elements. BUT, then the command stack had N+1 "Update element" entries added, since each update counted as a separate command.

(From what I can tell, this is because DomainModelChangeListener#resourceSetChanged issues its updates asynchronously, which means those changes occur after the initial command has executed, thus the original transaction was closed and each subsequent update appears to be a standalone change.)

So, I found a workaround, which is to mimic what that change listener does. If I add this at the end of TutorialDirectEditEClassFeature#setValue():

  // we know that multiple elements may use the same BO -- force refresh
        PictogramElement[] related = getDiagramEditor().getDiagramTypeProvider().getNotificationService().calculateRelatedPictogramElements(
        		new Object[] { eClass });

Then it works -- there is one entry on the command stack that handles the BO change and all the updates, and they can all be undone/redone in one shot.

But, I'm concerned I'd have to follow this pattern in every feature that updates a business object -- there's no telling how many pictogram elements may be affected, given what other features may be doing.

So, I wonder, should this kind of update not be the standard behavior for any feature that changes a business object? Or is there some other mechanism for doing what I need?

-- Ed
Re: recommended way to group updates? [message #891861 is a reply to message #891688] Tue, 26 June 2012 11:05 Go to previous messageGo to next message
Michael Wenz is currently offline Michael WenzFriend
Messages: 1921
Registered: July 2009
Location: Walldorf, Germany
Senior Member
Correct, the automatic update mechanism of Graphiti does the updates in
separate transactions causing separate undo stack entries. This is due to
the EMF adapters used for notifying. A change is done to the domain model,
the EMF adapter triggers the update asynchronously in the UI thread.

An additional option might be to have an transaction EMF adapter that just
listens for the changes done in the current transaction and updates the
current diagram directly within the transaction. Not sure if that is
doable... Besides that might have others effects for various tools, that's
why we decided to not do this at least for now (as you can see in the
comment at the end of TutorialDirectEditEClassFeature.setValue() there were
thoughts about that). Nevertheless, simply open an enhancement bugzilla for
this if you see an advantage in having this.

Instead we decided that each modifying feature needs to update effected
pictogram elements as your coding does. This is the most flexible soultion,
unfotunatly a litte heavy to manage. An easier to implement alternative
would be to trigger an update for the diagran and have a subclass of
DefaultUpdateDiagramFeature do the work for all features?

Re: recommended way to group updates? [message #891901 is a reply to message #891861] Tue, 26 June 2012 13:22 Go to previous message
Ed Swartz is currently offline Ed SwartzFriend
Messages: 3
Registered: June 2012
Location: Austin, TX
Junior Member
Thanks, I understand the reasoning.

Your suggestion worked -- I just did "updatePictogramElement(getDiagram())" and that worked without extending DefaultUpdateDiagramFeature.

Sometimes the answers are right there in front of one's eyes Smile

-- Ed

Previous Topic:Show Properties View in Context Menu
Next Topic:Customized Editing Domain for Diagram Editor
Goto Forum:

Current Time: Tue Aug 04 12:11:35 GMT 2020

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

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

Back to the top