RedoOperationAction.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.traceviewer.operation;
00002 
00003 import org.eclipse.core.commands.ExecutionException;
00004 import org.eclipse.core.commands.operations.IUndoableOperation;
00005 import org.eclipse.core.runtime.IStatus;
00006 import org.eclipse.jface.action.Action;
00007 import org.eclipse.jface.resource.ImageDescriptor;
00008 import org.eclipse.swt.widgets.Control;
00009 import org.eclipse.swt.widgets.Menu;
00010 
00011 public class RedoOperationAction extends OperationHistoryAction {
00012 
00013     public RedoOperationAction(ImageDescriptor img) {
00014         super(img);
00015     }
00016 
00017 
00018     @Override
00019     protected IUndoableOperation[] getHistory() {
00020         return TraceOperation.getRedoHistory();
00021     }
00022 
00023     @Override
00024     public Menu getMenu(Control parent) {
00025         Menu menu = getMenu();
00026         if (menu != null) 
00027             menu.dispose();
00028         
00029         menu = new Menu(parent);
00030         
00031         IUndoableOperation[] operations = getHistory();
00032         
00033         // create a list of menus of undoable operations
00034         for (int i=operations.length-1; i>=0; i--) {
00035             final IUndoableOperation op = operations[i];
00036             Action action = new Action(op.getLabel()) {
00037                 public void run() {
00038                     execute(op);
00039                 }
00040             };
00041             addActionToMenu(menu, action);
00042         } 
00043         return menu;
00044     }
00045 
00046     
00047     @Override
00048     protected void execute() {
00049 
00050         IUndoableOperation[] undos = TraceOperation.getUndoHistory();
00051         
00052         if (undos.length == 0) {
00053             // hack: when there's no undo, we need to remove the current
00054             // history into the undo stack. To do this properly, we
00055             // should perform an extra redo before the real redo
00056 
00057             doRedo();
00058         }
00059         doRedo();
00060     }
00061 
00062     /****
00063      * helper method to perform the default redo
00064      */
00065     private void doRedo() {
00066         try {
00067             IStatus status = TraceOperation.getOperationHistory().
00068                     redo(TraceOperation.undoableContext, null, null);
00069             if (!status.isOK()) {
00070                 System.err.println("Cannot redo: " + status.getMessage());
00071             }
00072         } catch (ExecutionException e) {
00073             e.printStackTrace();
00074         }
00075     }
00076     
00077     @Override
00078     protected void execute(IUndoableOperation operation) {
00079         try {
00080             TraceOperation.getOperationHistory().redoOperation(operation, null, null);
00081         } catch (ExecutionException e) {
00082             e.printStackTrace();
00083         }
00084     }
00085 
00086 
00087     @Override
00088     protected IUndoableOperation[] setStatus() {
00089         final IUndoableOperation []ops = getHistory(); 
00090         //debug("redo", ops);
00091         //System.out.println();
00092         setEnabled(ops.length>0);
00093         return ops;
00094     }
00095 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1