Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Newcomers » Newcomers » Undo/Redo mechanism(undo/redo buttons remains gray)
Undo/Redo mechanism [message #524353] Wed, 31 March 2010 15:31 Go to next message
hodac  is currently offline hodac Friend
Messages: 29
Registered: December 2009
Junior Member
Hello,

I have created an editor in a RCP application. I want to enable undo/redo support.

I create a custom plugin that my RCP application depends on to enable the toolbar buttons:

<?xml version="1.0" encoding="UTF-8"?>
<?eclipse version="3.4"?>
<plugin>
   <extension
         point="org.eclipse.ui.menus">
      <menuContribution
          locationURI="toolbar:org.eclipse.ui.main.toolbar?after=additions">
         <toolbar
               id="undoredo.toolbar">
            <command
                  commandId="org.eclipse.ui.edit.undo"
                  id="undoredo.undo"
                  style="push">
            </command>
            <command
                  commandId="org.eclipse.ui.edit.redo"
                  id="undoredo.redo"
                  style="push">
            </command>
            <command
                  commandId="org.eclipse.ui.file.save"
                  id="file.save"
                  style="push">
            </command>
         </toolbar>
      </menuContribution>
   </extension>

</plugin>


then, I my editor class (in fact, in a delegate class) I call in the constructor:

	private void createGlobalActionHandlers() {
		// set up action handlers that operate on the current context
		undoAction = new UndoActionHandler(site, undoContext);
		redoAction = new RedoActionHandler(site, undoContext);
		IActionBars actionBars = site.getActionBars();
		actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
		undoAction);
		actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),
		redoAction);
		}



and in my usecase (MoveOperation extends AbstractOperation):

		final Point init = initialMousePos;
		ArrayList <SvgComponent> toMove = new ArrayList<SvgComponent>(lockedAsClicked);
		toMove.add(component);
		
		IUndoableOperation op = new MoveOperation(toMove, initialMousePos, endMousePoint);
		op.addContext(undoContext);
		try {
			OperationHistoryFactory.getOperationHistory().execute(op, null, null);
		} catch (ExecutionException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}


The execute method of my MoveOperation is called but the undo/redo buttons remains disabled (grey)

what did I miss?

In addition, I can see in the error log that some errors are logged (see below). I found that the package explorer view that I have in my perspective installs some undo/redo with the context=null. I found that the package explorer calls
	/**
	 * Creates a new <code>RefactorActionGroup</code>. The group requires
	 * that the selection provided by the part's selection provider is of type <code>
	 * org.eclipse.jface.viewers.IStructuredSelection</code>.
	 *
	 * @param part the view part that owns this action group
	 */
	public RefactorActionGroup(IViewPart part) {
		this(part.getSite(), null);

		IUndoContext workspaceContext= (IUndoContext)ResourcesPlugin.getWorkspace().getAdapter(IUndoContext.class);
		fUndoRedoActionGroup= new UndoRedoActionGroup(part.getViewSite(), workspaceContext, true);

		installQuickAccessAction();
	}


with workspaceContext returned = null!!


here is the stack trace
org.eclipse.core.runtime.AssertionFailedException: null argument:
at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:85)
at org.eclipse.core.runtime.Assert.isNotNull(Assert.java:73)
at org.eclipse.core.commands.operations.AbstractOperation.hasContext(AbstractOperation.java:153)
at org.eclipse.ui.operations.OperationHistoryActionHandler$HistoryListener.historyNotification(OperationHistoryActionHandler.java:141)
at org.eclipse.core.commands.operations.DefaultOperationHistory$2.run(DefaultOperationHistory.java:939)
at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
at org.eclipse.core.commands.operations.DefaultOperationHistory.notifyListeners(DefaultOperationHistory.java:928)
at org.eclipse.core.commands.operations.DefaultOperationHistory.notifyAdd(DefaultOperationHistory.java:990)
at org.eclipse.core.commands.operations.DefaultOperationHistory.add(DefaultOperationHistory.java:190)
at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:528)
at com.moow.svg.editor.AbstractSelectionMaskLayer.commitMove(AbstractSelectionMaskLayer.java:363)
at com.moow.svg.editor.AbstractSelectionMaskLayer.access$3(AbstractSelectionMaskLayer.java:355)
at com.moow.svg.editor.AbstractSelectionMaskLayer$6.handleEvent(AbstractSelectionMaskLayer.java:328)
at org.apache.batik.dom.events.EventSupport.fireEventListeners(EventSupport.java:324)
at org.apache.batik.dom.events.EventSupport.fireEventListeners(EventSupport.java:366)
at org.apache.batik.dom.events.EventSupport.dispatchEvent(EventSupport.java:276)
at org.apache.batik.dom.AbstractNode.dispatchEvent(AbstractNode.java:1014)
at org.apache.batik.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(BridgeEventSupport.java:405)
at org.apache.batik.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(BridgeEventSupport.java:341)
at org.apache.batik.bridge.BridgeEventSupport$Listener.mouseReleased(BridgeEventSupport.java:257)
at org.apache.batik.gvt.event.AbstractAWTEventDispatcher.processMouseEvent(AbstractAWTEventDispatcher.java:612)
at org.apache.batik.gvt.event.AbstractAWTEventDispatcher.dispatchMouseEvent(AbstractAWTEventDispatcher.java:545)
at org.apache.batik.gvt.event.AbstractAWTEventDispatcher.dispatchEvent(AbstractAWTEventDispatcher.java:387)
at org.apache.batik.gvt.event.AbstractAWTEventDispatcher.mouseReleased(AbstractAWTEventDispatcher.java:174)
at org.apache.batik.swing.svg.AbstractJSVGComponent$19.run(AbstractJSVGComponent.java:2146)
at org.apache.batik.util.RunnableQueue.run(RunnableQueue.java:237)
at java.lang.Thread.run(Unknown Source)
Re: Undo/Redo mechanism [message #534790 is a reply to message #524353] Thu, 20 May 2010 10:59 Go to previous messageGo to next message
Carsten Labinsky is currently offline Carsten LabinskyFriend
Messages: 3
Registered: May 2010
Junior Member
Hi,

I had the same problem and after several hours of search I found the cause: It looks like the Command-Framework is not yet complete at that point. See https://bugs.eclipse.org/bugs/show_bug.cgi?id=270007

Workaround: To enable the Undo/Redo-Commands you may register the following Actions in your ApplicationActionBarAdvisior...
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {

    /* ... */

    protected void makeActions(IWorkbenchWindow window) {
	register(ActionFactory.UNDO.create(window));
	register(ActionFactory.REDO.create(window));
	/* ... */
    }

}



It may be a bit too late for you, hodac, but I will post it anyway as a guide for other developers. Smile

Hope it helps,
Carsten

[Updated on: Thu, 20 May 2010 11:02]

Report message to a moderator

Re: Undo/Redo mechanism [message #534827 is a reply to message #534790] Thu, 20 May 2010 13:12 Go to previous messageGo to next message
hodac  is currently offline hodac Friend
Messages: 29
Registered: December 2009
Junior Member
it's never too late! it works now thank's to you! Razz

but still not perfect for me:

I'd like to have an undo/redo history for each of my editor. For the moment, if I have 2 open editors (different imputs), the operations are stacked together in the history. Did you succeeded in having 2 different stacks?

For the moment I have tried

IOperationHistory operationHistory= PlatformUI.getWorkbench().getOperationSupport().getOperationHistory();
operationHistory.execute(op, null, null);


and

OperationHistoryFactory.getOperationHistory().execute(op, null, null);
Re: Undo/Redo mechanism [message #534913 is a reply to message #534827] Thu, 20 May 2010 15:50 Go to previous messageGo to next message
Carsten Labinsky is currently offline Carsten LabinskyFriend
Messages: 3
Registered: May 2010
Junior Member
Let each editor provide its own UndoContext. See topic Undo contexts in
http://help.eclipse.org/galileo/index.jsp?topic=/org.eclipse .platform.doc.isv/guide/wrkAdv_undo.htm
for further information.

Here is how I did it...

Quote:

public class MyEditor extends GraphicalEditor {
private final IUndoContext undoContext = new ObjectUndoContext(this);
...
public IUndoContext getUndoContext() {
return undoContext;
}
...



Add this context to the operation before execution:
Quote:

IOperationHistory operationHistory= PlatformUI.getWorkbench().getOperationSupport().getOperation History();
op.addContext(editor.getUndoContext());
operationHistory.execute(op, null, null);



To support context switching when the active editor changes, I also had to declare a contributor for my editor in plugin.xml (extensions->org.eclipse.ui.editors->myEditor->Property "contributorClass").

Quote:

public class MyEditorContributor extends ActionBarContributor {

@Override
protected void buildActions() {}

@Override
protected void declareGlobalActionKeys() {
addGlobalActionKey(ActionFactory.UNDO.getId());
addGlobalActionKey(ActionFactory.REDO.getId());
}

}



Good luck.
Re: Undo/Redo mechanism [message #535319 is a reply to message #534913] Sat, 22 May 2010 08:39 Go to previous messageGo to next message
hodac  is currently offline hodac Friend
Messages: 29
Registered: December 2009
Junior Member
hello,

is it the whole contributor class you pasted here?

do you register actions in your editor (getActionRegister())?
I personally don't depend on GEF. The code source of GEF shows that your undo/redo actions must be registered in the editor...

can you tell me if so?

Re: Undo/Redo mechanism [message #700438 is a reply to message #534790] Sat, 23 July 2011 12:30 Go to previous messageGo to next message
Philipp M. Fischer is currently offline Philipp M. FischerFriend
Messages: 67
Registered: November 2010
Location: Germany
Member
Hi Everyone,

I am developing an RCP based on Eclipse 3.6. It is extending the application "org.eclipse.ui.ide.workbench". I am facing the smae problem, but debugging the ide.Workbensch, i can see that the Undo and Redo actions are registered as mentioned. What else could go wrong?

Cheers

Phil
Re: Undo/Redo mechanism [message #701929 is a reply to message #700438] Mon, 25 July 2011 18:39 Go to previous messageGo to next message
Eric Rizzo is currently offline Eric RizzoFriend
Messages: 3070
Registered: July 2009
Senior Member
On 7/23/11 8:30 AM, Phil M. Fischer wrote:
> Hi Everyone,
>
> I am developing an RCP based on Eclipse 3.6. It is extending the
> application "org.eclipse.ui.ide.workbench". I am facing the smae
> problem, but debugging the ide.Workbensch, i can see that the Undo and
> Redo actions are registered as mentioned. What else could go wrong?

Probably better to ask on the Platform forum group; this is not really a
question for newbies using Eclipse.

Eric
Re: Undo/Redo mechanism [message #994783 is a reply to message #701929] Fri, 28 December 2012 08:50 Go to previous message
akhil gupta is currently offline akhil guptaFriend
Messages: 13
Registered: November 2012
Junior Member
Hello all,

I am implementing undo redo functionality in my form based editor, But i don't know to incorporate it into my project. Can any one suggest any pointer or help on this.

Thanks in Advance!
Regards,
Akhil
Previous Topic:How to get read of closed entityManager after each redeployment?
Next Topic:activate buttons to reach new class
Goto Forum:
  


Current Time: Thu Mar 28 22:34:59 GMT 2024

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

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

Back to the top