KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > commands > CommandEvent


1 /*******************************************************************************
2  * Copyright (c) 2004, 2007 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;
12
13 import org.eclipse.core.commands.common.AbstractNamedHandleEvent;
14
15 /**
16  * An instance of this class describes changes to an instance of
17  * <code>Command</code>.
18  * <p>
19  * This class is not intended to be extended by clients.
20  * </p>
21  *
22  * @since 3.1
23  * @see ICommandListener#commandChanged(CommandEvent)
24  */

25 public final class CommandEvent extends AbstractNamedHandleEvent {
26
27     /**
28      * The bit used to represent whether the command has changed its category.
29      */

30     private static final int CHANGED_CATEGORY = LAST_USED_BIT << 1;
31
32     /**
33      * The bit used to represent whether the command has changed its handler.
34      */

35     private static final int CHANGED_HANDLED = LAST_USED_BIT << 2;
36
37     /**
38      * The bit used to represent whether the command has changed its parameters.
39      */

40     private static final int CHANGED_PARAMETERS = LAST_USED_BIT << 3;
41
42     /**
43      * The bit used to represent whether the command has changed its return
44      * type.
45      *
46      * @since 3.2
47      */

48     private static final int CHANGED_RETURN_TYPE = LAST_USED_BIT << 4;
49
50     /**
51      * The bit used to represent whether the command has changed its help
52      * context identifier.
53      *
54      * @since 3.2
55      */

56     private static final int CHANGED_HELP_CONTEXT_ID = LAST_USED_BIT << 5;
57
58     /**
59      * The bit used to represent whether this commands active handler has
60      * changed its enablement state.
61      *
62      * @since 3.3
63      */

64     private static final int CHANGED_ENABLED = LAST_USED_BIT << 6;
65
66     /**
67      * The command that has changed; this value is never <code>null</code>.
68      */

69     private final Command command;
70
71     /**
72      * Creates a new instance of this class.
73      *
74      * @param command
75      * the instance of the interface that changed.
76      * @param categoryChanged
77      * <code>true</code>, iff the category property changed.
78      * @param definedChanged
79      * <code>true</code>, iff the defined property changed.
80      * @param descriptionChanged
81      * <code>true</code>, iff the description property changed.
82      * @param handledChanged
83      * <code>true</code>, iff the handled property changed.
84      * @param nameChanged
85      * <code>true</code>, iff the name property changed.
86      * @param parametersChanged
87      * <code>true</code> if the parameters have changed;
88      * <code>false</code> otherwise.
89      */

90     public CommandEvent(final Command command, final boolean categoryChanged,
91             final boolean definedChanged, final boolean descriptionChanged,
92             final boolean handledChanged, final boolean nameChanged,
93             final boolean parametersChanged) {
94         this(command, categoryChanged, definedChanged, descriptionChanged,
95                 handledChanged, nameChanged, parametersChanged, false);
96     }
97
98     /**
99      * Creates a new instance of this class.
100      *
101      * @param command
102      * the instance of the interface that changed.
103      * @param categoryChanged
104      * <code>true</code>, iff the category property changed.
105      * @param definedChanged
106      * <code>true</code>, iff the defined property changed.
107      * @param descriptionChanged
108      * <code>true</code>, iff the description property changed.
109      * @param handledChanged
110      * <code>true</code>, iff the handled property changed.
111      * @param nameChanged
112      * <code>true</code>, iff the name property changed.
113      * @param parametersChanged
114      * <code>true</code> if the parameters have changed;
115      * <code>false</code> otherwise.
116      * @param returnTypeChanged
117      * <code>true</code> iff the return type property changed;
118      * <code>false</code> otherwise.
119      * @since 3.2
120      */

121     public CommandEvent(final Command command, final boolean categoryChanged,
122             final boolean definedChanged, final boolean descriptionChanged,
123             final boolean handledChanged, final boolean nameChanged,
124             final boolean parametersChanged, final boolean returnTypeChanged) {
125         this(command, categoryChanged, definedChanged, descriptionChanged,
126                 handledChanged, nameChanged, parametersChanged,
127                 returnTypeChanged, false);
128     }
129
130     /**
131      * Creates a new instance of this class.
132      *
133      * @param command
134      * the instance of the interface that changed.
135      * @param categoryChanged
136      * <code>true</code>, iff the category property changed.
137      * @param definedChanged
138      * <code>true</code>, iff the defined property changed.
139      * @param descriptionChanged
140      * <code>true</code>, iff the description property changed.
141      * @param handledChanged
142      * <code>true</code>, iff the handled property changed.
143      * @param nameChanged
144      * <code>true</code>, iff the name property changed.
145      * @param parametersChanged
146      * <code>true</code> if the parameters have changed;
147      * <code>false</code> otherwise.
148      * @param returnTypeChanged
149      * <code>true</code> iff the return type property changed;
150      * <code>false</code> otherwise.
151      * @param helpContextIdChanged
152      * <code>true</code> iff the help context identifier changed;
153      * <code>false</code> otherwise.
154      * @since 3.2
155      */

156     public CommandEvent(final Command command, final boolean categoryChanged,
157             final boolean definedChanged, final boolean descriptionChanged,
158             final boolean handledChanged, final boolean nameChanged,
159             final boolean parametersChanged, final boolean returnTypeChanged,
160             final boolean helpContextIdChanged) {
161         this(command, categoryChanged, definedChanged, descriptionChanged,
162                 handledChanged, nameChanged, parametersChanged,
163                 returnTypeChanged, helpContextIdChanged, false);
164     }
165
166     /**
167      * Creates a new instance of this class.
168      *
169      * @param command
170      * the instance of the interface that changed.
171      * @param categoryChanged
172      * <code>true</code>, iff the category property changed.
173      * @param definedChanged
174      * <code>true</code>, iff the defined property changed.
175      * @param descriptionChanged
176      * <code>true</code>, iff the description property changed.
177      * @param handledChanged
178      * <code>true</code>, iff the handled property changed.
179      * @param nameChanged
180      * <code>true</code>, iff the name property changed.
181      * @param parametersChanged
182      * <code>true</code> if the parameters have changed;
183      * <code>false</code> otherwise.
184      * @param returnTypeChanged
185      * <code>true</code> iff the return type property changed;
186      * <code>false</code> otherwise.
187      * @param helpContextIdChanged
188      * <code>true</code> iff the help context identifier changed;
189      * <code>false</code> otherwise.
190      * @param enabledChanged
191      * <code>true</code> iff the comand enablement changed;
192      * <code>false</code> otherwise.
193      * @since 3.3
194      */

195     public CommandEvent(final Command command, final boolean categoryChanged,
196             final boolean definedChanged, final boolean descriptionChanged,
197             final boolean handledChanged, final boolean nameChanged,
198             final boolean parametersChanged, final boolean returnTypeChanged,
199             final boolean helpContextIdChanged, final boolean enabledChanged) {
200         super(definedChanged, descriptionChanged, nameChanged);
201
202         if (command == null) {
203             throw new NullPointerException JavaDoc();
204         }
205         this.command = command;
206
207         if (categoryChanged) {
208             changedValues |= CHANGED_CATEGORY;
209         }
210         if (handledChanged) {
211             changedValues |= CHANGED_HANDLED;
212         }
213         if (parametersChanged) {
214             changedValues |= CHANGED_PARAMETERS;
215         }
216         if (returnTypeChanged) {
217             changedValues |= CHANGED_RETURN_TYPE;
218         }
219         if (helpContextIdChanged) {
220             changedValues |= CHANGED_HELP_CONTEXT_ID;
221         }
222         if (enabledChanged) {
223             changedValues |= CHANGED_ENABLED;
224         }
225     }
226
227     /**
228      * Returns the instance of the interface that changed.
229      *
230      * @return the instance of the interface that changed. Guaranteed not to be
231      * <code>null</code>.
232      */

233     public final Command getCommand() {
234         return command;
235     }
236
237     /**
238      * Returns whether or not the category property changed.
239      *
240      * @return <code>true</code>, iff the category property changed.
241      */

242     public final boolean isCategoryChanged() {
243         return ((changedValues & CHANGED_CATEGORY) != 0);
244     }
245
246     /**
247      * Returns whether or not the handled property changed.
248      *
249      * @return <code>true</code>, iff the handled property changed.
250      */

251     public final boolean isHandledChanged() {
252         return ((changedValues & CHANGED_HANDLED) != 0);
253     }
254
255     /**
256      * Returns whether or not the help context identifier changed.
257      *
258      * @return <code>true</code>, iff the help context identifier changed.
259      * @since 3.2
260      */

261     public final boolean isHelpContextIdChanged() {
262         return ((changedValues & CHANGED_HELP_CONTEXT_ID) != 0);
263     }
264
265     /**
266      * Returns whether or not the parameters have changed.
267      *
268      * @return <code>true</code>, iff the parameters property changed.
269      */

270     public final boolean isParametersChanged() {
271         return ((changedValues & CHANGED_PARAMETERS) != 0);
272     }
273
274     /**
275      * Returns whether or not the return type property changed.
276      *
277      * @return <code>true</code>, iff the return type property changed.
278      * @since 3.2
279      */

280     public final boolean isReturnTypeChanged() {
281         return ((changedValues & CHANGED_RETURN_TYPE) != 0);
282     }
283
284     /**
285      * Return whether the enable property changed.
286      *
287      * @return <code>true</code> iff the comand enablement changed
288      * @since 3.3
289      */

290     public final boolean isEnabledChanged() {
291         return ((changedValues & CHANGED_ENABLED) != 0);
292     }
293 }
294
Popular Tags