KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > menus > MenuManagerEvent


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.ui.internal.menus;
12
13 import org.eclipse.core.commands.common.AbstractBitSetEvent;
14
15 /**
16  * <p>
17  * An event indicating that the set of defined menu element identifiers has
18  * changed.
19  * </p>
20  * <p>
21  * <strong>PROVISIONAL</strong>. This class or interface has been added as
22  * part of a work in progress. There is a guarantee neither that this API will
23  * work nor that it will remain the same. Please do not use this API without
24  * consulting with the Platform/UI team.
25  * </p>
26  * <p>
27  * This class will eventually exist in <code>org.eclipse.jface.menus</code>.
28  * </p>
29  *
30  * @since 3.2
31  * @see IMenuManagerListener#menuManagerChanged(MenuManagerEvent)
32  */

33 public final class MenuManagerEvent extends AbstractBitSetEvent {
34
35     /**
36      * The bit used to represent whether the given action set has become
37      * defined. If this bit is not set and there is no action set id, then no
38      * action set has become defined nor undefined. If this bit is not set and
39      * there is a action set id, then the action set has become undefined.
40      */

41     private static final int CHANGED_ACTION_SET_DEFINED = 1;
42
43     /**
44      * The bit used to represent whether the given group has become defined. If
45      * this bit is not set and there is no group id, then no group has become
46      * defined nor undefined. If this bit is not set and there is a group id,
47      * then the group has become undefined.
48      */

49     private static final int CHANGED_GROUP_DEFINED = 1 << 1;
50
51     /**
52      * The bit used to represent whether the given item has become defined. If
53      * this bit is not set and there is no item id, then no item has become
54      * defined nor undefined. If this bit is not set and there is a item id,
55      * then the item has become undefined.
56      */

57     private static final int CHANGED_ITEM_DEFINED = 1 << 2;
58
59     /**
60      * The bit used to represent whether the given menu has become defined. If
61      * this bit is not set and there is no menu id, then no menu has become
62      * defined nor undefined. If this bit is not set and there is a menu id,
63      * then the menu has become undefined.
64      */

65     private static final int CHANGED_MENU_DEFINED = 1 << 3;
66
67     /**
68      * The bit used to represent whether the given widget has become defined. If
69      * this bit is not set and there is no widget id, then no widget has become
70      * defined nor undefined. If this bit is not set and there is a widget id,
71      * then the widget has become undefined.
72      */

73     private static final int CHANGED_WIDGET_DEFINED = 1 << 4;
74
75     /**
76      * The action set identifier that was added or removed from the list of
77      * defined action set identifiers. This value is <code>null</code> if the
78      * list of defined action set identifiers did not change.
79      */

80     private final String JavaDoc actionSetId;
81
82     /**
83      * The group identifier that was added or removed from the list of defined
84      * group identifiers. This value is <code>null</code> if the list of
85      * defined group identifiers did not change.
86      */

87     private final String JavaDoc groupId;
88
89     /**
90      * The item identifier that was added or removed from the list of defined
91      * item identifiers. This value is <code>null</code> if the list of
92      * defined item identifiers did not change.
93      */

94     private final String JavaDoc itemId;
95
96     /**
97      * The menu identifier that was added or removed from the list of defined
98      * menu identifiers. This value is <code>null</code> if the list of
99      * defined menu identifiers did not change.
100      */

101     private final String JavaDoc menuId;
102
103     /**
104      * The menu manager that has changed.
105      */

106     private final SMenuManager menuManager;
107
108     /**
109      * The widget identifier that was added or removed from the list of defined
110      * widget identifiers. This value is <code>null</code> if the list of
111      * defined widget identifiers did not change.
112      */

113     private final String JavaDoc widgetId;
114
115     /**
116      * Creates a new instance of this class.
117      *
118      * @param menuManager
119      * the instance of the manager that changed; must not be
120      * <code>null</code>.
121      * @param groupId
122      * The group identifier that was added or removed;
123      * <code>null</code> if a group did not change.
124      * @param groupIdAdded
125      * Whether the group identifier became defined (otherwise, it
126      * became undefined).
127      * @param itemId
128      * The item identifier that was added or removed;
129      * <code>null</code> if a item did not change.
130      * @param itemIdAdded
131      * Whether the item identifier became defined (otherwise, it
132      * became undefined).
133      * @param menuId
134      * The menu identifier that was added or removed;
135      * <code>null</code> if a menu did not change.
136      * @param menuIdAdded
137      * Whether the menu identifier became defined (otherwise, it
138      * became undefined).
139      * @param widgetId
140      * The widget identifier that was added or removed;
141      * <code>null</code> if a widget did not change.
142      * @param widgetIdAdded
143      * Whether the widget identifier became defined (otherwise, it
144      * became undefined).
145      * @param actionSetId
146      * The action set identifier that was added or removed;
147      * <code>null</code> if an action set did not change.
148      * @param actionSetIdAdded
149      * Whether the action set identifier became defined (otherwise,
150      * it became undefined).
151      */

152     MenuManagerEvent(final SMenuManager menuManager, final String JavaDoc groupId,
153             final boolean groupIdAdded, final String JavaDoc itemId,
154             final boolean itemIdAdded, final String JavaDoc menuId,
155             final boolean menuIdAdded, final String JavaDoc widgetId,
156             final boolean widgetIdAdded, final String JavaDoc actionSetId,
157             final boolean actionSetIdAdded) {
158         if (menuManager == null) {
159             throw new NullPointerException JavaDoc(
160                     "An event must refer to its menu manager"); //$NON-NLS-1$
161
}
162
163         this.menuManager = menuManager;
164         this.groupId = groupId;
165         this.itemId = itemId;
166         this.menuId = menuId;
167         this.widgetId = widgetId;
168         this.actionSetId = actionSetId;
169
170         if (groupIdAdded) {
171             changedValues |= CHANGED_GROUP_DEFINED;
172         }
173         if (itemIdAdded) {
174             changedValues |= CHANGED_ITEM_DEFINED;
175         }
176         if (menuIdAdded) {
177             changedValues |= CHANGED_MENU_DEFINED;
178         }
179         if (widgetIdAdded) {
180             changedValues |= CHANGED_WIDGET_DEFINED;
181         }
182         if (actionSetIdAdded) {
183             changedValues |= CHANGED_ACTION_SET_DEFINED;
184         }
185     }
186
187     /**
188      * Returns the action set identifier that was added or removed.
189      *
190      * @return The action set identifier that was added or removed; may be
191      * <code>null</code> if no action set changed.
192      */

193     public final String JavaDoc getActionSetId() {
194         return groupId;
195     }
196
197     /**
198      * Returns the group identifier that was added or removed.
199      *
200      * @return The group identifier that was added or removed; may be
201      * <code>null</code> if no group changed.
202      */

203     public final String JavaDoc getGroupId() {
204         return groupId;
205     }
206
207     /**
208      * Returns the item identifier that was added or removed.
209      *
210      * @return The item identifier that was added or removed; may be
211      * <code>null</code> if no item changed.
212      */

213     public final String JavaDoc getItemId() {
214         return itemId;
215     }
216
217     /**
218      * Returns the menu identifier that was added or removed.
219      *
220      * @return The menu identifier that was added or removed; may be
221      * <code>null</code> if no menu changed.
222      */

223     public final String JavaDoc getMenuId() {
224         return menuId;
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 SMenuManager getMenuManager() {
234         return menuManager;
235     }
236
237     /**
238      * Returns the widget identifier that was added or removed.
239      *
240      * @return The widget identifier that was added or removed; may be
241      * <code>null</code> if no widget changed.
242      */

243     public final String JavaDoc getWidgetId() {
244         return widgetId;
245     }
246
247     /**
248      * Returns whether the list of defined action set identifiers has changed.
249      *
250      * @return <code>true</code> if the list of action set identifiers has
251      * changed; <code>false</code> otherwise.
252      */

253     public final boolean isActionSetChanged() {
254         return (actionSetId != null);
255     }
256
257     /**
258      * Returns whether the action set identifier became defined. Otherwise, the
259      * action set identifier became undefined.
260      *
261      * @return <code>true</code> if the action set identifier became defined;
262      * <code>false</code> if the action set identifier became
263      * undefined.
264      */

265     public final boolean isActionSetDefined() {
266         return (((changedValues & CHANGED_ACTION_SET_DEFINED) != 0) && (actionSetId != null));
267     }
268
269     /**
270      * Returns whether the list of defined group identifiers has changed.
271      *
272      * @return <code>true</code> if the list of group identifiers has changed;
273      * <code>false</code> otherwise.
274      */

275     public final boolean isGroupChanged() {
276         return (groupId != null);
277     }
278
279     /**
280      * Returns whether the group identifier became defined. Otherwise, the group
281      * identifier became undefined.
282      *
283      * @return <code>true</code> if the group identifier became defined;
284      * <code>false</code> if the group identifier became undefined.
285      */

286     public final boolean isGroupDefined() {
287         return (((changedValues & CHANGED_GROUP_DEFINED) != 0) && (groupId != null));
288     }
289
290     /**
291      * Returns whether the list of defined item identifiers has changed.
292      *
293      * @return <code>true</code> if the list of item identifiers has changed;
294      * <code>false</code> otherwise.
295      */

296     public final boolean isItemChanged() {
297         return (itemId != null);
298     }
299
300     /**
301      * Returns whether the item identifier became defined. Otherwise, the item
302      * identifier became undefined.
303      *
304      * @return <code>true</code> if the item identifier became defined;
305      * <code>false</code> if the item identifier became undefined.
306      */

307     public final boolean isItemDefined() {
308         return (((changedValues & CHANGED_ITEM_DEFINED) != 0) && (itemId != null));
309     }
310
311     /**
312      * Returns whether the list of defined menu identifiers has changed.
313      *
314      * @return <code>true</code> if the list of menu identifiers has changed;
315      * <code>false</code> otherwise.
316      */

317     public final boolean isMenuChanged() {
318         return (menuId != null);
319     }
320
321     /**
322      * Returns whether the menu identifier became defined. Otherwise, the menu
323      * identifier became undefined.
324      *
325      * @return <code>true</code> if the menu identifier became defined;
326      * <code>false</code> if the menu identifier became undefined.
327      */

328     public final boolean isMenuDefined() {
329         return (((changedValues & CHANGED_MENU_DEFINED) != 0) && (menuId != null));
330     }
331
332     /**
333      * Returns whether the list of defined widget identifiers has changed.
334      *
335      * @return <code>true</code> if the list of widget identifiers has
336      * changed; <code>false</code> otherwise.
337      */

338     public final boolean isWidgetChanged() {
339         return (widgetId != null);
340     }
341
342     /**
343      * Returns whether the widget identifier became defined. Otherwise, the
344      * widget identifier became undefined.
345      *
346      * @return <code>true</code> if the widget identifier became defined;
347      * <code>false</code> if the widget identifier became undefined.
348      */

349     public final boolean isWidgetDefined() {
350         return (((changedValues & CHANGED_WIDGET_DEFINED) != 0) && (widgetId != null));
351     }
352 }
353
Popular Tags