01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.operations;
11:
12: import org.eclipse.core.commands.operations.IUndoContext;
13: import org.eclipse.ui.IActionBars;
14: import org.eclipse.ui.IWorkbenchPartSite;
15: import org.eclipse.ui.actions.ActionFactory;
16: import org.eclipse.ui.actions.ActionGroup;
17:
18: /**
19: * <p>
20: * UndoRedoActionGroup provides standard undo and redo action handlers for a
21: * workbench part site. It supports filtering of undo or redo on a particular
22: * undo context. The undo context can be optionally pruned, which means the
23: * context will be flushed actively whenever an invalid operation is found on
24: * top of its history. This class may be instantiated by clients.
25: * </p>
26: *
27: * @since 3.1
28: */
29: public final class UndoRedoActionGroup extends ActionGroup {
30:
31: private UndoActionHandler undoActionHandler;
32:
33: private RedoActionHandler redoActionHandler;
34:
35: /**
36: * Construct an undo redo action group for the specified workbench part
37: * site, using the specified undo context.
38: *
39: * @param site
40: * the workbench part site that is creating the action group
41: * @param undoContext
42: * the undo context to be used for filtering the operation
43: * history
44: * @param pruneHistory
45: * a boolean that indicates whether the history for the specified
46: * context should be pruned whenever an invalid operation is
47: * encountered.
48: */
49: public UndoRedoActionGroup(IWorkbenchPartSite site,
50: IUndoContext undoContext, boolean pruneHistory) {
51:
52: // create the undo action handler
53: undoActionHandler = new UndoActionHandler(site, undoContext);
54: undoActionHandler.setPruneHistory(pruneHistory);
55:
56: // create the redo action handler
57: redoActionHandler = new RedoActionHandler(site, undoContext);
58: redoActionHandler.setPruneHistory(pruneHistory);
59: }
60:
61: /*
62: * (non-Javadoc)
63: *
64: * @see org.eclipse.ui.actions.ActionGroup#fillActionBars(org.eclipse.ui.IActionBars)
65: */
66: public void fillActionBars(IActionBars actionBars) {
67: super.fillActionBars(actionBars);
68: if (undoActionHandler != null) {
69: actionBars.setGlobalActionHandler(ActionFactory.UNDO
70: .getId(), undoActionHandler);
71: actionBars.setGlobalActionHandler(ActionFactory.REDO
72: .getId(), redoActionHandler);
73: }
74: }
75: }
|