E4/EAS/Undo Redo

From Eclipsepedia

< E4‎ | EAS
Jump to: navigation, search

Components should be able to isolate their own atomic operations for supporting undo/redo. These should be connected to the base platform in some way to ensure that when a user invokes undo/redo, the context of the application can be analyzed and the right operation stack can be processed for undoing/redoing.

Contents

Eclipse 3.x API

In Eclipse 3.x, the IWorkbenchOperationSupport interface provided by PlatformUI.getWorkbench().getOperationSupport() can be used for managing undo/redo support.

Execution operation

IWorkbenchOperationSupport operationSupport = PlatformUI.getWorkbench().getOperationSupport();
IOperationHistory operationHistory = operationSupport.getOperationHistory();
IStatus status = operationHistory.execute(undoableOperation, null, null);
if (!status.isOK()) {
  // handle the error
}

Undo operation

IWorkbenchOperationSupport operationSupport = PlatformUI.getWorkbench().getOperationSupport();
IOperationHistory operationHistory = operationSupport.getOperationHistory();
IStatus status = operationHistory.undo(undoableOperation, null, null);
if (!status.isOK()) {
  // handle the error
}

Redo operation

IWorkbenchOperationSupport operationSupport = PlatformUI.getWorkbench().getOperationSupport();
IOperationHistory operationHistory = operationSupport.getOperationHistory();
IStatus status = operationHistory.redo(undoableOperation, null, null);
if (!status.isOK()) {
  // handle the error
}