| Summary: | ResourceUndoContext should be more flexible regarding affected resource policy | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Modeling] EMF Services | Reporter: | Sébastien Gandon <sgandon> | ||||
| Component: | Transaction | Assignee: | Christian Damus <give.a.damus> | ||||
| Status: | VERIFIED FIXED | QA Contact: | |||||
| Severity: | enhancement | ||||||
| Priority: | P3 | CC: | ahunter.eclipse, ldamus | ||||
| Version: | unspecified | Keywords: | plan | ||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Windows XP | ||||||
| Whiteboard: | Client Control | ||||||
| Bug Depends on: | |||||||
| Bug Blocks: | 252378 | ||||||
| Attachments: |
|
||||||
|
Description
Sébastien Gandon
I think this mechanism should be able to help GMF to sort out some problems in managing the editor's dirty state according to its custom ModificationTrackingAdapter rules (cc'ing Linda fhi). Thanks for drawing this to my attention, Christian! This is exactly what we need in GMF. As I wrote on the EMF newsgroup (http://www.eclipse.org/newsportal/article.php?id=36900&group=eclipse.tools.emf#36900), in GMF we use the isModified state of the resource to determine whether or not a given GMF editor is dirty. GMFResource overrides ResourceImpl.ModificationTrackingAdapter to exclude notifications on transient features from changing the modified state of the GMFResource. In order for me to fix bug 149214, which will remove the dirty marker from GMF editors when changes to the resource are undone back to the last save point, my approach has been to make use of the ResourceUndoContexts added to undoable operations by the WorkspaceCommandStackImpl.DomainListener. I have assumed that if an operation has a ResourceUndoContext for a given resource, then the operation has in some way changed the state of that resource. Once all operations with the context for a given resource have been undone back to the last known save point, if the resource is in a GMF editing domain I will set the isModified state back to false. For this to work, GMF needs the logic that sets the modified state to true to correspond to the logic that adds ResourceUndoContexts to operations on the history. With this enhancement to WorkspaceCommandStackImpl, I expect GMF will be able to provide its own policy for when to add the ResourceUndoContexts for operations affecting its resources. Our policy will exclude notifications on transient features. Anthony, I've added you to the CC list, just FYI. (In reply to comment #2) > Thanks for drawing this to my attention, Christian! > > This is exactly what we need in GMF. As I wrote on the EMF newsgroup > (http://www.eclipse.org/newsportal/article.php?id=36900&group=eclipse.tools.emf#36900), > in GMF we use the isModified state of the resource to determine whether or not > a given GMF editor is dirty. Good! That was the conversation that reminded me of this bug in the first place. I'm glad to see more interest in it. > In order for me to fix bug 149214, which will remove the dirty marker from GMF > editors when changes to the resource are undone back to the last save point, my > approach has been to make use of the ResourceUndoContexts added to undoable > operations by the WorkspaceCommandStackImpl.DomainListener. I have assumed > that if an operation has a ResourceUndoContext for a given resource, then the > operation has in some way changed the state of that resource. Once all You mean the persistent state of the resource, right? As I understand it, GMF does some funkiness with transient containment (which is an odd notion, IMHO). > operations with the context for a given resource have been undone back to the > last known save point, if the resource is in a GMF editing domain I will set > the isModified state back to false. Sounds reasonable. > For this to work, GMF needs the logic that sets the modified state to true to > correspond to the logic that adds ResourceUndoContexts to operations on the > history. I suppose that GMF's resource implementation and undo-context strategy (implementing the new API of this bug) would share a single definition of these rules. > With this enhancement to WorkspaceCommandStackImpl, I expect GMF will be able > to provide its own policy for when to add the ResourceUndoContexts for > operations affecting its resources. Our policy will exclude notifications on > transient features. M3 is coming soon. Could I ask you to evaluate a patch when it is ready, so that this can be committed for the milestone (Wed. 5 Nov.)? Created attachment 116700 [details] Proposed API for resource undo-context policy Attached a proposed new API for client control over the undo-context policy. The basic idea is to extract the static ResourceUndoContext::getAffectedResources(...) API into a policy object that determines what resources are in an operation's undo context. Thus, we have an object that can be provided by clients with a default implementation supplied that behaves as the 1.2 release. The new IResourceUndeContextPolicy interface defines the protocol for this policy object. A default implementation is supplied that works as before, additionally resolving the isTouch() issue (bug 252378). Clients can plug in their own implementations by overriding a new getResourceUndoContextPolicy() method in the WorkspaceEditingDomainFactory. The AbstractResourceUndoContextPolicy class is the default implementation, with convenient override hooks for: - the directed cross-resource reference issue for which this bug was originally raised - handling of certain Resource properties that don't affect serialization I would like that somebody provide feed-back on this patch before I proceed any further. I've tried out the proposed API, and I'd like to request just one small change. Could you refactor the isTouch check in AbstractResourceUndoContextPolicy out into a new protected method? That will make it very simple for me to extend the criteria that determine whether or not a given notification should be ignored by the algorithm. In GMF we need to exclude notifications on transient features. Apart from that, the new API looks great for what we need in GMF. Thanks! Yes, of course, that's an obvious hook that I should have provided in the first place. Thanks for testing the patch! Committed the patch to HEAD (1.3 release) branch, with changes:
- added an isAbstractChange(Notification) hook to factor out the
!isTouch() criterion
- factored out the handling of resource and object events into
resourceChange(...) and objectChange(...) methods, respectively.
Also added resourceSetChange(...) because, well, you never know
what folks may need and these events were ignored, before
Fix available in HEAD: 1.3.0.I200811021821. Restore original target after milestones were deranged. |