KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 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;
12
13 /**
14  * <p>
15  * An event indicating that the set of defined command identifiers has changed.
16  * </p>
17  *
18  * @since 3.1
19  * @see ICommandManagerListener#commandManagerChanged(CommandManagerEvent)
20  */

21 public final class CommandManagerEvent {
22
23     /**
24      * The bit used to represent whether the given category has become defined.
25      * If this bit is not set and there is no category id, then no category has
26      * become defined nor undefined. If this bit is not set and there is a
27      * category id, then the category has become undefined.
28      */

29     private static final int CHANGED_CATEGORY_DEFINED = 1;
30
31     /**
32      * The bit used to represent whether the given command has become defined.
33      * If this bit is not set and there is no command id, then no command has
34      * become defined nor undefined. If this bit is not set and there is a
35      * command id, then the command has become undefined.
36      */

37     private static final int CHANGED_COMMAND_DEFINED = 1 << 1;
38     
39     /**
40      * The bit used to represent whether the given command parameter type has
41      * become defined. If this bit is not set and there is no parameter type id,
42      * then no parameter type has become defined nor undefined. If this bit is
43      * not set and there is a parameter type id, then the parameter type has
44      * become undefined.
45      *
46      * @since 3.2
47      */

48     private static final int CHANGED_PARAMETER_TYPE_DEFINED = 1 << 2;
49
50     /**
51      * The category identifier that was added or removed from the list of
52      * defined category identifiers. This value is <code>null</code> if the
53      * list of defined category identifiers did not change.
54      */

55     private final String JavaDoc categoryId;
56
57     /**
58      * A collection of bits representing whether certain values have changed. A
59      * bit is set (i.e., <code>1</code>) if the corresponding property has
60      * changed.
61      */

62     private final int changedValues;
63
64     /**
65      * The command identifier that was added or removed from the list of defined
66      * command identifiers. This value is <code>null</code> if the list of
67      * defined command identifiers did not change.
68      */

69     private final String JavaDoc commandId;
70     
71     /**
72      * The command parameter type identifier that was added or removed from the
73      * list of defined parameter type identifiers. This value is
74      * <code>null</code> if the list of defined parameter type identifiers did
75      * not change.
76      *
77      * @since 3.2
78      */

79     private final String JavaDoc parameterTypeId;
80
81     /**
82      * The command manager that has changed.
83      */

84     private final CommandManager commandManager;
85
86     /**
87      * Creates a new <code>CommandManagerEvent</code> instance to describe
88      * changes to commands and/or categories.
89      *
90      * @param commandManager
91      * the instance of the interface that changed; must not be
92      * <code>null</code>.
93      * @param commandId
94      * The command identifier that was added or removed; must not be
95      * <code>null</code> if commandIdChanged is <code>true</code>.
96      * @param commandIdAdded
97      * Whether the command identifier became defined (otherwise, it
98      * became undefined).
99      * @param commandIdChanged
100      * Whether the list of defined command identifiers has changed.
101      * @param categoryId
102      * The category identifier that was added or removed; must not be
103      * <code>null</code> if categoryIdChanged is <code>true</code>.
104      * @param categoryIdAdded
105      * Whether the category identifier became defined (otherwise, it
106      * became undefined).
107      * @param categoryIdChanged
108      * Whether the list of defined category identifiers has changed.
109      */

110     public CommandManagerEvent(final CommandManager commandManager,
111             final String JavaDoc commandId, final boolean commandIdAdded,
112             final boolean commandIdChanged, final String JavaDoc categoryId,
113             final boolean categoryIdAdded, final boolean categoryIdChanged) {
114         if (commandManager == null) {
115             throw new NullPointerException JavaDoc(
116                     "An event must refer to its command manager"); //$NON-NLS-1$
117
}
118
119         if (commandIdChanged && (commandId == null)) {
120             throw new NullPointerException JavaDoc(
121                     "If the list of defined commands changed, then the added/removed command must be mentioned"); //$NON-NLS-1$
122
}
123
124         if (categoryIdChanged && (categoryId == null)) {
125             throw new NullPointerException JavaDoc(
126                     "If the list of defined categories changed, then the added/removed category must be mentioned"); //$NON-NLS-1$
127
}
128
129         this.commandManager = commandManager;
130         this.commandId = commandId;
131         this.categoryId = categoryId;
132         
133         // this constructor only works for changes to commands and categories
134
this.parameterTypeId = null;
135
136         int changedValues = 0;
137         if (categoryIdChanged && categoryIdAdded) {
138             changedValues |= CHANGED_CATEGORY_DEFINED;
139         }
140         if (commandIdChanged && commandIdAdded) {
141             changedValues |= CHANGED_COMMAND_DEFINED;
142         }
143         this.changedValues = changedValues;
144     }
145     
146     /**
147      * Creates a new <code>CommandManagerEvent</code> instance to describe
148      * changes to command parameter types.
149      *
150      * @param commandManager
151      * the instance of the interface that changed; must not be
152      * <code>null</code>.
153      * @param parameterTypeId
154      * The command parameter type identifier that was added or
155      * removed; must not be <code>null</code> if
156      * parameterTypeIdChanged is <code>true</code>.
157      * @param parameterTypeIdAdded
158      * Whether the parameter type identifier became defined
159      * (otherwise, it became undefined).
160      * @param parameterTypeIdChanged
161      * Whether the list of defined parameter type identifiers has
162      * changed.
163      *
164      * @since 3.2
165      */

166     public CommandManagerEvent(final CommandManager commandManager,
167             final String JavaDoc parameterTypeId, final boolean parameterTypeIdAdded,
168             final boolean parameterTypeIdChanged) {
169
170         if (commandManager == null) {
171             throw new NullPointerException JavaDoc(
172                     "An event must refer to its command manager"); //$NON-NLS-1$
173
}
174
175         if (parameterTypeIdChanged && (parameterTypeId == null)) {
176             throw new NullPointerException JavaDoc(
177                     "If the list of defined command parameter types changed, then the added/removed parameter type must be mentioned"); //$NON-NLS-1$
178
}
179
180         this.commandManager = commandManager;
181         this.commandId = null;
182         this.categoryId = null;
183
184         this.parameterTypeId = parameterTypeId;
185
186         int changedValues = 0;
187         if (parameterTypeIdChanged && parameterTypeIdAdded) {
188             changedValues |= CHANGED_PARAMETER_TYPE_DEFINED;
189         }
190
191         this.changedValues = changedValues;
192     }
193
194     /**
195      * Returns the category identifier that was added or removed.
196      *
197      * @return The category identifier that was added or removed; may be
198      * <code>null</code>.
199      */

200     public final String JavaDoc getCategoryId() {
201         return categoryId;
202     }
203
204     /**
205      * Returns the command identifier that was added or removed.
206      *
207      * @return The command identifier that was added or removed; may be
208      * <code>null</code>.
209      */

210     public final String JavaDoc getCommandId() {
211         return commandId;
212     }
213
214     /**
215      * Returns the instance of the interface that changed.
216      *
217      * @return the instance of the interface that changed. Guaranteed not to be
218      * <code>null</code>.
219      */

220     public final CommandManager getCommandManager() {
221         return commandManager;
222     }
223     
224     /**
225      * Returns the command parameter type identifier that was added or removed.
226      *
227      * @return The command parameter type identifier that was added or removed;
228      * may be <code>null</code>.
229      *
230      * @since 3.2
231      */

232     public final String JavaDoc getParameterTypeId() {
233         return parameterTypeId;
234     }
235
236     /**
237      * Returns whether the list of defined category identifiers has changed.
238      *
239      * @return <code>true</code> if the list of category identifiers has
240      * changed; <code>false</code> otherwise.
241      */

242     public final boolean isCategoryChanged() {
243         return (categoryId != null);
244     }
245
246     /**
247      * Returns whether the category identifier became defined. Otherwise, the
248      * category identifier became undefined.
249      *
250      * @return <code>true</code> if the category identifier became defined;
251      * <code>false</code> if the category identifier became undefined.
252      */

253     public final boolean isCategoryDefined() {
254         return (((changedValues & CHANGED_CATEGORY_DEFINED) != 0) && (categoryId != null));
255     }
256
257     /**
258      * Returns whether the list of defined command identifiers has changed.
259      *
260      * @return <code>true</code> if the list of command identifiers has
261      * changed; <code>false</code> otherwise.
262      */

263     public final boolean isCommandChanged() {
264         return (commandId != null);
265     }
266
267     /**
268      * Returns whether the command identifier became defined. Otherwise, the
269      * command identifier became undefined.
270      *
271      * @return <code>true</code> if the command identifier became defined;
272      * <code>false</code> if the command identifier became undefined.
273      */

274     public final boolean isCommandDefined() {
275         return (((changedValues & CHANGED_COMMAND_DEFINED) != 0) && (commandId != null));
276     }
277     
278     /**
279      * Returns whether the list of defined command parameter type identifiers
280      * has changed.
281      *
282      * @return <code>true</code> if the list of command parameter type
283      * identifiers has changed; <code>false</code> otherwise.
284      *
285      * @since 3.2
286      */

287     public final boolean isParameterTypeChanged() {
288         return (parameterTypeId != null);
289     }
290     
291     /**
292      * Returns whether the command parameter type identifier became defined.
293      * Otherwise, the command parameter type identifier became undefined.
294      *
295      * @return <code>true</code> if the command parameter type identifier
296      * became defined; <code>false</code> if the command parameter
297      * type identifier became undefined.
298      *
299      * @since 3.2
300      */

301     public final boolean isParameterTypeDefined() {
302         return (((changedValues & CHANGED_PARAMETER_TYPE_DEFINED) != 0) && (parameterTypeId != null));
303     }
304 }
305
Popular Tags