recommended way to group updates? [message #891688] |
Mon, 25 June 2012 13:55 |
Ed Swartz Messages: 3 Registered: June 2012 Location: Austin, TX |
Junior Member |
|
|
Hi,
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 });
getDiagramEditor().getDiagramTypeProvider().getNotificationService().updatePictogramElements(related);
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06524 seconds