Undo/Redo mechanism [message #524353] |
Wed, 31 March 2010 15:31 |
hodac 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 #700438 is a reply to message #534790] |
Sat, 23 July 2011 12:30 |
|
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
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.06981 seconds