Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Trouble Implementing an IUndoableOperation in my RCP application using my own IUndoContext(I think my trouble is getting my view associated to the proper IUndoContext, but I'm not sure.)
Trouble Implementing an IUndoableOperation in my RCP application using my own IUndoContext [message #1081931] Wed, 07 August 2013 22:09
Trace Windham is currently offline Trace WindhamFriend
Messages: 17
Registered: July 2009
Junior Member
I've implemented my operation class and it extends org.eclipse.core.commands.operations.AbstractOperation, so it has implementations of the methods execute(), redo(), and undo().

At first, I could only get the execute() method to be called (because I was calling it directly), but I could never see an undo or redo command become available on my Eclipse undo redo buttons (I have them contributed to my RCP application's Edit menu in the main menu).

Then I include an example plugin in the run configuration of my RCP application called (org.eclipse.ui.examples.undo), and magic started happening.

Using the view "Undo History View" that came with the example plugin, I could see my custom undo and redo items being added to the stack of things to undo and redo. Plus, when the "Undo History View" is active, my custom undo redo actions are showing up in the Eclipse undo redo buttons that I mentioned earlier. So, it's working, but there's a problem.

When I select my view part the items disappear from the Eclipse undo redo buttons. My assumption is that I'm not using the IUndoContext correctly.

Here's what I have as far as execution of the operation. The MyCustomOperation class extends org.eclipse.core.commands.operations.AbstractOperation. And the activePart field is an instance of my View Part that creates my instance of my IUndoContext on getUndoContext()

    MyCustomeOperation operation = new MyCustomOperation("My Custom Operation Label");
    IWorkbench workbench = activePart.getSite().getWorkbenchWindow().getWorkbench();
    IOperationHistory operationHistory = workbench.getOperationSupport().getOperationHistory();
    IUndoContext undoContext = activePart.getUndoContext();
    operation.addContext(undoContext);
    operationHistory.execute(operation, new NullProgressMonitor(), null);


The getUndoContext() method in my view part looks like this

    public IUndoContext getUndoContext() {
        if(undoContext == null) {
            undoContext = new ObjectUndoContext(this, "Inventory View Part Undo Context");
        }
        return undoContext;
    }

I believe that this will get me one IUndoContext per instance of my view part.


I'm using the documentation from:

Platform Plug-in Developer Guide > Programmer's Guide > Advanced workbench concepts > Undoable operations

I've noticed that a section on that page called Undo and redo action handlers is marked as Deprecated, so I didn't use the code from there at first, but when I was desperate, I added this line to my view part's createPartControl() method:

new UndoRedoActionGroup(this.getSite(), undoContext, true);


but it still exhibits the same behavior as before I added that line.

Does anyone see what I'm missing here?

Thanks,
Trace Windham
Previous Topic:Own Eclipse Debugger, select active Thread
Next Topic:Eclipse file system: Relationship between files
Goto Forum:
  


Current Time: Fri Apr 26 12:16:28 GMT 2024

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

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

Back to the top