1 11 package org.eclipse.ui.internal.navigator; 12 13 import java.util.ArrayList ; 14 import java.util.Collection ; 15 import java.util.Collections ; 16 import java.util.HashMap ; 17 import java.util.HashSet ; 18 import java.util.Iterator ; 19 import java.util.List ; 20 import java.util.Map ; 21 import java.util.Set ; 22 import java.util.SortedSet ; 23 import java.util.TreeSet ; 24 import java.util.WeakHashMap ; 25 26 import org.eclipse.core.runtime.ISafeRunnable; 27 import org.eclipse.core.runtime.SafeRunner; 28 import org.eclipse.jface.viewers.ILabelProvider; 29 import org.eclipse.jface.viewers.ITreeContentProvider; 30 import org.eclipse.jface.viewers.StructuredViewer; 31 import org.eclipse.jface.viewers.Viewer; 32 import org.eclipse.swt.widgets.Shell; 33 import org.eclipse.ui.IMemento; 34 import org.eclipse.ui.internal.navigator.dnd.NavigatorDnDService; 35 import org.eclipse.ui.internal.navigator.extensions.ExtensionPriorityComparator; 36 import org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor; 37 import org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptorManager; 38 import org.eclipse.ui.internal.navigator.extensions.NavigatorContentExtension; 39 import org.eclipse.ui.internal.navigator.extensions.NavigatorViewerDescriptor; 40 import org.eclipse.ui.internal.navigator.extensions.NavigatorViewerDescriptorManager; 41 import org.eclipse.ui.internal.navigator.extensions.StructuredViewerManager; 42 import org.eclipse.ui.internal.navigator.sorters.NavigatorSorterService; 43 import org.eclipse.ui.navigator.IDescriptionProvider; 44 import org.eclipse.ui.navigator.IExtensionActivationListener; 45 import org.eclipse.ui.navigator.IExtensionStateModel; 46 import org.eclipse.ui.navigator.IMementoAware; 47 import org.eclipse.ui.navigator.INavigatorActivationService; 48 import org.eclipse.ui.navigator.INavigatorContentDescriptor; 49 import org.eclipse.ui.navigator.INavigatorContentExtension; 50 import org.eclipse.ui.navigator.INavigatorContentService; 51 import org.eclipse.ui.navigator.INavigatorContentServiceListener; 52 import org.eclipse.ui.navigator.INavigatorDnDService; 53 import org.eclipse.ui.navigator.INavigatorFilterService; 54 import org.eclipse.ui.navigator.INavigatorPipelineService; 55 import org.eclipse.ui.navigator.INavigatorSaveablesService; 56 import org.eclipse.ui.navigator.INavigatorSorterService; 57 import org.eclipse.ui.navigator.INavigatorViewerDescriptor; 58 59 73 public class NavigatorContentService implements IExtensionActivationListener, 74 IMementoAware, INavigatorContentService { 75 76 private static final NavigatorContentDescriptorManager CONTENT_DESCRIPTOR_REGISTRY = NavigatorContentDescriptorManager 77 .getInstance(); 78 79 private static final NavigatorViewerDescriptorManager VIEWER_DESCRIPTOR_REGISTRY = NavigatorViewerDescriptorManager 80 .getInstance(); 81 82 private static final ITreeContentProvider[] NO_CONTENT_PROVIDERS = new ITreeContentProvider[0]; 83 84 private static final ILabelProvider[] NO_LABEL_PROVIDERS = new ILabelProvider[0]; 85 86 private static final INavigatorContentDescriptor[] NO_DESCRIPTORS = new INavigatorContentDescriptor[0]; 87 88 private static final String [] NO_EXTENSION_IDS = new String [0]; 89 90 private final NavigatorViewerDescriptor viewerDescriptor; 91 92 private final List listeners = new ArrayList (); 93 94 98 private final Map contentExtensions = new HashMap (); 99 100 private StructuredViewerManager structuredViewerManager; 101 102 private ITreeContentProvider[] rootContentProviders; 103 104 private WeakHashMap contributionMemory; 105 106 private ITreeContentProvider contentProvider; 107 108 private ILabelProvider labelProvider; 109 110 private final VisibilityAssistant assistant; 111 112 private NavigatorFilterService navigatorFilterService; 113 114 private INavigatorSorterService navigatorSorterService; 115 116 private INavigatorPipelineService navigatorPipelineService; 117 118 private INavigatorDnDService navigatorDnDService; 119 120 private INavigatorActivationService navigatorActivationService; 121 122 private NavigatorSaveablesService navigatorSaveablesService; 123 124 private NavigatorExtensionStateService navigatorExtensionStateService; 125 126 private IDescriptionProvider descriptionProvider; 127 128 private boolean contentProviderInitialized; 129 130 private boolean labelProviderInitialized; 131 132 137 public NavigatorContentService(String aViewerId) { 138 super(); 139 aViewerId = aViewerId != null ? aViewerId : ""; viewerDescriptor = VIEWER_DESCRIPTOR_REGISTRY 141 .getNavigatorViewerDescriptor(aViewerId); 142 assistant = new VisibilityAssistant(viewerDescriptor, 143 getActivationService()); 144 getActivationService().addExtensionActivationListener(this); 145 } 146 147 154 public NavigatorContentService(String aViewerId, StructuredViewer aViewer) { 155 this(aViewerId); 156 structuredViewerManager = new StructuredViewerManager(aViewer); 157 } 158 159 public String [] getVisibleExtensionIds() { 160 161 List visibleExtensionIds = new ArrayList (); 162 163 NavigatorContentDescriptor[] descriptors = CONTENT_DESCRIPTOR_REGISTRY 164 .getAllContentDescriptors(); 165 for (int i = 0; i < descriptors.length; i++) { 166 if (assistant.isVisible(descriptors[i].getId())) { 167 visibleExtensionIds.add(descriptors[i].getId()); 168 } 169 } 170 if (visibleExtensionIds.isEmpty()) { 171 return NO_EXTENSION_IDS; 172 } 173 return (String []) visibleExtensionIds 174 .toArray(new String [visibleExtensionIds.size()]); 175 176 } 177 178 public INavigatorContentDescriptor[] getVisibleExtensions() { 179 List visibleDescriptors = new ArrayList (); 180 181 NavigatorContentDescriptor[] descriptors = CONTENT_DESCRIPTOR_REGISTRY 182 .getAllContentDescriptors(); 183 for (int i = 0; i < descriptors.length; i++) { 184 if (assistant.isVisible(descriptors[i].getId())) { 185 visibleDescriptors.add(descriptors[i]); 186 } 187 } 188 if (visibleDescriptors.isEmpty()) { 189 return NO_DESCRIPTORS; 190 } 191 return (INavigatorContentDescriptor[]) visibleDescriptors 192 .toArray(new INavigatorContentDescriptor[visibleDescriptors 193 .size()]); 194 195 } 196 197 INavigatorContentDescriptor[] getActiveDescriptorsWithSaveables() { 198 List result = new ArrayList (); 199 200 NavigatorContentDescriptor[] descriptors = CONTENT_DESCRIPTOR_REGISTRY 201 .getContentDescriptorsWithSaveables(); 202 for (int i = 0; i < descriptors.length; i++) { 203 if (assistant.isVisible(descriptors[i].getId()) 204 && assistant.isActive(descriptors[i])) { 205 result.add(descriptors[i]); 206 } 207 } 208 if (result.isEmpty()) { 209 return NO_DESCRIPTORS; 210 } 211 return (INavigatorContentDescriptor[]) result 212 .toArray(new INavigatorContentDescriptor[result.size()]); 213 214 } 215 216 222 public INavigatorContentDescriptor[] bindExtensions(String [] extensionIds, 223 boolean isRoot) { 224 if (extensionIds == null || extensionIds.length == 0) { 225 return NO_DESCRIPTORS; 226 } 227 228 for (int i = 0; i < extensionIds.length; i++) { 229 assistant.bindExtensions(extensionIds, isRoot); 230 } 231 Set boundDescriptors = new HashSet (); 232 INavigatorContentDescriptor descriptor; 233 for (int i = 0; i < extensionIds.length; i++) { 234 descriptor = CONTENT_DESCRIPTOR_REGISTRY 235 .getContentDescriptor(extensionIds[i]); 236 if (descriptor != null) { 237 boundDescriptors.add(descriptor); 238 } 239 } 240 241 if (boundDescriptors.size() == 0) { 242 return NO_DESCRIPTORS; 243 } 244 return (INavigatorContentDescriptor[]) boundDescriptors 245 .toArray(new INavigatorContentDescriptor[boundDescriptors 246 .size()]); 247 248 } 249 250 255 public ITreeContentProvider createCommonContentProvider() { 256 if (contentProviderInitialized) { 257 return contentProvider; 258 } 259 synchronized (this) { 260 if (contentProvider == null) { 261 contentProvider = new NavigatorContentServiceContentProvider( 262 this); 263 } 264 contentProviderInitialized = true; 265 } 266 return contentProvider; 267 } 268 269 274 public ILabelProvider createCommonLabelProvider() { 275 if (labelProviderInitialized) { 276 return labelProvider; 277 } 278 synchronized (this) { 279 if (labelProvider == null) { 280 labelProvider = new NavigatorContentServiceLabelProvider(this); 281 } 282 labelProviderInitialized = true; 283 } 284 return labelProvider; 285 } 286 287 292 public IDescriptionProvider createCommonDescriptionProvider() { 293 if (descriptionProvider != null) { 294 return descriptionProvider; 295 } 296 synchronized (this) { 297 if (descriptionProvider == null) { 298 descriptionProvider = new NavigatorContentServiceDescriptionProvider( 299 this); 300 } 301 } 302 return descriptionProvider; 303 } 304 305 310 public void dispose() { 311 if (navigatorSaveablesService != null) { 312 assistant.removeListener(navigatorSaveablesService); 313 } 314 for (Iterator contentItr = contentExtensions.values().iterator(); contentItr 315 .hasNext();) { 316 ((NavigatorContentExtension) contentItr.next()).dispose(); 317 } 318 getActivationService().removeExtensionActivationListener(this); 319 assistant.dispose(); 320 } 321 322 protected void updateService(Viewer aViewer, Object anOldInput, 323 Object aNewInput) { 324 325 synchronized (this) { 326 327 if (structuredViewerManager == null) { 328 structuredViewerManager = new StructuredViewerManager(aViewer); 329 structuredViewerManager.inputChanged(anOldInput, aNewInput); 330 } else { 331 structuredViewerManager.inputChanged(aViewer, anOldInput, 332 aNewInput); 333 } 334 335 for (Iterator contentItr = contentExtensions.values().iterator(); contentItr 336 .hasNext();) { 337 structuredViewerManager 338 .initialize(((NavigatorContentExtension) contentItr 339 .next()).getContentProvider()); 340 } 341 342 rootContentProviders = extractContentProviders(findRootContentExtensions(aNewInput)); 343 } 344 } 345 346 public IExtensionStateModel findStateModel(String anExtensionId) { 347 if (anExtensionId == null) { 348 return null; 349 } 350 INavigatorContentDescriptor desc = CONTENT_DESCRIPTOR_REGISTRY 351 .getContentDescriptor(anExtensionId); 352 if (desc == null) { 353 return null; 354 } 355 INavigatorContentExtension ext = getExtension(desc); 356 if (ext == null) { 357 return null; 358 } 359 return ext.getStateModel(); 360 } 361 362 380 public ITreeContentProvider[] findParentContentProviders(Object anElement) { 381 return extractContentProviders(findContentExtensionsWithPossibleChild(anElement)); 382 } 383 384 401 public ITreeContentProvider[] findRootContentProviders(Object anElement) { 402 if (rootContentProviders != null) { 403 return rootContentProviders; 404 } 405 synchronized (this) { 406 if (rootContentProviders == null) { 407 rootContentProviders = extractContentProviders(findRootContentExtensions(anElement)); 408 409 } 410 } 411 return rootContentProviders; 412 } 413 414 427 public ILabelProvider[] findRelevantLabelProviders(Object anElement) { 428 return extractLabelProviders(findContentExtensionsWithPossibleChild( 429 anElement, false)); 430 } 431 432 445 public Set findRootContentExtensions(Object anElement) { 446 return findRootContentExtensions(anElement, true); 447 } 448 449 465 public Set findRootContentExtensions(Object anElement, 466 boolean toRespectViewerRoots) { 467 468 SortedSet rootExtensions = new TreeSet ( 469 ExtensionPriorityComparator.INSTANCE); 470 if (toRespectViewerRoots 471 && viewerDescriptor.hasOverriddenRootExtensions()) { 472 473 NavigatorContentDescriptor[] descriptors = CONTENT_DESCRIPTOR_REGISTRY 474 .getAllContentDescriptors(); 475 476 NavigatorContentExtension extension = null; 477 for (int i = 0; i < descriptors.length; i++) { 478 if (isActive(descriptors[i].getId()) 479 && isRootExtension(descriptors[i].getId())) { 480 extension = getExtension(descriptors[i]); 481 if (!extension.hasLoadingFailed()) { 482 rootExtensions.add(extension); 483 } 484 } 485 } 486 } 487 if (rootExtensions.isEmpty()) { 488 return findContentExtensionsByTriggerPoint(anElement); 489 } 490 return rootExtensions; 491 } 492 493 504 public Set findOverrideableContentExtensionsByTriggerPoint(Object anElement) { 505 Set overrideableExtensions = new TreeSet ( 506 ExtensionPriorityComparator.INSTANCE); 507 Set descriptors = findDescriptorsByTriggerPoint(anElement); 508 for (Iterator iter = descriptors.iterator(); iter.hasNext();) { 509 INavigatorContentDescriptor descriptor = (INavigatorContentDescriptor) iter 510 .next(); 511 if (descriptor.hasOverridingExtensions()) { 512 overrideableExtensions.add(getExtension(descriptor)); 513 } 514 } 515 return overrideableExtensions; 516 } 517 518 529 public Set findOverrideableContentExtensionsForPossibleChild( 530 Object anElement) { 531 Set overrideableExtensions = new TreeSet ( 532 ExtensionPriorityComparator.INSTANCE); 533 Set descriptors = findDescriptorsWithPossibleChild(anElement, false); 534 for (Iterator iter = descriptors.iterator(); iter.hasNext();) { 535 INavigatorContentDescriptor descriptor = (INavigatorContentDescriptor) iter 536 .next(); 537 if (descriptor.hasOverridingExtensions()) { 538 overrideableExtensions.add(getExtension(descriptor)); 539 } 540 } 541 return overrideableExtensions; 542 } 543 544 549 public INavigatorContentDescriptor getContentDescriptorById( 550 String anExtensionId) { 551 return CONTENT_DESCRIPTOR_REGISTRY.getContentDescriptor(anExtensionId); 552 } 553 554 563 public INavigatorContentExtension getContentExtensionById( 564 String anExtensionId) { 565 NavigatorContentDescriptor descriptor = CONTENT_DESCRIPTOR_REGISTRY 566 .getContentDescriptor(anExtensionId); 567 if (descriptor != null) 568 return getExtension(descriptor); 569 return null; 570 } 571 572 583 public Set findContentExtensionsByTriggerPoint(Object anElement) { 584 return findContentExtensionsByTriggerPoint(anElement, true); 585 } 586 587 600 public Set findContentExtensionsByTriggerPoint(Object anElement, 601 boolean toLoadIfNecessary) { 602 Set enabledDescriptors = findDescriptorsByTriggerPoint(anElement); 603 return extractDescriptorInstances(enabledDescriptors, toLoadIfNecessary); 604 } 605 606 617 public Set findContentExtensionsWithPossibleChild(Object anElement) { 618 return findContentExtensionsWithPossibleChild(anElement, true); 619 } 620 621 634 public Set findContentExtensionsWithPossibleChild(Object anElement, 635 boolean toLoadIfNecessary) { 636 Set enabledDescriptors = findDescriptorsWithPossibleChild(anElement); 637 return extractDescriptorInstances(enabledDescriptors, toLoadIfNecessary); 638 } 639 640 649 public synchronized void rememberContribution( 650 NavigatorContentDescriptor source, Object [] elements) { 651 652 if (source != null && elements != null) { 653 for (int i = 0; i < elements.length; i++) { 654 getContributionMemory().put(elements[i], source); 655 } 656 } 657 } 658 659 668 public synchronized void rememberContribution( 669 NavigatorContentDescriptor source, Object element) { 670 if (source != null && element != null) { 671 getContributionMemory().put(element, source); 672 } 673 } 674 675 682 public NavigatorContentDescriptor getSourceOfContribution(Object element) { 683 return (NavigatorContentDescriptor) getContributionMemory() 684 .get(element); 685 } 686 687 690 public Map getContributionMemory() { 691 if (contributionMemory != null) { 692 return contributionMemory; 693 } 694 synchronized (this) { 695 if (contributionMemory == null) { 696 contributionMemory = new WeakHashMap (); 697 } 698 } 699 700 return contributionMemory; 701 } 702 703 715 public Set findDescriptorsByTriggerPoint(Object anElement) { 716 717 NavigatorContentDescriptor descriptor = getSourceOfContribution(anElement); 718 Set result = new TreeSet (ExtensionPriorityComparator.INSTANCE); 719 if (descriptor != null) { 720 result.add(descriptor); 721 } 722 result.addAll(CONTENT_DESCRIPTOR_REGISTRY 723 .findDescriptorsForTriggerPoint(anElement, assistant)); 724 return result; 725 } 726 727 738 public Set findDescriptorsWithPossibleChild(Object anElement) { 739 return findDescriptorsWithPossibleChild(anElement, true); 740 } 741 742 755 public Set findDescriptorsWithPossibleChild(Object anElement, 756 boolean toComputeOverrides) { 757 758 NavigatorContentDescriptor descriptor = getSourceOfContribution(anElement); 759 Set result = new TreeSet (ExtensionPriorityComparator.INSTANCE); 760 if (descriptor != null) { 761 result.add(descriptor); 762 } 763 result.addAll(CONTENT_DESCRIPTOR_REGISTRY 764 .findDescriptorsForPossibleChild(anElement, assistant, 765 toComputeOverrides)); 766 return result; 767 } 768 769 775 public void onExtensionActivation(String aViewerId, 776 String [] aNavigatorExtensionId, boolean toEnable) { 777 synchronized (this) { 778 try { 779 NavigatorContentDescriptor key; 780 NavigatorContentExtension extension; 781 for (Iterator iter = contentExtensions.keySet().iterator(); iter 782 .hasNext();) { 783 key = (NavigatorContentDescriptor) iter.next(); 784 INavigatorActivationService activation = getActivationService(); 785 if (!activation.isNavigatorExtensionActive(key.getId())) { 786 extension = (NavigatorContentExtension) contentExtensions 787 .get(key); 788 iter.remove(); 789 793 if (extension != null) { 794 extension.dispose(); 795 } 796 } 797 } 798 } catch (RuntimeException e) { 799 String msg = e.getMessage() != null ? e.getMessage() : e 800 .toString(); 801 NavigatorPlugin.logError(0, msg, e); 802 } 803 } 804 update(); 805 } 806 807 812 public void update() { 813 rootContentProviders = null; 814 if (structuredViewerManager != null) { 815 structuredViewerManager.safeRefresh(); 816 } 817 } 818 819 824 public final String getViewerId() { 825 return viewerDescriptor.getViewerId(); 826 } 827 828 834 public final NavigatorContentExtension getExtension( 835 INavigatorContentDescriptor aDescriptorKey) { 836 return getExtension(aDescriptorKey, true); 837 } 838 839 846 public final NavigatorContentExtension getExtension( 847 INavigatorContentDescriptor aDescriptorKey, 848 boolean toLoadIfNecessary) { 849 850 NavigatorContentExtension extension = (NavigatorContentExtension) contentExtensions 851 .get(aDescriptorKey); 852 if (extension != null || !toLoadIfNecessary) { 853 return extension; 854 } 855 856 861 synchronized (this) { 862 extension = (NavigatorContentExtension) contentExtensions 863 .get(aDescriptorKey); 864 if (extension == null) { 865 contentExtensions.put(aDescriptorKey, 866 (extension = new NavigatorContentExtension( 867 (NavigatorContentDescriptor) aDescriptorKey, 868 this, structuredViewerManager))); 869 notifyListeners(extension); 870 } 871 } 872 return extension; 873 874 } 875 876 881 public INavigatorViewerDescriptor getViewerDescriptor() { 882 return viewerDescriptor; 883 } 884 885 890 public void restoreState(final IMemento aMemento) { 891 synchronized (this) { 892 List runnables = new ArrayList (); 893 for (Iterator extensionItr = getExtensions().iterator(); extensionItr 894 .hasNext();) { 895 final NavigatorContentExtension element = (NavigatorContentExtension) extensionItr 896 .next(); 897 ISafeRunnable runnable = new ISafeRunnable() { 898 public void run() throws Exception { 899 element.restoreState(aMemento); 900 } 901 902 public void handleException(Throwable exception) { 903 NavigatorPlugin.logError(0, 904 "Could not restore state for Common Navigator content extension" + element.getId(), exception); 906 } 907 }; 908 runnables.add(runnable); 909 } 910 for (Iterator iterator = runnables.iterator(); iterator.hasNext();) { 911 ISafeRunnable runnable = (ISafeRunnable) iterator.next(); 912 SafeRunner.run(runnable); 913 } 914 } 915 } 916 917 922 public void saveState(final IMemento aMemento) { 923 synchronized (this) { 924 925 List runnables = new ArrayList (); 926 for (Iterator extensionItr = getExtensions().iterator(); extensionItr 927 .hasNext();) { 928 final NavigatorContentExtension element = (NavigatorContentExtension) extensionItr 929 .next(); 930 ISafeRunnable runnable = new ISafeRunnable() { 931 public void run() throws Exception { 932 element.saveState(aMemento); 933 } 934 935 public void handleException(Throwable exception) { 936 NavigatorPlugin.logError(0, 937 "Could not save state for Common Navigator content extension" + element.getId(), exception); 939 } 940 }; 941 runnables.add(runnable); 942 } 943 for (Iterator iterator = runnables.iterator(); iterator.hasNext();) { 944 ISafeRunnable runnable = (ISafeRunnable) iterator.next(); 945 SafeRunner.run(runnable); 946 } 947 } 948 } 949 950 public boolean isActive(String anExtensionId) { 951 return assistant.isActive(anExtensionId); 952 } 953 954 public boolean isVisible(String anExtensionId) { 955 return assistant.isVisible(anExtensionId); 956 } 957 958 protected final Collection getExtensions() { 959 return (contentExtensions.size() > 0) ? Collections 960 .unmodifiableCollection(contentExtensions.values()) 961 : Collections.EMPTY_LIST; 962 } 963 964 969 public void addListener(INavigatorContentServiceListener aListener) { 970 listeners.add(aListener); 971 } 972 973 978 public INavigatorFilterService getFilterService() { 979 if (navigatorFilterService == null) { 980 navigatorFilterService = new NavigatorFilterService(this); 981 } 982 return navigatorFilterService; 983 } 984 985 990 public INavigatorSorterService getSorterService() { 991 if (navigatorSorterService == null) { 992 navigatorSorterService = new NavigatorSorterService(this); 993 } 994 return navigatorSorterService; 995 } 996 997 1002 public INavigatorPipelineService getPipelineService() { 1003 if (navigatorPipelineService == null) { 1004 navigatorPipelineService = new NavigatorPipelineService(this); 1005 } 1006 return navigatorPipelineService; 1007 } 1008 1009 1014 public INavigatorDnDService getDnDService() { 1015 if (navigatorDnDService == null) { 1016 navigatorDnDService = new NavigatorDnDService(this); 1017 } 1018 return navigatorDnDService; 1019 } 1020 1021 1026 public INavigatorActivationService getActivationService() { 1027 1028 if (navigatorActivationService == null) { 1029 navigatorActivationService = new NavigatorActivationService(this); 1030 } 1031 return navigatorActivationService; 1032 } 1033 1034 1039 public INavigatorSaveablesService getSaveablesService() { 1040 synchronized (this) { 1041 if (navigatorSaveablesService == null) { 1042 navigatorSaveablesService = new NavigatorSaveablesService(this); 1043 assistant.addListener(navigatorSaveablesService); 1044 } 1045 return navigatorSaveablesService; 1046 } 1047 } 1048 1049 1055 public NavigatorExtensionStateService getExtensionStateService() { 1056 if (navigatorExtensionStateService == null) { 1057 navigatorExtensionStateService = new NavigatorExtensionStateService( 1058 this); 1059 } 1060 return navigatorExtensionStateService; 1061 } 1062 1063 1068 public Shell getShell() { 1069 if (structuredViewerManager != null 1070 && structuredViewerManager.getViewer() != null) { 1071 return structuredViewerManager.getViewer().getControl().getShell(); 1072 } 1073 return null; 1074 } 1075 1076 protected boolean isRootExtension(String anExtensionId) { 1077 return assistant.isRootExtension(anExtensionId); 1078 } 1079 1080 1085 public void removeListener(INavigatorContentServiceListener aListener) { 1086 listeners.remove(aListener); 1087 } 1088 1089 1094 public String toString() { 1095 return "ContentService[" + viewerDescriptor.getViewerId() + "]"; } 1097 1098 private void notifyListeners(NavigatorContentExtension aDescriptorInstance) { 1099 1100 if (listeners.size() == 0) { 1101 return; 1102 } 1103 INavigatorContentServiceListener listener = null; 1104 List failedListeners = null; 1105 for (Iterator listenersItr = listeners.iterator(); listenersItr 1106 .hasNext();) { 1107 try { 1108 listener = (INavigatorContentServiceListener) listenersItr 1109 .next(); 1110 listener.onLoad(aDescriptorInstance); 1111 } catch (RuntimeException re) { 1112 if (failedListeners == null) { 1113 failedListeners = new ArrayList (); 1114 } 1115 failedListeners.add(listener); 1116 } 1117 } 1118 if (failedListeners != null) { 1119 listeners.removeAll(failedListeners); 1120 } 1121 } 1122 1123 private ITreeContentProvider[] extractContentProviders( 1124 Set theDescriptorInstances) { 1125 if (theDescriptorInstances.size() == 0) { 1126 return NO_CONTENT_PROVIDERS; 1127 } 1128 List resultProvidersList = new ArrayList (); 1129 for (Iterator itr = theDescriptorInstances.iterator(); itr.hasNext();) { 1130 resultProvidersList.add(((NavigatorContentExtension) itr.next()) 1131 .internalGetContentProvider()); 1132 } 1133 return (ITreeContentProvider[]) resultProvidersList 1134 .toArray(new ITreeContentProvider[resultProvidersList.size()]); 1135 } 1136 1137 private Set extractDescriptorInstances(Set theDescriptors, 1138 boolean toLoadAllIfNecessary) { 1139 if (theDescriptors.size() == 0) { 1140 return Collections.EMPTY_SET; 1141 } 1142 Set resultInstances = new TreeSet (ExtensionPriorityComparator.INSTANCE); 1143 for (Iterator descriptorIter = theDescriptors.iterator(); descriptorIter 1144 .hasNext();) { 1145 NavigatorContentExtension extension = getExtension( 1146 (NavigatorContentDescriptor) descriptorIter.next(), 1147 toLoadAllIfNecessary); 1148 if (extension != null) { 1149 resultInstances.add(extension); 1150 1151 } 1152 } 1153 return resultInstances; 1154 } 1155 1156 private ILabelProvider[] extractLabelProviders(Set theDescriptorInstances) { 1157 if (theDescriptorInstances.size() == 0) { 1158 return NO_LABEL_PROVIDERS; 1159 } 1160 List resultProvidersList = new ArrayList (); 1161 for (Iterator itr = theDescriptorInstances.iterator(); itr.hasNext();) { 1162 resultProvidersList.add(((NavigatorContentExtension) itr.next()) 1163 .getLabelProvider()); 1164 } 1165 return (ILabelProvider[]) resultProvidersList 1166 .toArray(new ILabelProvider[resultProvidersList.size()]); 1167 } 1168 1169} 1170 | Popular Tags |