2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.actions
;
12 import org
.apache
.log4j
.Logger
;
13 import org
.eclipse
.core
.commands
.ExecutionException
;
14 import org
.eclipse
.core
.commands
.operations
.AbstractOperation
;
15 import org
.eclipse
.core
.commands
.operations
.IOperationHistory
;
16 import org
.eclipse
.core
.commands
.operations
.IUndoContext
;
17 import org
.eclipse
.core
.commands
.operations
.IUndoableOperation
;
18 import org
.eclipse
.core
.runtime
.IAdaptable
;
19 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
20 import org
.eclipse
.core
.runtime
.IStatus
;
21 import org
.eclipse
.jface
.action
.Action
;
22 import org
.eclipse
.jface
.resource
.ImageDescriptor
;
24 import eu
.etaxonomy
.taxeditor
.UiUtil
;
31 public abstract class UndoableAction
extends Action
{
32 private static final Logger logger
= Logger
.getLogger(UndoableAction
.class);
34 protected IUndoableOperation operation
;
37 protected UndoableAction(String text
, ImageDescriptor image
) {
39 setImageDescriptor(image
);
42 operation
= new UndoableOperation();
47 IOperationHistory operationHistory
= UiUtil
.getOperationHistory();
48 IUndoContext undoContext
= UiUtil
.getWorkbenchUndoContext();
49 operation
.addContext(undoContext
);
51 operationHistory
.execute(operation
, null, null);
52 operationHistory
.add(operation
);
53 } catch (ExecutionException e
) {
58 protected abstract IStatus
executeOperation();
59 protected abstract IStatus
redoOperation();
60 protected abstract IStatus
undoOperation();
62 class UndoableOperation
extends AbstractOperation
{
64 public UndoableOperation() {
65 super("'" + text
+ "'");
69 public IStatus
execute(IProgressMonitor monitor
, IAdaptable info
)
70 throws ExecutionException
{
71 return executeOperation();
75 public IStatus
redo(IProgressMonitor monitor
, IAdaptable info
)
76 throws ExecutionException
{
77 return redoOperation();
81 public IStatus
undo(IProgressMonitor monitor
, IAdaptable info
)
82 throws ExecutionException
{
83 return undoOperation();