1414
1515package org .eclipse .ui .activities ;
1616
17+ import static java .util .Collections .emptySet ;
18+
1719import java .util .Set ;
20+ import java .util .stream .Stream ;
1821import org .eclipse .ui .internal .util .Util ;
1922
2023/**
@@ -39,23 +42,31 @@ public final class ActivityManagerEvent {
3942
4043 private boolean enabledActivityIdsChanged ;
4144
45+ /**
46+ * Indicates whether enabled IDs of non-expression-controlled activities have
47+ * changed. The value is calculated from changed enabled activity IDs given to
48+ * the constructor if known by the caller or is set to <code>null</null> and
49+ * will be calculated on demand upon first access to the value.
50+ */
51+ private Boolean enabledNonExpressionControlledActivityIdsChanged = null ;
52+
4253 /**
4354 * The set of activity identifiers (strings) that were defined before the change
44- * occurred. If the defined activities did not changed , then this value is
55+ * occurred. If the defined activities did not change , then this value is
4556 * <code>null</code>.
4657 */
4758 private final Set <String > previouslyDefinedActivityIds ;
4859
4960 /**
5061 * The set of category identifiers (strings) that were defined before the change
51- * occurred. If the defined category did not changed , then this value is
62+ * occurred. If the defined category did not change , then this value is
5263 * <code>null</code>.
5364 */
5465 private final Set <String > previouslyDefinedCategoryIds ;
5566
5667 /**
5768 * The set of activity identifiers (strings) that were enabled before the change
58- * occurred. If the enabled activities did not changed , then this value is
69+ * occurred. If the enabled activities did not change , then this value is
5970 * <code>null</code>.
6071 */
6172 private final Set <String > previouslyEnabledActivityIds ;
@@ -145,6 +156,91 @@ public ActivityManagerEvent(IActivityManager activityManager, boolean definedAct
145156 this .enabledActivityIdsChanged = enabledActivityIdsChanged ;
146157 }
147158
159+ /**
160+ * Creates a new instance of this class.
161+ *
162+ * @param activityManager the instance of the interface that
163+ * changed.
164+ * @param definedActivityIdsChanged <code>true</code>, iff the
165+ * definedActivityIds property changed.
166+ * @param definedCategoryIdsChanged <code>true</code>, iff the
167+ * definedCategoryIds property changed.
168+ * @param enabledActivityIdsChanged <code>true</code>, iff the
169+ * enabledActivityIds property changed.
170+ * @param previouslyDefinedActivityIds the set of identifiers to previously
171+ * defined activities. This set may be
172+ * empty. If this set is not empty, it must
173+ * only contain instances of
174+ * <code>String</code> . This set must be
175+ * <code>null</code> if
176+ * definedActivityIdsChanged is
177+ * <code>false</code> and must not be null
178+ * if definedActivityIdsChanged is
179+ * <code>true</code>.
180+ * @param previouslyDefinedCategoryIds the set of identifiers to previously
181+ * defined category. This set may be empty.
182+ * If this set is not empty, it must only
183+ * contain instances of <code>String</code>.
184+ * This set must be <code>null</code> if
185+ * definedCategoryIdsChanged is
186+ * <code>false</code> and must not be null
187+ * if definedCategoryIdsChanged is
188+ * <code>true</code>.
189+ * @param previouslyEnabledActivityIds the set of identifiers to previously
190+ * enabled activities. This set may be
191+ * empty. If this set is not empty, it must
192+ * only contain instances of
193+ * <code>String</code>. This set must be
194+ * <code>null</code> if
195+ * enabledActivityIdsChanged is
196+ * <code>false</code> and must not be null
197+ * if enabledActivityIdsChanged is
198+ * <code>true</code>.
199+ * @param changedEnabledActivityIds the set of identifiers to activities
200+ * whose enabled state has changed. This set
201+ * may be empty. If this set is not empty,
202+ * it must only contain instances of
203+ * <code>String</code>. This set must be
204+ * <code>null</code> if
205+ * enabledActivityIdsChanged is
206+ * <code>false</code> and must not be null
207+ * if enabledActivityIdsChanged is
208+ * <code>true</code>.
209+ * @since 3.131
210+ */
211+ public ActivityManagerEvent (IActivityManager activityManager , boolean definedActivityIdsChanged ,
212+ boolean definedCategoryIdsChanged , boolean enabledActivityIdsChanged ,
213+ final Set <String > previouslyDefinedActivityIds , final Set <String > previouslyDefinedCategoryIds ,
214+ final Set <String > previouslyEnabledActivityIds , Set <String > changedEnabledActivityIds ) {
215+ this (activityManager , definedActivityIdsChanged , definedCategoryIdsChanged , enabledActivityIdsChanged ,
216+ previouslyDefinedActivityIds , previouslyDefinedCategoryIds , previouslyEnabledActivityIds );
217+ if (enabledActivityIdsChanged ) {
218+ this .enabledNonExpressionControlledActivityIdsChanged = changedEnabledActivityIds .stream ()
219+ .anyMatch (this ::isIdOfNonExpressionControlledActivity );
220+ } else {
221+ this .enabledNonExpressionControlledActivityIdsChanged = false ;
222+ }
223+
224+ }
225+
226+ /**
227+ * Creates a copy of this {@link ActivityManagerEvent} containing the given
228+ * {@code newActivityManager}.
229+ *
230+ * @param newActivityManager the new activity manager to be referenced by the
231+ * copied event
232+ *
233+ * @return a copy of this event referencing the given activity manager
234+ * @since 3.131
235+ */
236+ public ActivityManagerEvent copyFor (IActivityManager newActivityManager ) {
237+ ActivityManagerEvent copy = new ActivityManagerEvent (newActivityManager , definedActivityIdsChanged ,
238+ definedCategoryIdsChanged , enabledActivityIdsChanged , previouslyDefinedActivityIds ,
239+ previouslyDefinedCategoryIds , previouslyEnabledActivityIds );
240+ copy .enabledNonExpressionControlledActivityIdsChanged = enabledNonExpressionControlledActivityIdsChanged ;
241+ return copy ;
242+ }
243+
148244 /**
149245 * Returns the instance of the interface that changed.
150246 *
@@ -214,4 +310,35 @@ public boolean haveDefinedCategoryIdsChanged() {
214310 public boolean haveEnabledActivityIdsChanged () {
215311 return enabledActivityIdsChanged ;
216312 }
313+
314+ /**
315+ * Returns whether or not enabledActivityIds property changed and any of the
316+ * changed IDs belongs to a non-expression-controlled activity.
317+ *
318+ * @return <code>true>/code> iff the enabledActivityIds property changed and any
319+ * of the changed IDs belongs to a non-expression-controlled activity.
320+ * @since 3.131
321+ */
322+ public boolean haveEnabledNonExpressionControlledActivityIdsChanged () {
323+ if (enabledNonExpressionControlledActivityIdsChanged == null ) {
324+ enabledNonExpressionControlledActivityIdsChanged = calculateHaveEnabledNonExpressionControlledActivityIdsChanged ();
325+ }
326+ return enabledNonExpressionControlledActivityIdsChanged ;
327+ }
328+
329+ private boolean calculateHaveEnabledNonExpressionControlledActivityIdsChanged () {
330+ Set <String > previousIds = previouslyEnabledActivityIds == null ? emptySet () : previouslyEnabledActivityIds ;
331+ Set <String > currentIds = activityManager .getEnabledActivityIds ();
332+ Stream <String > addedIds = currentIds .stream ().filter (id -> !previousIds .contains (id ));
333+ if (addedIds .anyMatch (this ::isIdOfNonExpressionControlledActivity )) {
334+ return true ;
335+ }
336+ Stream <String > removedIds = previousIds .stream ().filter (id -> !currentIds .contains (id ));
337+ return removedIds .anyMatch (this ::isIdOfNonExpressionControlledActivity );
338+ }
339+
340+ private boolean isIdOfNonExpressionControlledActivity (String id ) {
341+ return activityManager .getActivity (id ).getExpression () == null ;
342+ }
343+
217344}
0 commit comments