KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > commands > contexts > ContextManagerEvent


1 /*******************************************************************************
2  * Copyright (c) 2003, 2005 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.contexts;
12
13 import java.util.Set JavaDoc;
14
15 import org.eclipse.core.commands.common.AbstractBitSetEvent;
16
17 /**
18  * <p>
19  * An event indicating that the set of defined context identifiers has changed.
20  * </p>
21  *
22  * @since 3.1
23  * @see IContextManagerListener#contextManagerChanged(ContextManagerEvent)
24  */

25 public final class ContextManagerEvent extends AbstractBitSetEvent {
26
27     /**
28      * The bit used to represent whether the set of defined contexts has
29      * changed.
30      */

31     private static final int CHANGED_CONTEXT_DEFINED = 1 << 1;
32
33     /**
34      * The bit used to represent whether the set of active contexts has changed.
35      */

36     private static final int CHANGED_CONTEXTS_ACTIVE = 1;
37
38     /**
39      * The context identifier that was added or removed from the list of defined
40      * context identifiers.
41      */

42     private final String JavaDoc contextId;
43
44     /**
45      * The context manager that has changed.
46      */

47     private final ContextManager contextManager;
48
49     /**
50      * The set of context identifiers (strings) that were active before the
51      * change occurred. If the active contexts did not changed, then this value
52      * is <code>null</code>.
53      */

54     private final Set JavaDoc previouslyActiveContextIds;
55
56     /**
57      * Creates a new instance of this class.
58      *
59      * @param contextManager
60      * the instance of the interface that changed; must not be
61      * <code>null</code>.
62      * @param contextId
63      * The context identifier that was added or removed; may be
64      * <code>null</code> if the active contexts are changing.
65      * @param contextIdAdded
66      * Whether the context identifier became defined (otherwise, it
67      * became undefined).
68      * @param activeContextsChanged
69      * Whether the list of active contexts has changed.
70      * @param previouslyActiveContextIds
71      * the set of identifiers of previously active contexts. This set
72      * may be empty. If this set is not empty, it must only contain
73      * instances of <code>String</code>. This set must be
74      * <code>null</code> if activeContextChanged is
75      * <code>false</code> and must not be null if
76      * activeContextChanged is <code>true</code>.
77      */

78     public ContextManagerEvent(final ContextManager contextManager,
79             final String JavaDoc contextId, final boolean contextIdAdded,
80             final boolean activeContextsChanged,
81             final Set JavaDoc previouslyActiveContextIds) {
82         if (contextManager == null) {
83             throw new NullPointerException JavaDoc();
84         }
85
86         this.contextManager = contextManager;
87         this.contextId = contextId;
88         this.previouslyActiveContextIds = previouslyActiveContextIds;
89
90         if (contextIdAdded) {
91             changedValues |= CHANGED_CONTEXT_DEFINED;
92         }
93         if (activeContextsChanged) {
94             changedValues |= CHANGED_CONTEXTS_ACTIVE;
95         }
96     }
97
98     /**
99      * Returns the context identifier that was added or removed.
100      *
101      * @return The context identifier that was added or removed. This value may
102      * be <code>null</code> if no context identifier was added or
103      * removed.
104      */

105     public final String JavaDoc getContextId() {
106         return contextId;
107     }
108
109     /**
110      * Returns the instance of the interface that changed.
111      *
112      * @return the instance of the interface that changed. Guaranteed not to be
113      * <code>null</code>.
114      */

115     public final ContextManager getContextManager() {
116         return contextManager;
117     }
118
119     /**
120      * Returns the set of identifiers to previously active contexts.
121      *
122      * @return the set of identifiers to previously active contexts. This set
123      * may be empty. If this set is not empty, it is guaranteed to only
124      * contain instances of <code>String</code>. This set is
125      * guaranteed to be <code>null</code> if
126      * haveActiveContextChanged() is <code>false</code> and is
127      * guaranteed to not be <code>null</code> if
128      * haveActiveContextsChanged() is <code>true</code>.
129      */

130     public final Set JavaDoc getPreviouslyActiveContextIds() {
131         return previouslyActiveContextIds;
132     }
133
134     /**
135      * Returns whether the active context identifiers have changed.
136      *
137      * @return <code>true</code> if the collection of active contexts changed;
138      * <code>false</code> otherwise.
139      */

140     public final boolean isActiveContextsChanged() {
141         return ((changedValues & CHANGED_CONTEXTS_ACTIVE) != 0);
142     }
143
144     /**
145      * Returns whether the list of defined context identifiers has changed.
146      *
147      * @return <code>true</code> if the list of context identifiers has
148      * changed; <code>false</code> otherwise.
149      */

150     public final boolean isContextChanged() {
151         return (contextId != null);
152     }
153
154     /**
155      * Returns whether the context identifier became defined. Otherwise, the
156      * context identifier became undefined.
157      *
158      * @return <code>true</code> if the context identifier became defined;
159      * <code>false</code> if the context identifier became undefined.
160      */

161     public final boolean isContextDefined() {
162         return (((changedValues & CHANGED_CONTEXT_DEFINED) != 0) && (contextId != null));
163     }
164 }
165
Popular Tags