comparison org.eclipse.core.commands/src/org/eclipse/core/commands/CommandManagerEvent.d @ 12:bc29606a740c

Added dwt-addons in original directory structure of eclipse.org
author Frank Benoit <benoit@tionex.de>
date Sat, 14 Mar 2009 18:23:29 +0100
parents
children
comparison
equal deleted inserted replaced
11:43904fec5dca 12:bc29606a740c
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 * Port to the D programming language:
11 * Frank Benoit <benoit@tionex.de>
12 *******************************************************************************/
13 module org.eclipse.core.commands.CommandManagerEvent;
14
15 import org.eclipse.core.commands.CommandManager;
16
17 import java.lang.all;
18
19 /**
20 * <p>
21 * An event indicating that the set of defined command identifiers has changed.
22 * </p>
23 *
24 * @since 3.1
25 * @see ICommandManagerListener#commandManagerChanged(CommandManagerEvent)
26 */
27 public final class CommandManagerEvent {
28
29 /**
30 * The bit used to represent whether the given category has become defined.
31 * If this bit is not set and there is no category id, then no category has
32 * become defined nor undefined. If this bit is not set and there is a
33 * category id, then the category has become undefined.
34 */
35 private static const int CHANGED_CATEGORY_DEFINED = 1;
36
37 /**
38 * The bit used to represent whether the given command has become defined.
39 * If this bit is not set and there is no command id, then no command has
40 * become defined nor undefined. If this bit is not set and there is a
41 * command id, then the command has become undefined.
42 */
43 private static const int CHANGED_COMMAND_DEFINED = 1 << 1;
44
45 /**
46 * The bit used to represent whether the given command parameter type has
47 * become defined. If this bit is not set and there is no parameter type id,
48 * then no parameter type has become defined nor undefined. If this bit is
49 * not set and there is a parameter type id, then the parameter type has
50 * become undefined.
51 *
52 * @since 3.2
53 */
54 private static const int CHANGED_PARAMETER_TYPE_DEFINED = 1 << 2;
55
56 /**
57 * The category identifier that was added or removed from the list of
58 * defined category identifiers. This value is <code>null</code> if the
59 * list of defined category identifiers did not change.
60 */
61 private const String categoryId;
62
63 /**
64 * A collection of bits representing whether certain values have changed. A
65 * bit is set (i.e., <code>1</code>) if the corresponding property has
66 * changed.
67 */
68 private const int changedValues;
69
70 /**
71 * The command identifier that was added or removed from the list of defined
72 * command identifiers. This value is <code>null</code> if the list of
73 * defined command identifiers did not change.
74 */
75 private const String commandId;
76
77 /**
78 * The command parameter type identifier that was added or removed from the
79 * list of defined parameter type identifiers. This value is
80 * <code>null</code> if the list of defined parameter type identifiers did
81 * not change.
82 *
83 * @since 3.2
84 */
85 private const String parameterTypeId;
86
87 /**
88 * The command manager that has changed.
89 */
90 private const CommandManager commandManager;
91
92 /**
93 * Creates a new <code>CommandManagerEvent</code> instance to describe
94 * changes to commands and/or categories.
95 *
96 * @param commandManager
97 * the instance of the interface that changed; must not be
98 * <code>null</code>.
99 * @param commandId
100 * The command identifier that was added or removed; must not be
101 * <code>null</code> if commandIdChanged is <code>true</code>.
102 * @param commandIdAdded
103 * Whether the command identifier became defined (otherwise, it
104 * became undefined).
105 * @param commandIdChanged
106 * Whether the list of defined command identifiers has changed.
107 * @param categoryId
108 * The category identifier that was added or removed; must not be
109 * <code>null</code> if categoryIdChanged is <code>true</code>.
110 * @param categoryIdAdded
111 * Whether the category identifier became defined (otherwise, it
112 * became undefined).
113 * @param categoryIdChanged
114 * Whether the list of defined category identifiers has changed.
115 */
116 public this(CommandManager commandManager,
117 String commandId, bool commandIdAdded,
118 bool commandIdChanged, String categoryId,
119 bool categoryIdAdded, bool categoryIdChanged) {
120 if (commandManager is null) {
121 throw new NullPointerException(
122 "An event must refer to its command manager"); //$NON-NLS-1$
123 }
124
125 if (commandIdChanged && (commandId is null)) {
126 throw new NullPointerException(
127 "If the list of defined commands changed, then the added/removed command must be mentioned"); //$NON-NLS-1$
128 }
129
130 if (categoryIdChanged && (categoryId is null)) {
131 throw new NullPointerException(
132 "If the list of defined categories changed, then the added/removed category must be mentioned"); //$NON-NLS-1$
133 }
134
135 this.commandManager = commandManager;
136 this.commandId = commandId;
137 this.categoryId = categoryId;
138
139 // this constructor only works for changes to commands and categories
140 this.parameterTypeId = null;
141
142 int changedValues = 0;
143 if (categoryIdChanged && categoryIdAdded) {
144 changedValues |= CHANGED_CATEGORY_DEFINED;
145 }
146 if (commandIdChanged && commandIdAdded) {
147 changedValues |= CHANGED_COMMAND_DEFINED;
148 }
149 this.changedValues = changedValues;
150 }
151
152 /**
153 * Creates a new <code>CommandManagerEvent</code> instance to describe
154 * changes to command parameter types.
155 *
156 * @param commandManager
157 * the instance of the interface that changed; must not be
158 * <code>null</code>.
159 * @param parameterTypeId
160 * The command parameter type identifier that was added or
161 * removed; must not be <code>null</code> if
162 * parameterTypeIdChanged is <code>true</code>.
163 * @param parameterTypeIdAdded
164 * Whether the parameter type identifier became defined
165 * (otherwise, it became undefined).
166 * @param parameterTypeIdChanged
167 * Whether the list of defined parameter type identifiers has
168 * changed.
169 *
170 * @since 3.2
171 */
172 public this(CommandManager commandManager,
173 String parameterTypeId, bool parameterTypeIdAdded,
174 bool parameterTypeIdChanged) {
175
176 if (commandManager is null) {
177 throw new NullPointerException(
178 "An event must refer to its command manager"); //$NON-NLS-1$
179 }
180
181 if (parameterTypeIdChanged && (parameterTypeId is null)) {
182 throw new NullPointerException(
183 "If the list of defined command parameter types changed, then the added/removed parameter type must be mentioned"); //$NON-NLS-1$
184 }
185
186 this.commandManager = commandManager;
187 this.commandId = null;
188 this.categoryId = null;
189
190 this.parameterTypeId = parameterTypeId;
191
192 int changedValues = 0;
193 if (parameterTypeIdChanged && parameterTypeIdAdded) {
194 changedValues |= CHANGED_PARAMETER_TYPE_DEFINED;
195 }
196
197 this.changedValues = changedValues;
198 }
199
200 /**
201 * Returns the category identifier that was added or removed.
202 *
203 * @return The category identifier that was added or removed; may be
204 * <code>null</code>.
205 */
206 public final String getCategoryId() {
207 return categoryId;
208 }
209
210 /**
211 * Returns the command identifier that was added or removed.
212 *
213 * @return The command identifier that was added or removed; may be
214 * <code>null</code>.
215 */
216 public final String getCommandId() {
217 return commandId;
218 }
219
220 /**
221 * Returns the instance of the interface that changed.
222 *
223 * @return the instance of the interface that changed. Guaranteed not to be
224 * <code>null</code>.
225 */
226 public final CommandManager getCommandManager() {
227 return commandManager;
228 }
229
230 /**
231 * Returns the command parameter type identifier that was added or removed.
232 *
233 * @return The command parameter type identifier that was added or removed;
234 * may be <code>null</code>.
235 *
236 * @since 3.2
237 */
238 public final String getParameterTypeId() {
239 return parameterTypeId;
240 }
241
242 /**
243 * Returns whether the list of defined category identifiers has changed.
244 *
245 * @return <code>true</code> if the list of category identifiers has
246 * changed; <code>false</code> otherwise.
247 */
248 public final bool isCategoryChanged() {
249 return (categoryId !is null);
250 }
251
252 /**
253 * Returns whether the category identifier became defined. Otherwise, the
254 * category identifier became undefined.
255 *
256 * @return <code>true</code> if the category identifier became defined;
257 * <code>false</code> if the category identifier became undefined.
258 */
259 public final bool isCategoryDefined() {
260 return (((changedValues & CHANGED_CATEGORY_DEFINED) !is 0) && (categoryId !is null));
261 }
262
263 /**
264 * Returns whether the list of defined command identifiers has changed.
265 *
266 * @return <code>true</code> if the list of command identifiers has
267 * changed; <code>false</code> otherwise.
268 */
269 public final bool isCommandChanged() {
270 return (commandId !is null);
271 }
272
273 /**
274 * Returns whether the command identifier became defined. Otherwise, the
275 * command identifier became undefined.
276 *
277 * @return <code>true</code> if the command identifier became defined;
278 * <code>false</code> if the command identifier became undefined.
279 */
280 public final bool isCommandDefined() {
281 return (((changedValues & CHANGED_COMMAND_DEFINED) !is 0) && (commandId !is null));
282 }
283
284 /**
285 * Returns whether the list of defined command parameter type identifiers
286 * has changed.
287 *
288 * @return <code>true</code> if the list of command parameter type
289 * identifiers has changed; <code>false</code> otherwise.
290 *
291 * @since 3.2
292 */
293 public final bool isParameterTypeChanged() {
294 return (parameterTypeId !is null);
295 }
296
297 /**
298 * Returns whether the command parameter type identifier became defined.
299 * Otherwise, the command parameter type identifier became undefined.
300 *
301 * @return <code>true</code> if the command parameter type identifier
302 * became defined; <code>false</code> if the command parameter
303 * type identifier became undefined.
304 *
305 * @since 3.2
306 */
307 public final bool isParameterTypeDefined() {
308 return (((changedValues & CHANGED_PARAMETER_TYPE_DEFINED) !is 0) && (parameterTypeId !is null));
309 }
310 }