1 11 12 package org.eclipse.ui.internal.activities; 13 14 import java.util.ArrayList ; 15 import java.util.Collection ; 16 import java.util.Collections ; 17 import java.util.HashMap ; 18 import java.util.HashSet ; 19 import java.util.Iterator ; 20 import java.util.LinkedList ; 21 import java.util.List ; 22 import java.util.Map ; 23 import java.util.Set ; 24 import java.util.TreeMap ; 25 import java.util.WeakHashMap ; 26 27 import org.eclipse.core.runtime.IProgressMonitor; 28 import org.eclipse.core.runtime.IStatus; 29 import org.eclipse.core.runtime.Platform; 30 import org.eclipse.core.runtime.Status; 31 import org.eclipse.core.runtime.jobs.Job; 32 import org.eclipse.ui.activities.ActivityEvent; 33 import org.eclipse.ui.activities.ActivityManagerEvent; 34 import org.eclipse.ui.activities.CategoryEvent; 35 import org.eclipse.ui.activities.IActivity; 36 import org.eclipse.ui.activities.IActivityPatternBinding; 37 import org.eclipse.ui.activities.IActivityRequirementBinding; 38 import org.eclipse.ui.activities.ICategory; 39 import org.eclipse.ui.activities.ICategoryActivityBinding; 40 import org.eclipse.ui.activities.IIdentifier; 41 import org.eclipse.ui.activities.IMutableActivityManager; 42 import org.eclipse.ui.activities.IdentifierEvent; 43 import org.eclipse.ui.internal.util.Util; 44 45 50 public final class MutableActivityManager extends AbstractActivityManager 51 implements IMutableActivityManager, Cloneable { 52 53 private Map activitiesById = new WeakHashMap (); 54 55 private Map activityRequirementBindingsByActivityId = new HashMap (); 56 57 private Map activityDefinitionsById = new HashMap (); 58 59 private Map activityPatternBindingsByActivityId = new HashMap (); 60 61 private IActivityRegistry activityRegistry; 62 63 private Map categoriesById = new WeakHashMap (); 64 65 private Map categoryActivityBindingsByCategoryId = new HashMap (); 66 67 private Map categoryDefinitionsById = new HashMap (); 68 69 private Set definedActivityIds = new HashSet (); 70 71 private Set definedCategoryIds = new HashSet (); 72 73 private Set enabledActivityIds = new HashSet (); 74 75 private Map identifiersById = new WeakHashMap (); 76 77 80 private List deferredIdentifiers = Collections.synchronizedList(new LinkedList ()); 81 82 85 private Job deferredIdentifierJob = null; 86 87 private final IActivityRegistryListener activityRegistryListener = new IActivityRegistryListener() { 88 public void activityRegistryChanged( 89 ActivityRegistryEvent activityRegistryEvent) { 90 readRegistry(false); 91 } 92 }; 93 94 97 public MutableActivityManager() { 98 this(new ExtensionActivityRegistry(Platform.getExtensionRegistry())); 99 } 100 101 106 public MutableActivityManager(IActivityRegistry activityRegistry) { 107 if (activityRegistry == null) { 108 throw new NullPointerException (); 109 } 110 111 this.activityRegistry = activityRegistry; 112 113 this.activityRegistry 114 .addActivityRegistryListener(activityRegistryListener); 115 116 readRegistry(true); 117 } 118 119 public IActivity getActivity(String activityId) { 120 if (activityId == null) { 121 throw new NullPointerException (); 122 } 123 124 Activity activity = (Activity) activitiesById.get(activityId); 125 126 if (activity == null) { 127 activity = new Activity(activityId); 128 updateActivity(activity); 129 activitiesById.put(activityId, activity); 130 } 131 132 return activity; 133 } 134 135 public ICategory getCategory(String categoryId) { 136 if (categoryId == null) { 137 throw new NullPointerException (); 138 } 139 140 Category category = (Category) categoriesById.get(categoryId); 141 142 if (category == null) { 143 category = new Category(categoryId); 144 updateCategory(category); 145 categoriesById.put(categoryId, category); 146 } 147 148 return category; 149 } 150 151 public Set getDefinedActivityIds() { 152 return Collections.unmodifiableSet(definedActivityIds); 153 } 154 155 public Set getDefinedCategoryIds() { 156 return Collections.unmodifiableSet(definedCategoryIds); 157 } 158 159 public Set getEnabledActivityIds() { 160 return Collections.unmodifiableSet(enabledActivityIds); 161 } 162 163 public IIdentifier getIdentifier(String identifierId) { 164 if (identifierId == null) { 165 throw new NullPointerException (); 166 } 167 168 Identifier identifier = (Identifier) identifiersById.get(identifierId); 169 170 if (identifier == null) { 171 identifier = new Identifier(identifierId); 172 updateIdentifier(identifier); 173 identifiersById.put(identifierId, identifier); 174 } 175 176 return identifier; 177 } 178 179 private void getRequiredActivityIds(Set activityIds, Set requiredActivityIds) { 180 for (Iterator iterator = activityIds.iterator(); iterator.hasNext();) { 181 String activityId = (String ) iterator.next(); 182 IActivity activity = getActivity(activityId); 183 Set childActivityIds = new HashSet (); 184 Set activityRequirementBindings = activity 185 .getActivityRequirementBindings(); 186 187 for (Iterator iterator2 = activityRequirementBindings.iterator(); iterator2 188 .hasNext();) { 189 IActivityRequirementBinding activityRequirementBinding = (IActivityRequirementBinding) iterator2 190 .next(); 191 childActivityIds.add(activityRequirementBinding 192 .getRequiredActivityId()); 193 } 194 195 childActivityIds.removeAll(requiredActivityIds); 196 requiredActivityIds.addAll(childActivityIds); 197 getRequiredActivityIds(childActivityIds, requiredActivityIds); 198 } 199 } 200 201 private void notifyActivities(Map activityEventsByActivityId) { 202 for (Iterator iterator = activityEventsByActivityId.entrySet() 203 .iterator(); iterator.hasNext();) { 204 Map.Entry entry = (Map.Entry ) iterator.next(); 205 String activityId = (String ) entry.getKey(); 206 ActivityEvent activityEvent = (ActivityEvent) entry.getValue(); 207 Activity activity = (Activity) activitiesById.get(activityId); 208 209 if (activity != null) { 210 activity.fireActivityChanged(activityEvent); 211 } 212 } 213 } 214 215 private void notifyCategories(Map categoryEventsByCategoryId) { 216 for (Iterator iterator = categoryEventsByCategoryId.entrySet() 217 .iterator(); iterator.hasNext();) { 218 Map.Entry entry = (Map.Entry ) iterator.next(); 219 String categoryId = (String ) entry.getKey(); 220 CategoryEvent categoryEvent = (CategoryEvent) entry.getValue(); 221 Category category = (Category) categoriesById.get(categoryId); 222 223 if (category != null) { 224 category.fireCategoryChanged(categoryEvent); 225 } 226 } 227 } 228 229 private void notifyIdentifiers(Map identifierEventsByIdentifierId) { 230 for (Iterator iterator = identifierEventsByIdentifierId.entrySet() 231 .iterator(); iterator.hasNext();) { 232 Map.Entry entry = (Map.Entry ) iterator.next(); 233 String identifierId = (String ) entry.getKey(); 234 IdentifierEvent identifierEvent = (IdentifierEvent) entry 235 .getValue(); 236 Identifier identifier = (Identifier) identifiersById 237 .get(identifierId); 238 239 if (identifier != null) { 240 identifier.fireIdentifierChanged(identifierEvent); 241 } 242 } 243 } 244 245 private void readRegistry(boolean setDefaults) { 246 if (!isRegexpSupported()) { 247 return; 248 } 249 Collection activityDefinitions = new ArrayList (); 250 activityDefinitions.addAll(activityRegistry.getActivityDefinitions()); 251 Map activityDefinitionsById = new HashMap (ActivityDefinition 252 .activityDefinitionsById(activityDefinitions, false)); 253 254 for (Iterator iterator = activityDefinitionsById.values().iterator(); iterator 255 .hasNext();) { 256 ActivityDefinition activityDefinition = (ActivityDefinition) iterator 257 .next(); 258 String name = activityDefinition.getName(); 259 260 if (name == null || name.length() == 0) { 261 iterator.remove(); 262 } 263 } 264 265 Collection categoryDefinitions = new ArrayList (); 266 categoryDefinitions.addAll(activityRegistry.getCategoryDefinitions()); 267 Map categoryDefinitionsById = new HashMap (CategoryDefinition 268 .categoryDefinitionsById(categoryDefinitions, false)); 269 270 for (Iterator iterator = categoryDefinitionsById.values().iterator(); iterator 271 .hasNext();) { 272 CategoryDefinition categoryDefinition = (CategoryDefinition) iterator 273 .next(); 274 String name = categoryDefinition.getName(); 275 276 if (name == null || name.length() == 0) { 277 iterator.remove(); 278 } 279 } 280 281 Map activityRequirementBindingDefinitionsByActivityId = ActivityRequirementBindingDefinition 282 .activityRequirementBindingDefinitionsByActivityId(activityRegistry 283 .getActivityRequirementBindingDefinitions()); 284 Map activityRequirementBindingsByActivityId = new HashMap (); 285 286 for (Iterator iterator = activityRequirementBindingDefinitionsByActivityId 287 .entrySet().iterator(); iterator.hasNext();) { 288 Map.Entry entry = (Map.Entry ) iterator.next(); 289 String parentActivityId = (String ) entry.getKey(); 290 291 if (activityDefinitionsById.containsKey(parentActivityId)) { 292 Collection activityRequirementBindingDefinitions = (Collection ) entry 293 .getValue(); 294 295 if (activityRequirementBindingDefinitions != null) { 296 for (Iterator iterator2 = activityRequirementBindingDefinitions 297 .iterator(); iterator2.hasNext();) { 298 ActivityRequirementBindingDefinition activityRequirementBindingDefinition = (ActivityRequirementBindingDefinition) iterator2 299 .next(); 300 String childActivityId = activityRequirementBindingDefinition 301 .getRequiredActivityId(); 302 303 if (activityDefinitionsById 304 .containsKey(childActivityId)) { 305 IActivityRequirementBinding activityRequirementBinding = new ActivityRequirementBinding( 306 childActivityId, parentActivityId); 307 Set activityRequirementBindings = (Set ) activityRequirementBindingsByActivityId 308 .get(parentActivityId); 309 310 if (activityRequirementBindings == null) { 311 activityRequirementBindings = new HashSet (); 312 activityRequirementBindingsByActivityId.put( 313 parentActivityId, 314 activityRequirementBindings); 315 } 316 317 activityRequirementBindings 318 .add(activityRequirementBinding); 319 } 320 } 321 } 322 } 323 } 324 325 Map activityPatternBindingDefinitionsByActivityId = ActivityPatternBindingDefinition 326 .activityPatternBindingDefinitionsByActivityId(activityRegistry 327 .getActivityPatternBindingDefinitions()); 328 Map activityPatternBindingsByActivityId = new HashMap (); 329 330 for (Iterator iterator = activityPatternBindingDefinitionsByActivityId 331 .entrySet().iterator(); iterator.hasNext();) { 332 Map.Entry entry = (Map.Entry ) iterator.next(); 333 String activityId = (String ) entry.getKey(); 334 335 if (activityDefinitionsById.containsKey(activityId)) { 336 Collection activityPatternBindingDefinitions = (Collection ) entry 337 .getValue(); 338 339 if (activityPatternBindingDefinitions != null) { 340 for (Iterator iterator2 = activityPatternBindingDefinitions 341 .iterator(); iterator2.hasNext();) { 342 ActivityPatternBindingDefinition activityPatternBindingDefinition = (ActivityPatternBindingDefinition) iterator2 343 .next(); 344 String pattern = activityPatternBindingDefinition 345 .getPattern(); 346 347 if (pattern != null && pattern.length() != 0) { 348 IActivityPatternBinding activityPatternBinding = new ActivityPatternBinding( 349 activityId, pattern); 350 Set activityPatternBindings = (Set ) activityPatternBindingsByActivityId 351 .get(activityId); 352 353 if (activityPatternBindings == null) { 354 activityPatternBindings = new HashSet (); 355 activityPatternBindingsByActivityId.put( 356 activityId, activityPatternBindings); 357 } 358 359 activityPatternBindings.add(activityPatternBinding); 360 } 361 } 362 } 363 } 364 } 365 366 Map categoryActivityBindingDefinitionsByCategoryId = CategoryActivityBindingDefinition 367 .categoryActivityBindingDefinitionsByCategoryId(activityRegistry 368 .getCategoryActivityBindingDefinitions()); 369 Map categoryActivityBindingsByCategoryId = new HashMap (); 370 371 for (Iterator iterator = categoryActivityBindingDefinitionsByCategoryId 372 .entrySet().iterator(); iterator.hasNext();) { 373 Map.Entry entry = (Map.Entry ) iterator.next(); 374 String categoryId = (String ) entry.getKey(); 375 376 if (categoryDefinitionsById.containsKey(categoryId)) { 377 Collection categoryActivityBindingDefinitions = (Collection ) entry 378 .getValue(); 379 380 if (categoryActivityBindingDefinitions != null) { 381 for (Iterator iterator2 = categoryActivityBindingDefinitions 382 .iterator(); iterator2.hasNext();) { 383 CategoryActivityBindingDefinition categoryActivityBindingDefinition = (CategoryActivityBindingDefinition) iterator2 384 .next(); 385 String activityId = categoryActivityBindingDefinition 386 .getActivityId(); 387 388 if (activityDefinitionsById.containsKey(activityId)) { 389 ICategoryActivityBinding categoryActivityBinding = new CategoryActivityBinding( 390 activityId, categoryId); 391 Set categoryActivityBindings = (Set ) categoryActivityBindingsByCategoryId 392 .get(categoryId); 393 394 if (categoryActivityBindings == null) { 395 categoryActivityBindings = new HashSet (); 396 categoryActivityBindingsByCategoryId.put( 397 categoryId, categoryActivityBindings); 398 } 399 400 categoryActivityBindings 401 .add(categoryActivityBinding); 402 } 403 } 404 } 405 } 406 } 407 408 this.activityRequirementBindingsByActivityId = activityRequirementBindingsByActivityId; 409 this.activityDefinitionsById = activityDefinitionsById; 410 this.activityPatternBindingsByActivityId = activityPatternBindingsByActivityId; 411 this.categoryActivityBindingsByCategoryId = categoryActivityBindingsByCategoryId; 412 this.categoryDefinitionsById = categoryDefinitionsById; 413 boolean definedActivityIdsChanged = false; 414 Set definedActivityIds = new HashSet (activityDefinitionsById.keySet()); 415 416 Set previouslyDefinedActivityIds = null; 417 if (!definedActivityIds.equals(this.definedActivityIds)) { 418 previouslyDefinedActivityIds = this.definedActivityIds; 419 this.definedActivityIds = definedActivityIds; 420 definedActivityIdsChanged = true; 421 } 422 423 boolean definedCategoryIdsChanged = false; 424 Set definedCategoryIds = new HashSet (categoryDefinitionsById.keySet()); 425 426 Set previouslyDefinedCategoryIds = null; 427 if (!definedCategoryIds.equals(this.definedCategoryIds)) { 428 previouslyDefinedCategoryIds = this.definedCategoryIds; 429 this.definedCategoryIds = definedCategoryIds; 430 definedCategoryIdsChanged = true; 431 } 432 433 Set enabledActivityIds = new HashSet (this.enabledActivityIds); 434 getRequiredActivityIds(this.enabledActivityIds, enabledActivityIds); 435 boolean enabledActivityIdsChanged = false; 436 437 Set previouslyEnabledActivityIds = null; 438 if (!this.enabledActivityIds.equals(enabledActivityIds)) { 439 previouslyEnabledActivityIds = this.enabledActivityIds; 440 this.enabledActivityIds = enabledActivityIds; 441 enabledActivityIdsChanged = true; 442 } 443 444 Map activityEventsByActivityId = updateActivities(activitiesById 445 .keySet()); 446 447 Map categoryEventsByCategoryId = updateCategories(categoriesById 448 .keySet()); 449 450 Map identifierEventsByIdentifierId = updateIdentifiers(identifiersById 451 .keySet()); 452 453 if (definedActivityIdsChanged || definedCategoryIdsChanged 454 || enabledActivityIdsChanged) { 455 fireActivityManagerChanged(new ActivityManagerEvent(this, 456 definedActivityIdsChanged, definedCategoryIdsChanged, 457 enabledActivityIdsChanged, previouslyDefinedActivityIds, 458 previouslyDefinedCategoryIds, previouslyEnabledActivityIds)); 459 } 460 461 if (activityEventsByActivityId != null) { 462 notifyActivities(activityEventsByActivityId); 463 } 464 465 if (categoryEventsByCategoryId != null) { 466 notifyCategories(categoryEventsByCategoryId); 467 } 468 469 if (identifierEventsByIdentifierId != null) { 470 notifyIdentifiers(identifierEventsByIdentifierId); 471 } 472 473 if (setDefaults) { 474 setEnabledActivityIds(new HashSet (activityRegistry 475 .getDefaultEnabledActivities())); 476 } 477 } 478 479 487 private boolean isRegexpSupported() { 488 try { 489 Class.forName("java.util.regex.Pattern"); return true; 491 } 492 catch (Exception e) { 493 return false; 494 } 495 } 496 497 public void setEnabledActivityIds(Set enabledActivityIds) { 498 enabledActivityIds = Util.safeCopy(enabledActivityIds, String .class); 499 Set requiredActivityIds = new HashSet (enabledActivityIds); 500 getRequiredActivityIds(enabledActivityIds, requiredActivityIds); 501 enabledActivityIds = requiredActivityIds; 502 boolean activityManagerChanged = false; 503 Map activityEventsByActivityId = null; 504 Set deltaActivityIds = null; 505 Set previouslyEnabledActivityIds = null; 506 if (!this.enabledActivityIds.equals(enabledActivityIds)) { 507 previouslyEnabledActivityIds = this.enabledActivityIds; 508 this.enabledActivityIds = enabledActivityIds; 509 activityManagerChanged = true; 510 511 deltaActivityIds = new HashSet (previouslyEnabledActivityIds); 513 deltaActivityIds.removeAll(enabledActivityIds); 514 Set temp = new HashSet (enabledActivityIds); 515 temp.removeAll(previouslyEnabledActivityIds); 516 deltaActivityIds.addAll(temp); 517 518 activityEventsByActivityId = updateActivities(deltaActivityIds); 519 } 520 521 if (activityManagerChanged) { 523 Map identifierEventsByIdentifierId = updateIdentifiers(identifiersById 524 .keySet(), deltaActivityIds); 525 if (identifierEventsByIdentifierId != null) { 526 notifyIdentifiers(identifierEventsByIdentifierId); 527 } 528 } 529 if (activityEventsByActivityId != null) { 530 notifyActivities(activityEventsByActivityId); 531 } 532 533 if (activityManagerChanged) { 534 fireActivityManagerChanged(new ActivityManagerEvent(this, false, 535 false, true, null, null, previouslyEnabledActivityIds)); 536 } 537 } 538 539 private Map updateActivities(Collection activityIds) { 540 Map activityEventsByActivityId = new TreeMap (); 541 542 for (Iterator iterator = activityIds.iterator(); iterator.hasNext();) { 543 String activityId = (String ) iterator.next(); 544 Activity activity = (Activity) activitiesById.get(activityId); 545 546 if (activity != null) { 547 ActivityEvent activityEvent = updateActivity(activity); 548 549 if (activityEvent != null) { 550 activityEventsByActivityId.put(activityId, activityEvent); 551 } 552 } 553 } 554 555 return activityEventsByActivityId; 556 } 557 558 private ActivityEvent updateActivity(Activity activity) { 559 Set activityRequirementBindings = (Set ) activityRequirementBindingsByActivityId 560 .get(activity.getId()); 561 boolean activityRequirementBindingsChanged = activity 562 .setActivityRequirementBindings(activityRequirementBindings != null ? activityRequirementBindings 563 : Collections.EMPTY_SET); 564 Set activityPatternBindings = (Set ) activityPatternBindingsByActivityId 565 .get(activity.getId()); 566 boolean activityPatternBindingsChanged = activity 567 .setActivityPatternBindings(activityPatternBindings != null ? activityPatternBindings 568 : Collections.EMPTY_SET); 569 ActivityDefinition activityDefinition = (ActivityDefinition) activityDefinitionsById 570 .get(activity.getId()); 571 boolean definedChanged = activity 572 .setDefined(activityDefinition != null); 573 boolean enabledChanged = activity.setEnabled(enabledActivityIds 574 .contains(activity.getId())); 575 boolean nameChanged = activity 576 .setName(activityDefinition != null ? activityDefinition 577 .getName() : null); 578 boolean descriptionChanged = activity 579 .setDescription(activityDefinition != null ? activityDefinition 580 .getDescription() : null); 581 boolean defaultEnabledChanged = activity.setDefaultEnabled(activityRegistry 582 .getDefaultEnabledActivities().contains(activity.getId())); 583 if (activityRequirementBindingsChanged 584 || activityPatternBindingsChanged || definedChanged 585 || enabledChanged || nameChanged || descriptionChanged 586 || defaultEnabledChanged) { 587 return new ActivityEvent(activity, 588 activityRequirementBindingsChanged, 589 activityPatternBindingsChanged, definedChanged, 590 descriptionChanged, enabledChanged, nameChanged, defaultEnabledChanged); 591 } 592 593 return null; 594 } 595 596 private Map updateCategories(Collection categoryIds) { 597 Map categoryEventsByCategoryId = new TreeMap (); 598 599 for (Iterator iterator = categoryIds.iterator(); iterator.hasNext();) { 600 String categoryId = (String ) iterator.next(); 601 Category category = (Category) categoriesById.get(categoryId); 602 603 if (category != null) { 604 CategoryEvent categoryEvent = updateCategory(category); 605 606 if (categoryEvent != null) { 607 categoryEventsByCategoryId.put(categoryId, categoryEvent); 608 } 609 } 610 } 611 612 return categoryEventsByCategoryId; 613 } 614 615 private CategoryEvent updateCategory(Category category) { 616 Set categoryActivityBindings = (Set ) categoryActivityBindingsByCategoryId 617 .get(category.getId()); 618 boolean categoryActivityBindingsChanged = category 619 .setCategoryActivityBindings(categoryActivityBindings != null ? categoryActivityBindings 620 : Collections.EMPTY_SET); 621 CategoryDefinition categoryDefinition = (CategoryDefinition) categoryDefinitionsById 622 .get(category.getId()); 623 boolean definedChanged = category 624 .setDefined(categoryDefinition != null); 625 boolean nameChanged = category 626 .setName(categoryDefinition != null ? categoryDefinition 627 .getName() : null); 628 boolean descriptionChanged = category 629 .setDescription(categoryDefinition != null ? categoryDefinition 630 .getDescription() : null); 631 632 if (categoryActivityBindingsChanged || definedChanged || nameChanged 633 || descriptionChanged) { 634 return new CategoryEvent(category, categoryActivityBindingsChanged, 635 definedChanged, descriptionChanged, nameChanged); 636 } 637 638 return null; 639 } 640 641 private IdentifierEvent updateIdentifier(Identifier identifier) { 642 return updateIdentifier(identifier, definedActivityIds); 643 } 644 645 private IdentifierEvent updateIdentifier(Identifier identifier, Set changedActivityIds) { 646 String id = identifier.getId(); 647 Set activityIds = new HashSet (); 648 649 boolean enabled = false; 650 651 boolean activityIdsChanged = false; 652 653 boolean enabledChanged = false; 654 655 if (enabledActivityIds.size() == definedActivityIds.size()) { 659 enabled = true; 660 enabledChanged = identifier.setEnabled(enabled); 661 identifier.setActivityIds(Collections.EMPTY_SET); 662 deferredIdentifiers.add(identifier); 663 getUpdateJob().schedule(); 664 if (enabledChanged) { 665 return new IdentifierEvent(identifier, activityIdsChanged, 666 enabledChanged); 667 } 668 } 669 else { 670 boolean matchesAtLeastOneEnabled = false; 671 boolean matchesAtLeastOneDisabled = false; 672 Set activityIdsToUpdate = new HashSet (changedActivityIds); 673 if (identifier.getActivityIds() != null) { 674 activityIdsToUpdate.addAll(identifier.getActivityIds()); 675 } 676 for (Iterator iterator = activityIdsToUpdate.iterator(); iterator 677 .hasNext();) { 678 String activityId = (String ) iterator.next(); 679 Activity activity = (Activity) getActivity(activityId); 680 681 if (activity.isMatch(id)) { 682 activityIds.add(activityId); 683 if (activity.isEnabled()) { 684 matchesAtLeastOneEnabled = true; 685 } else { 686 matchesAtLeastOneDisabled = true; 687 } 688 } 689 } 690 691 enabled = matchesAtLeastOneEnabled ? true : !matchesAtLeastOneDisabled; 692 693 activityIdsChanged = identifier.setActivityIds(activityIds); 694 enabledChanged = identifier.setEnabled(enabled); 695 696 if (activityIdsChanged || enabledChanged) { 697 return new IdentifierEvent(identifier, activityIdsChanged, 698 enabledChanged); 699 } 700 } 701 return null; 702 } 703 704 private Map updateIdentifiers(Collection identifierIds) { 705 return updateIdentifiers(identifierIds, definedActivityIds); 706 } 707 708 private Map updateIdentifiers(Collection identifierIds, Set changedActivityIds) { 709 Map identifierEventsByIdentifierId = new TreeMap (); 710 711 for (Iterator iterator = identifierIds.iterator(); iterator.hasNext();) { 712 String identifierId = (String ) iterator.next(); 713 Identifier identifier = (Identifier) identifiersById 714 .get(identifierId); 715 716 if (identifier != null) { 717 IdentifierEvent identifierEvent = updateIdentifier(identifier, changedActivityIds); 718 719 if (identifierEvent != null) { 720 identifierEventsByIdentifierId.put(identifierId, 721 identifierEvent); 722 } 723 } 724 } 725 726 return identifierEventsByIdentifierId; 727 } 728 729 734 public void unhookRegistryListeners() { 735 activityRegistry.removeActivityRegistryListener(activityRegistryListener); 736 } 737 738 741 public Object clone() { 742 MutableActivityManager clone = new MutableActivityManager(activityRegistry); 743 clone.setEnabledActivityIds(getEnabledActivityIds()); 744 return clone; 745 } 746 747 753 private Job getUpdateJob() { 754 if (deferredIdentifierJob == null) { 755 deferredIdentifierJob = new Job("Identifier Update Job") { 757 760 protected IStatus run(IProgressMonitor monitor) { 761 while (!deferredIdentifiers.isEmpty()) { 762 Identifier identifier = (Identifier) deferredIdentifiers.remove(0); 763 Set activityIds = new HashSet (); 764 for (Iterator iterator = definedActivityIds.iterator(); iterator 765 .hasNext();) { 766 String activityId = (String ) iterator.next(); 767 Activity activity = (Activity) getActivity(activityId); 768 769 if (activity.isMatch(identifier.getId())) { 770 activityIds.add(activityId); 771 } 772 } 773 774 boolean activityIdsChanged = identifier.setActivityIds(activityIds); 775 if (activityIdsChanged) { 776 IdentifierEvent identifierEvent = new IdentifierEvent(identifier, activityIdsChanged, 777 false); 778 Map identifierEventsByIdentifierId = new HashMap (1); 779 identifierEventsByIdentifierId.put(identifier.getId(), 780 identifierEvent); 781 notifyIdentifiers(identifierEventsByIdentifierId); 782 } 783 } 784 return Status.OK_STATUS; 785 } 786 }; 787 deferredIdentifierJob.setSystem(true); 788 } 789 return deferredIdentifierJob; 790 } 791 } 792 | Popular Tags |