KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 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.operations.IUndoContext;
14 import org.eclipse.ui.IActionBars;
15 import org.eclipse.ui.IWorkbenchPartSite;
16 import org.eclipse.ui.actions.ActionFactory;
17 import org.eclipse.ui.actions.ActionGroup;
18
19 /**
20  * <p>
21  * UndoRedoActionGroup provides standard undo and redo action handlers for a
22  * workbench part site. It supports filtering of undo or redo on a particular
23  * undo context. The undo context can be optionally pruned, which means the
24  * context will be flushed actively whenever an invalid operation is found on
25  * top of its history. This class may be instantiated by clients.
26  * </p>
27  *
28  * @since 3.1
29  */

30 public final class UndoRedoActionGroup extends ActionGroup {
31
32     private UndoActionHandler undoActionHandler;
33
34     private RedoActionHandler redoActionHandler;
35
36     /**
37      * Construct an undo redo action group for the specified workbench part
38      * site, using the specified undo context.
39      *
40      * @param site
41      * the workbench part site that is creating the action group
42      * @param undoContext
43      * the undo context to be used for filtering the operation
44      * history
45      * @param pruneHistory
46      * a boolean that indicates whether the history for the specified
47      * context should be pruned whenever an invalid operation is
48      * encountered.
49      */

50     public UndoRedoActionGroup(IWorkbenchPartSite site,
51             IUndoContext undoContext, boolean pruneHistory) {
52
53         // create the undo action handler
54
undoActionHandler = new UndoActionHandler(site, undoContext);
55         undoActionHandler.setPruneHistory(pruneHistory);
56
57         // create the redo action handler
58
redoActionHandler = new RedoActionHandler(site, undoContext);
59         redoActionHandler.setPruneHistory(pruneHistory);
60     }
61
62     /*
63      * (non-Javadoc)
64      *
65      * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
66      */

67     public void fillActionBars(IActionBars actionBars) {
68         super.fillActionBars(actionBars);
69         if (undoActionHandler != null) {
70             actionBars.setGlobalActionHandler(ActionFactory.UNDO.getId(),
71                     undoActionHandler);
72             actionBars.setGlobalActionHandler(ActionFactory.REDO.getId(),
73                     redoActionHandler);
74         }
75     }
76 }
77
Popular Tags