Results 1 to 3 of 3
- 02-03-2009, 09:36 PM #1
Member
- Join Date
- Feb 2009
- Posts
- 3
- Rep Power
- 0
[Beginner]Eclipse RCP Undo/redo operation
Hello,
First, sorry for my english :o
Recently, I tried to use this tutorial :
http:
//help.eclipse.org/help32/index.jsp?topic=/org.eclipse.platform.doc.isv/guide/wrkAdv_undo.htm]Help - Eclipse SDK
I created a simple RCP application (Hello RCP)
I added 2 Menus (File and Edit)
In file menu, I added an ActionSetJava Code:public class ApplicationActionBarAdvisor extends ActionBarAdvisor { public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) { super(configurer); } protected void makeActions(IWorkbenchWindow window) { } protected void fillMenuBar(IMenuManager menuBar) { IWorkbenchWindow window = getActionBarConfigurer().getWindowConfigurer().getWindow(); menuBar.add(createFileMenu(window)); menuBar.add(createEditMenu(window)); } private MenuManager createFileMenu(IWorkbenchWindow window) { MenuManager menuMgr = new MenuManager("Fichier",IWorkbenchActionConstants.M_FILE); menuMgr.add(new GroupMarker(IWorkbenchActionConstants.FILE_START)); menuMgr.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS)); IWorkbenchAction action = ActionFactory.QUIT.create(window); menuMgr.add(action); action.setText("Quitter"); menuMgr.add(new GroupMarker(IWorkbenchActionConstants.FILE_END)); return menuMgr; } private MenuManager createEditMenu(IWorkbenchWindow window) { MenuManager menuEdit = new MenuManager("Edition",IWorkbenchActionConstants.M_EDIT); IWorkbenchAction undo = ActionFactory.UNDO.create(window); IWorkbenchAction redo = ActionFactory.REDO.create(window); menuEdit.add(undo); menuEdit.add(redo); return menuEdit; } }
This ActionSet started an action who implemented IWorkbenchWindowActionDelegateJava Code:<extension point="org.eclipse.ui.actionSets"> <actionSet id="MonApplication.actionSet2" label="label" visible="true"> <action class="fr.MonApplication.Actions.MonAction" id="MonApplication.action2" label="mon action" menubarPath="file/groupe1" style="push"> </action> </actionSet> </extension>
The Action run an undoable opérationJava Code:public class MonAction implements IWorkbenchWindowActionDelegate { private IWorkbenchWindow window; @Override public void dispose() { // TODO Auto-generated method stub } @Override public void init(IWorkbenchWindow window) { this.window = window; } @Override public void run(IAction action) { //Création d'une opération annulable IUndoableOperation operation = new ActionOperation(window.getShell()); //Récupéreation de l'historique des opérations du workbench IWorkbench workbench = window.getWorkbench(); IOperationHistory operationHistory = workbench.getOperationSupport().getOperationHistory(); operationHistory = OperationHistoryFactory.getOperationHistory(); //Récupération du contexte d'annulation du workbench IUndoContext undoContext = workbench.getOperationSupport().getUndoContext(); //ajout du contexte d'annulation operation.addContext(undoContext); //On lance l'opération d'ajout d'équipement à la fiche de manoeuvre try { operationHistory.execute(operation,null,null); } catch (ExecutionException e) { // TODO Auto-generated catch block e.printStackTrace(); } } @Override public void selectionChanged(IAction action, ISelection selection) { // TODO Auto-generated method stub } }
My problem :Java Code:public class ActionOperation extends AbstractOperation{ private Shell shell; public ActionOperation(Shell shell) { super("Test operation"); this.shell = shell; } @Override public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { MessageDialog.openInformation(shell, "Test", "Action executée"); return Status.OK_STATUS; } @Override public IStatus redo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { MessageDialog.openInformation(shell, "Test", "action Undo executée"); return Status.OK_STATUS; } @Override public IStatus undo(IProgressMonitor monitor, IAdaptable info) throws ExecutionException { MessageDialog.openInformation(shell, "Test", "action Redo executée"); return Status.OK_STATUS; } }
I execute my operation (execution ok), the undo menu remains disabled, whereas the operationHistory is not emty
The used example is very simple but I don't understand why the menu remains disabled
Thanks in advance for your help :)
VinceLast edited by pollux; 02-05-2009 at 07:28 PM.
- 02-18-2009, 01:46 PM #2
Member
- Join Date
- Feb 2009
- Posts
- 1
- Rep Power
- 0
How to enable Undo/Redo Menus
An UndoActionHandler must be applied for the menu to be enabled.
Create your handlers:
private UndoActionHandler undoAction;
private RedoActionHandler redoAction;
In your createPartControl method, assign the handles for undo/redo:
public void createPartControl(Composite parent) {
...
createGlobalActionHandlers();
}
private void createGlobalActionHandlers() {
// set up action handlers that operate on the current context
undoAction = new UndoActionHandler(this.getSite(), undoContext);
redoAction = new RedoActionHandler(this.getSite(), undoContext);
IActionBars actionBars = getViewSite().getActionBars();
actionBars.setGlobalActionHandler(ActionFactory.UN DO.getId(),
undoAction);
actionBars.setGlobalActionHandler(ActionFactory.RE DO.getId(),
redoAction);
}
Now when your view is selected, the undo/redo options should appear.
- 02-18-2009, 06:39 PM #3
Member
- Join Date
- Feb 2009
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
Help in building little text editor that perform the UNDO operation
By realahmed8 in forum New To JavaReplies: 6Last Post: 04-20-2009, 01:46 AM -
SWT Undo Redo
By Java Tip in forum SWTReplies: 0Last Post: 07-11-2008, 04:43 PM -
Undo/Redo JTextArea
By Java Tip in forum javax.swingReplies: 0Last Post: 06-27-2008, 07:52 PM -
Frame close operation
By Java Tip in forum Java TipReplies: 0Last Post: 12-21-2007, 08:39 AM -
undo java
By new214 in forum New To JavaReplies: 1Last Post: 11-20-2007, 09:16 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks