KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > operations > UndoActionHandler


1 /*******************************************************************************
2  * Copyright (c) 2005, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.operations;
12
13 import org.eclipse.core.commands.ExecutionException;
14 import org.eclipse.core.commands.operations.IUndoContext;
15 import org.eclipse.core.commands.operations.IUndoableOperation;
16 import org.eclipse.core.runtime.IProgressMonitor;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.ui.ISharedImages;
19 import org.eclipse.ui.IWorkbenchPartSite;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.internal.WorkbenchMessages;
22
23
24 /**
25  * <p>
26  * UndoActionHandler provides common behavior for performing an undo, as
27  * well as labelling and enabling the undo menu item. This class may be
28  * instantiated by clients.
29  * </p>
30  *
31  * @since 3.1
32  */

33 public final class UndoActionHandler extends OperationHistoryActionHandler {
34
35     /**
36      * Construct an action handler that handles the labelling and enabling of
37      * the undo action for the specified undo context.
38      *
39      * @param site
40      * the workbench part site that created the action.
41      * @param context
42      * the undo context to be used for the undo
43      */

44     public UndoActionHandler(IWorkbenchPartSite site, IUndoContext context) {
45         super(site, context);
46         setImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
47                 .getImageDescriptor(ISharedImages.IMG_TOOL_UNDO));
48         setDisabledImageDescriptor(PlatformUI.getWorkbench().getSharedImages()
49                 .getImageDescriptor(ISharedImages.IMG_TOOL_UNDO_DISABLED));
50     }
51
52     void flush() {
53         getHistory().dispose(getUndoContext(), true, false, false);
54     }
55
56     String JavaDoc getCommandString() {
57         return WorkbenchMessages.Operations_undoCommand;
58     }
59     
60     String JavaDoc getTooltipString() {
61         return WorkbenchMessages.Operations_undoTooltipCommand;
62     }
63     
64     String JavaDoc getSimpleCommandString() {
65         return WorkbenchMessages.Workbench_undo;
66     }
67     
68     String JavaDoc getSimpleTooltipString() {
69         return WorkbenchMessages.Workbench_undoToolTip;
70     }
71
72     IUndoableOperation getOperation() {
73         return getHistory().getUndoOperation(getUndoContext());
74
75     }
76
77     IStatus runCommand(IProgressMonitor pm) throws ExecutionException {
78         return getHistory().undo(getUndoContext(), pm, this);
79     }
80
81     boolean shouldBeEnabled() {
82         return getHistory().canUndo(getUndoContext());
83     }
84 }
85
Popular Tags