Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 320617

Summary: [ModelTooling] Undo/Redo not working in 4.0
Product: [Eclipse Project] e4 Reporter: Thomas Schindl <tom.schindl>
Component: UIAssignee: Project Inbox <e4.ui-inbox>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: bokowski, john.arthorne, pwebster, remy.suen, susan
Version: 1.0   
Target Milestone: 1.0 RC3   
Hardware: All   
OS: All   
Whiteboard:
Attachments:
Description Flags
SubActionBar-hack to get at least undo/redo
none
ModelEditor only fix
none
3rd idea make retarget-action available in IActionCommandMappingService
none
3rd the second
none
ActionCommandMappingService patch v1
none
make sure RetargetActions generate action mappings v05 none

Description Thomas Schindl CLA 2010-07-22 08:23:32 EDT
It looks like there's a difference in how Undo/Redo is working in 3.x and 4.0. 

The model-editor has a single source and when running in a 3.x env the undo/redo is working whereas in 4.0 it's not.

It could naturally be that I'm doing something which only works by chance in 3.x but because this code part is more or standard when writing Editors with undo/redo I'd not be suprised if other editors 3rd party code would have the same problem.

The code in question is in:
* org.eclipse.e4.tools.emf.editor3x.E4WorkbenchModelEditor
* org.eclipse.e4.tools.emf.editor3x.UndoAction
* org.eclipse.e4.tools.emf.editor3x.RedoAction

You can reproduce this quite easy by installing the E4 Tools from the e4 2010 Updates - http://download.eclipse.org/e4/updates/2010
Comment 1 Susan McCourt CLA 2010-07-22 10:17:54 EDT
I'll look at this in more detail today.
I double-checked that both text undo and workspace undo (delete a file and then undo the delete) are working in 4.0.

So we know the general platform undo mechanism is working, it's a question of what the model editor is doing that is different.

Random theories (before looking closer)

- the action update timing used by the platform undo handlers (OperationHistoryActionHandler and subclassing) is somehow different than Tom's undo actions
- have to figure out how the EMF command stack fits in here.  Tom's actions are using the command stack to determine whether the action is enabled.  I don't know the details of EMF's implementation but will look into it...
Comment 2 Thomas Schindl CLA 2010-07-22 10:22:56 EDT
Thanks Susan, the command stack stuff is fairly simply every change of the EMF-Resource is recorded as a command you can remove the code and simply always pass true to setEnabled().

Ping me on IRC when you need help from me. I'm available all day long.
Comment 3 Thomas Schindl CLA 2010-07-23 09:10:07 EDT
It's not only me who doesn't have undo/redo support. As I expected other editors like e.g. the Ecore-Editor has no undo/redo (the reason is that my code is derived from how the EMF-Editors implement Undo/Redo).

From a usability PoV this is a major problem IMHO so we should try to find out what's going wrong here.
Comment 4 Thomas Schindl CLA 2010-07-24 07:12:44 EDT
So I've now tracked this down to MenuServiceFilter#setEnabled(MHandledMenuItem) which in case for e.g. the Box View-Example returns true but for the ModelEditor false.
Comment 5 Thomas Schindl CLA 2010-07-24 07:23:02 EDT
Ok. Next interesting thing is that HandlerServiceImpl#lookUpHandler the "Box View" has handler::...undo in the localValues but my view has not!
Comment 6 Thomas Schindl CLA 2010-07-24 07:53:32 EDT
Ok. I think I now found the problem. The reason the undo does NOT work is found EditorActionBars in org.eclipse.ui.SubActionBars#setGlobalActionHandler().

When retargeting an Action and the target has NO actionDefinitionId it fails to register the appropriate handler. Has there been a rule that one has to set the actionDefinitionId?

The BoxView example does it and that's why it is working!
Comment 7 Thomas Schindl CLA 2010-07-24 08:49:15 EDT
Investigating deeper reveals that the real problem is that RetargetActions are not registered in our ActionBarAdvisor#register().

Commenting out the instance check there makes the undo/redo behave as expected. The only thing not working is the updateing of the Label-Text but that's a minor issue.

The change was introduced by Remy with Bug 308593
Comment 8 Thomas Schindl CLA 2010-07-24 08:53:14 EDT
Some more information. The change was introduced with bug 308593 Comment 19
Comment 9 Thomas Schindl CLA 2010-07-24 09:44:02 EDT
Created attachment 175152 [details]
SubActionBar-hack to get at least undo/redo

This is a dirty but very simply and not risky workaround so that editors without a setActionDefinitionId() undo/redo support
Comment 10 Thomas Schindl CLA 2010-07-24 10:03:18 EDT
Created attachment 175153 [details]
ModelEditor only fix

If we are not fixing the generic case this is the fix for the ModelEditor
Comment 11 Boris Bokowski CLA 2010-07-24 10:24:43 EDT
Not sure which one I like better. Remy, do you have an opinion?
Comment 12 Paul Webster CLA 2010-07-24 11:10:00 EDT
Just a comment.  RetargetActions can't be part of the handler system, they'll break it.

But if the root cause is that there is no action command mapping for "undo" to the UNDO command id, the another possible fix would be to simply add the mapping when we create the action mapping service.  That would allow subActionBars.setGlobalActionHandler(*) to work without each having to set their action definition ID.

PW
Comment 13 Thomas Schindl CLA 2010-07-24 11:35:10 EDT
Created attachment 175154 [details]
3rd idea make retarget-action available in IActionCommandMappingService

This is the 3rd solution and probably better than SubActionBar hack because it makes all RetargetAction work
Comment 14 Thomas Schindl CLA 2010-07-24 11:37:20 EDT
Created attachment 175155 [details]
3rd the second
Comment 15 Remy Suen CLA 2010-07-24 13:23:16 EDT
Created attachment 175158 [details]
ActionCommandMappingService patch v1

Spot fix to implement Paul's suggested comment 12.
Comment 16 Paul Webster CLA 2010-07-24 16:31:20 EDT
(In reply to comment #14)
> Created an attachment (id=175155) [details]
> 3rd the second

The place to do the command mapping and return is where we currently avoid the RetargetAction (if we're not going to go with the spot fix).  We want to avoid allowing Menu Bar retarget actions further into the system.

PW
Comment 17 Thomas Schindl CLA 2010-07-24 19:09:00 EDT
I've now released at least the local fix for ModelEditor so that it has undo/redo because I need to go to bed for now.
Comment 18 Thomas Schindl CLA 2010-07-24 19:11:24 EDT
... i still hope we could at least fix undo/redo in a generic fashion because i think it is really important - even if we only fix this undo/redo case with remys patch I'm +1 for it.
Comment 19 Paul Webster CLA 2010-07-24 20:15:19 EDT
Created attachment 175168 [details]
make sure RetargetActions generate action mappings v05
Comment 20 Remy Suen CLA 2010-07-24 20:23:17 EDT
(In reply to comment #19)
> Created an attachment (id=175168) [details]
> make sure RetargetActions generate action mappings v05

I'm fine with this, +1. I also tested editors in two workbench windows to ensure there wasn't any funny business with the retrieval of the service at the window level.
Comment 21 Boris Bokowski CLA 2010-07-24 20:34:33 EDT
+1 from me
Comment 22 Paul Webster CLA 2010-07-24 20:39:44 EDT
(In reply to comment #19)
> Created an attachment (id=175168) [details]
> make sure RetargetActions generate action mappings v05

I've released it for the I20100724-2045 build.  Tom, thanks for your investigation!!

PW
Comment 23 Thomas Schindl CLA 2010-07-25 07:48:06 EDT
I can confirm that the latest build fixes the Undo/Redo
Comment 24 Remy Suen CLA 2010-07-27 13:49:56 EDT
Verified with the ecore editor using I20100726-2152 on Windows XP.