KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > operations > WorkbenchOperationSupport


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
12 package org.eclipse.ui.internal.operations;
13
14 import org.eclipse.core.commands.operations.DefaultOperationHistory;
15 import org.eclipse.core.commands.operations.IOperationApprover;
16 import org.eclipse.core.commands.operations.IOperationHistory;
17 import org.eclipse.core.commands.operations.IUndoContext;
18 import org.eclipse.core.commands.operations.ObjectUndoContext;
19 import org.eclipse.core.commands.operations.OperationHistoryFactory;
20 import org.eclipse.ui.PlatformUI;
21 import org.eclipse.ui.internal.misc.Policy;
22 import org.eclipse.ui.operations.IWorkbenchOperationSupport;
23
24 /**
25  * <p>
26  * Provides undoable operation support for the workbench. This includes providing access to the default
27  * operation history and installing a workbench-specific operation approver that enforces a linear
28  * undo strategy.
29  * </p>
30  *
31  * @since 3.1
32  */

33 public class WorkbenchOperationSupport implements IWorkbenchOperationSupport {
34
35     private ObjectUndoContext undoContext;
36     private IOperationApprover approver;
37     
38     // initialize debug options
39
static {
40         DefaultOperationHistory.DEBUG_OPERATION_HISTORY_UNEXPECTED = Policy.DEBUG_OPERATIONS;
41         DefaultOperationHistory.DEBUG_OPERATION_HISTORY_OPENOPERATION = Policy.DEBUG_OPERATIONS;
42         DefaultOperationHistory.DEBUG_OPERATION_HISTORY_APPROVAL = Policy.DEBUG_OPERATIONS;
43         DefaultOperationHistory.DEBUG_OPERATION_HISTORY_NOTIFICATION = Policy.DEBUG_OPERATIONS && Policy.DEBUG_OPERATIONS_VERBOSE;
44         DefaultOperationHistory.DEBUG_OPERATION_HISTORY_DISPOSE = Policy.DEBUG_OPERATIONS && Policy.DEBUG_OPERATIONS_VERBOSE;
45     }
46
47     /**
48      * Disposes of anything created by the operation support.
49      */

50     public void dispose() {
51         /*
52          * uninstall the operation approver that we added to the operation history
53          */

54         getOperationHistory().removeOperationApprover(approver);
55         /*
56          * dispose of all operations using our context
57          */

58         getOperationHistory().dispose(getUndoContext(), true, true, true);
59     }
60
61     /**
62      * Returns the undo context for workbench operations.
63      * The workbench configures an undo context with the appropriate policies
64      * for the workbench undo model.
65      *
66      * @return the workbench operation context.
67      * @since 3.1
68      */

69     public IUndoContext getUndoContext() {
70         if (undoContext == null) {
71             undoContext = new ObjectUndoContext(PlatformUI.getWorkbench(),
72                     "Workbench Context"); //$NON-NLS-1$
73
}
74         return undoContext;
75     }
76
77     /**
78      * Returns the workbench operation history.
79      *
80      * @return the operation history for workbench operations.
81      * @since 3.1
82      */

83     public IOperationHistory getOperationHistory() {
84         IOperationHistory history = OperationHistoryFactory.getOperationHistory();
85         /*
86          * Set up the history if we have not done so before.
87          */

88         if (approver == null) {
89             /*
90              * install an operation approver that prevents linear undo violations
91              * in any context
92              */

93             approver = new AdvancedValidationUserApprover(getUndoContext());
94             history.addOperationApprover(approver);
95             /*
96              * set a limit for the workbench undo context
97              */

98             history.setLimit(getUndoContext(), 25);
99         }
100         return history;
101     }
102
103 }
104
Popular Tags