KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > commands > operations > OperationHistoryEvent


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.core.commands.operations;
12
13 import org.eclipse.core.runtime.IStatus;
14
15 /**
16  * <p>
17  * OperationHistoryEvent is used to communicate changes that occur in a
18  * DefaultOperationHistory, including the addition or removal of operations, and
19  * the execution, undo, and redo of operations.
20  * </p>
21  * <p>
22  * Operation history listeners must be prepared to receive notifications from a
23  * background thread. Any UI access occurring inside the implementation must be
24  * properly synchronized using the techniques specified by the client's widget
25  * library.
26  * </p>
27  *
28  *
29  * @since 3.1
30  */

31 public final class OperationHistoryEvent {
32
33     /**
34      * ABOUT_TO_EXECUTE indicates that an operation is about to execute.
35      * Listeners should prepare for the execution as appropriate. Listeners will
36      * receive a DONE notification if the operation is successful, or an
37      * OPERATION_NOT_OK notification if the execution is cancelled or otherwise
38      * fails. This notification is only received for those operations executed
39      * by the operation history. Operations that are added to the history after
40      * execution do not trigger these notifications.
41      *
42      * If the operation successfully executes, clients will also receive a
43      * notification that it has been added to the history.
44      *
45      * (value is 1).
46      */

47
48     public static final int ABOUT_TO_EXECUTE = 1;
49
50     /**
51      * ABOUT_TO_REDO indicates that an operation is about to be redone.
52      * Listeners should prepare for the redo as appropriate. Listeners will
53      * receive a REDONE notification if the operation is successful, or an
54      * OPERATION_NOT_OK notification if the redo is cancelled or otherwise
55      * fails.
56      *
57      * (value is 2).
58      */

59     public static final int ABOUT_TO_REDO = 2;
60
61     /**
62      * ABOUT_TO_UNDO indicates that an operation is about to be undone.
63      * Listeners should prepare for the undo as appropriate. Listeners will
64      * receive an UNDONE notification if the operation is successful, or an
65      * OPERATION_NOT_OK notification if the undo is cancelled or otherwise
66      * fails.
67      *
68      * (value is 3).
69      */

70     public static final int ABOUT_TO_UNDO = 3;
71
72     /**
73      * DONE indicates that an operation has been executed. Listeners can take
74      * appropriate action, such as revealing any relevant state in the UI. This
75      * notification is only received for those operations executed by the
76      * operation history. Operations that are added to the history after
77      * execution do not trigger this notification.
78      *
79      * Clients will also receive a notification that the operation has been
80      * added to the history.
81      *
82      * (value is 4).
83      */

84     public static final int DONE = 4;
85
86     /**
87      * OPERATION_ADDED indicates that an operation was added to the history.
88      * Listeners can use this notification to add their undo context to a new
89      * operation as appropriate or otherwise record the operation.
90      *
91      * (value is 5).
92      */

93     public static final int OPERATION_ADDED = 5;
94
95     /**
96      * OPERATION_CHANGED indicates that an operation has changed in some way
97      * since it was added to the operations history.
98      *
99      * (value is 6).
100      */

101     public static final int OPERATION_CHANGED = 6;
102
103     /**
104      * OPERATION_NOT_OK indicates that an operation was attempted and not
105      * successful. Listeners typically use this when they have prepared for an
106      * execute, undo, or redo, and need to know that the operation did not
107      * successfully complete. For example, listeners that turn redraw off before
108      * an operation is undone would turn redraw on when the operation completes,
109      * or when this notification is received, since there will be no
110      * notification of the completion.
111      *
112      * (value is 7).
113      */

114     public static final int OPERATION_NOT_OK = 7;
115
116     /**
117      * OPERATION_REMOVED indicates an operation was removed from the history.
118      * Listeners typically remove any record of the operation that they may have
119      * kept in their own state. The operation has been disposed by the time
120      * listeners receive this notification.
121      *
122      * (value is 8).
123      */

124     public static final int OPERATION_REMOVED = 8;
125
126     /**
127      * REDONE indicates that an operation was redone. Listeners can take
128      * appropriate action, such as revealing any relevant state in the UI.
129      *
130      * (value is 9).
131      */

132     public static final int REDONE = 9;
133
134     /**
135      * UNDONE indicates that an operation was undone. Listeners can take
136      * appropriate action, such as revealing any relevant state in the UI.
137      *
138      * (value is 10).
139      */

140     public static final int UNDONE = 10;
141
142     private int code = 0;
143
144     private IOperationHistory history;
145
146     private IUndoableOperation operation;
147
148     /* @since 3.2 */
149     private IStatus status;
150
151     /**
152      * Construct an event for the specified operation history.
153      *
154      * @param code
155      * the event code to be used.
156      * @param history
157      * the history triggering the event.
158      * @param operation
159      * the operation involved in the event.
160      */

161     public OperationHistoryEvent(int code, IOperationHistory history,
162             IUndoableOperation operation) {
163         this(code, history, operation, null);
164     }
165
166     /**
167      * Construct an event for the specified operation history.
168      *
169      * @param code
170      * the event code to be used.
171      * @param history
172      * the history triggering the event.
173      * @param operation
174      * the operation involved in the event.
175      * @param status
176      * the status associated with the event, or null if no status is
177      * available.
178      *
179      * @since 3.2
180      */

181     public OperationHistoryEvent(int code, IOperationHistory history,
182             IUndoableOperation operation, IStatus status) {
183         if (history == null) {
184             throw new NullPointerException JavaDoc();
185         }
186         if (operation == null) {
187             throw new NullPointerException JavaDoc();
188         }
189         this.code = code;
190         this.history = history;
191         this.operation = operation;
192         this.status = status;
193     }
194
195     /**
196      * Return the type of event that is occurring.
197      *
198      * @return the type code indicating the type of event.
199      */

200     public int getEventType() {
201         return code;
202     }
203
204     /**
205      * Return the operation history that triggered this event.
206      *
207      * @return the operation history
208      */

209
210     public IOperationHistory getHistory() {
211         return history;
212     }
213
214     /**
215      * Return the operation associated with this event.
216      *
217      * @return the operation
218      */

219
220     public IUndoableOperation getOperation() {
221         return operation;
222     }
223
224     /**
225      * Return the status associated with this event.
226      *
227      * @return the status associated with this event. The status may be null.
228      *
229      * @since 3.2
230      */

231
232     public IStatus getStatus() {
233         return status;
234     }
235
236 }
237
Popular Tags