001: /*******************************************************************************
002: * Copyright (c) 2000, 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.ui.activities;
011:
012: import java.util.Set;
013:
014: import org.eclipse.ui.internal.util.Util;
015:
016: /**
017: * An instance of this class describes changes to an instance of
018: * <code>IActivityManager</code>. This class does not give details as to the
019: * specifics of a change, only that the given property on the source object has
020: * changed.
021: *
022: * <p>
023: * This class is not intended to be extended by clients.
024: * </p>
025: *
026: * @since 3.0
027: * @see IActivityManagerListener#activityManagerChanged(ActivityManagerEvent)
028: */
029: public final class ActivityManagerEvent {
030: private IActivityManager activityManager;
031:
032: private boolean definedActivityIdsChanged;
033:
034: private boolean definedCategoryIdsChanged;
035:
036: private boolean enabledActivityIdsChanged;
037:
038: /**
039: * The set of activity identifiers (strings) that were defined before the
040: * change occurred. If the defined activities did not changed, then this
041: * value is <code>null</code>.
042: */
043: private final Set previouslyDefinedActivityIds;
044:
045: /**
046: * The set of category identifiers (strings) that were defined before the
047: * change occurred. If the defined category did not changed, then this value
048: * is <code>null</code>.
049: */
050: private final Set previouslyDefinedCategoryIds;
051:
052: /**
053: * The set of activity identifiers (strings) that were enabled before the
054: * change occurred. If the enabled activities did not changed, then this
055: * value is <code>null</code>.
056: */
057: private final Set previouslyEnabledActivityIds;
058:
059: /**
060: * Creates a new instance of this class.
061: *
062: * @param activityManager
063: * the instance of the interface that changed.
064: * @param definedActivityIdsChanged
065: * <code>true</code>, iff the definedActivityIds property
066: * changed.
067: * @param definedCategoryIdsChanged
068: * <code>true</code>, iff the definedCategoryIds property
069: * changed.
070: * @param enabledActivityIdsChanged
071: * <code>true</code>, iff the enabledActivityIds property
072: * changed.
073: * @param previouslyDefinedActivityIds
074: * the set of identifiers to previously defined activities. This
075: * set may be empty. If this set is not empty, it must only
076: * contain instances of <code>String</code>. This set must be
077: * <code>null</code> if definedActivityIdsChanged is
078: * <code>false</code> and must not be null if
079: * definedActivityIdsChanged is <code>true</code>.
080: * @param previouslyDefinedCategoryIds
081: * the set of identifiers to previously defined category. This
082: * set may be empty. If this set is not empty, it must only
083: * contain instances of <code>String</code>. This set must be
084: * <code>null</code> if definedCategoryIdsChanged is
085: * <code>false</code> and must not be null if
086: * definedCategoryIdsChanged is <code>true</code>.
087: * @param previouslyEnabledActivityIds
088: * the set of identifiers to previously enabled activities. This
089: * set may be empty. If this set is not empty, it must only
090: * contain instances of <code>String</code>. This set must be
091: * <code>null</code> if enabledActivityIdsChanged is
092: * <code>false</code> and must not be null if
093: * enabledActivityIdsChanged is <code>true</code>.
094: */
095: public ActivityManagerEvent(IActivityManager activityManager,
096: boolean definedActivityIdsChanged,
097: boolean definedCategoryIdsChanged,
098: boolean enabledActivityIdsChanged,
099: final Set previouslyDefinedActivityIds,
100: final Set previouslyDefinedCategoryIds,
101: final Set previouslyEnabledActivityIds) {
102: if (activityManager == null) {
103: throw new NullPointerException();
104: }
105:
106: if (!definedActivityIdsChanged
107: && previouslyDefinedActivityIds != null) {
108: throw new IllegalArgumentException();
109: }
110:
111: if (!definedCategoryIdsChanged
112: && previouslyDefinedCategoryIds != null) {
113: throw new IllegalArgumentException();
114: }
115:
116: if (!enabledActivityIdsChanged
117: && previouslyEnabledActivityIds != null) {
118: throw new IllegalArgumentException();
119: }
120:
121: if (definedActivityIdsChanged) {
122: this .previouslyDefinedActivityIds = Util.safeCopy(
123: previouslyDefinedActivityIds, String.class);
124: } else {
125: this .previouslyDefinedActivityIds = null;
126: }
127:
128: if (definedCategoryIdsChanged) {
129: this .previouslyDefinedCategoryIds = Util.safeCopy(
130: previouslyDefinedCategoryIds, String.class);
131: } else {
132: this .previouslyDefinedCategoryIds = null;
133: }
134:
135: if (enabledActivityIdsChanged) {
136: this .previouslyEnabledActivityIds = Util.safeCopy(
137: previouslyEnabledActivityIds, String.class);
138: } else {
139: this .previouslyEnabledActivityIds = null;
140: }
141:
142: this .activityManager = activityManager;
143: this .definedActivityIdsChanged = definedActivityIdsChanged;
144: this .definedCategoryIdsChanged = definedCategoryIdsChanged;
145: this .enabledActivityIdsChanged = enabledActivityIdsChanged;
146: }
147:
148: /**
149: * Returns the instance of the interface that changed.
150: *
151: * @return the instance of the interface that changed. Guaranteed not to be
152: * <code>null</code>.
153: */
154: public IActivityManager getActivityManager() {
155: return activityManager;
156: }
157:
158: /**
159: * Returns the activity identifiers that were previously defined.
160: *
161: * @return The set of defined activity identifiers before the changed; may
162: * be empty, but never <code>null</code>. This set will only
163: * contain strings.
164: */
165: public final Set getPreviouslyDefinedActivityIds() {
166: return previouslyDefinedActivityIds;
167: }
168:
169: /**
170: * Returns the category identifiers that were previously defined.
171: *
172: * @return The set of defined category identifiers before the changed; may
173: * be empty, but never <code>null</code>. This set will only
174: * contain strings.
175: */
176: public final Set getPreviouslyDefinedCategoryIds() {
177: return previouslyDefinedCategoryIds;
178: }
179:
180: /**
181: * Returns the activity identifiers that were previously enabled.
182: *
183: * @return The set of enabled activity identifiers before the changed; may
184: * be empty, but never <code>null</code>. This set will only
185: * contain strings.
186: */
187: public final Set getPreviouslyEnabledActivityIds() {
188: return previouslyEnabledActivityIds;
189: }
190:
191: /**
192: * Returns whether or not the definedActivityIds property changed.
193: *
194: * @return <code>true</code>, iff the definedActivityIds property changed.
195: */
196: public boolean haveDefinedActivityIdsChanged() {
197: return definedActivityIdsChanged;
198: }
199:
200: /**
201: * Returns whether or not the definedCategoryIds property changed.
202: *
203: * @return <code>true</code>, iff the definedCategoryIds property changed.
204: */
205: public boolean haveDefinedCategoryIdsChanged() {
206: return definedCategoryIdsChanged;
207: }
208:
209: /**
210: * Returns whether or not the enabledActivityIds property changed.
211: *
212: * @return <code>true</code>, iff the enabledActivityIds property changed.
213: */
214: public boolean haveEnabledActivityIdsChanged() {
215: return enabledActivityIdsChanged;
216: }
217: }
|