1 11 12 package org.eclipse.ui.internal.navigator; 13 14 import java.util.Arrays ; 15 import java.util.Iterator ; 16 import java.util.LinkedHashSet ; 17 import java.util.Set ; 18 19 import org.eclipse.jface.viewers.TreePath; 20 import org.eclipse.ui.internal.navigator.extensions.NavigatorContentDescriptor; 21 import org.eclipse.ui.internal.navigator.extensions.NavigatorContentExtension; 22 import org.eclipse.ui.navigator.INavigatorContentDescriptor; 23 import org.eclipse.ui.navigator.INavigatorPipelineService; 24 import org.eclipse.ui.navigator.IPipelinedTreeContentProvider; 25 import org.eclipse.ui.navigator.PipelinedShapeModification; 26 import org.eclipse.ui.navigator.PipelinedViewerUpdate; 27 28 32 public class NavigatorPipelineService implements INavigatorPipelineService { 33 34 private NavigatorContentService contentService; 35 36 42 public NavigatorPipelineService(NavigatorContentService aContentService) { 43 contentService = aContentService; 44 } 45 46 71 public PipelinedShapeModification interceptAdd( 72 PipelinedShapeModification anAddModification) { 73 74 ContributorTrackingSet trackedSet =(ContributorTrackingSet) anAddModification.getChildren(); 75 76 Set contentDescriptors = contentService.findDescriptorsByTriggerPoint(anAddModification.getParent()); 77 78 79 for (Iterator descriptorsItr = contentDescriptors.iterator(); descriptorsItr.hasNext();) { 80 INavigatorContentDescriptor descriptor = (INavigatorContentDescriptor) descriptorsItr.next(); 81 pipelineInterceptAdd(anAddModification, trackedSet, descriptor); 82 } 83 84 registerContribution(anAddModification.getParent(), anAddModification.getChildren().toArray()); 86 return anAddModification; 87 88 } 89 90 94 private void registerContribution(Object parent, Object [] contributions) { 95 96 Set possibleContributors = contentService.findDescriptorsByTriggerPoint(parent); 98 Set possibleMatches = null; 99 for (int i = 0; i < contributions.length; i++) { 100 possibleMatches = contentService.findDescriptorsWithPossibleChild(contributions[i]); 102 NavigatorContentDescriptor[] descriptors = (NavigatorContentDescriptor[]) possibleMatches.toArray(new NavigatorContentDescriptor[possibleMatches.size()]); 103 for (int indx = possibleMatches.size()-1; indx > -1; indx--) { 104 105 if(possibleContributors.contains(descriptors[indx])) { 107 contentService.rememberContribution(descriptors[indx], contributions[i]); 108 break; 109 } 110 111 } 112 } 113 } 114 115 private void pipelineInterceptAdd(PipelinedShapeModification anAddModification, ContributorTrackingSet trackedSet, INavigatorContentDescriptor descriptor) { 116 if(descriptor.hasOverridingExtensions()) { 117 Set overridingDescriptors = descriptor.getOverriddingExtensions(); 118 for (Iterator overridingDescriptorsItr = overridingDescriptors.iterator(); overridingDescriptorsItr 119 .hasNext();) { 120 INavigatorContentDescriptor overridingDescriptor = (INavigatorContentDescriptor) overridingDescriptorsItr.next(); 121 if(contentService.isVisible(overridingDescriptor.getId()) && contentService.isActive(overridingDescriptor.getId())) { 122 trackedSet.setContributor((NavigatorContentDescriptor) overridingDescriptor); 123 NavigatorContentExtension extension = contentService.getExtension(overridingDescriptor); 124 ((IPipelinedTreeContentProvider) extension.internalGetContentProvider()).interceptAdd(anAddModification); 125 trackedSet.setContributor(null); 126 pipelineInterceptAdd(anAddModification, trackedSet, overridingDescriptor); 127 } 128 } 129 } 130 } 131 132 133 158 public PipelinedShapeModification interceptRemove( 159 PipelinedShapeModification aRemoveModification) { 160 161 ContributorTrackingSet trackedSet =(ContributorTrackingSet) aRemoveModification.getChildren(); 162 163 Set interestedExtensions = new LinkedHashSet (); 164 for (Iterator iter = trackedSet.iterator(); iter.hasNext();) { 165 Object element = (Object ) iter.next(); 166 if(element instanceof TreePath) { 167 interestedExtensions.addAll(contentService.findOverrideableContentExtensionsForPossibleChild(((TreePath)element).getLastSegment())); 168 } else { 169 interestedExtensions = contentService.findOverrideableContentExtensionsForPossibleChild(element); 170 171 } 172 } 173 for (Iterator overridingExtensionsIter = interestedExtensions.iterator(); overridingExtensionsIter.hasNext();) 174 pipelineInterceptRemove(aRemoveModification, trackedSet, (NavigatorContentExtension) overridingExtensionsIter.next()); 175 return aRemoveModification; 176 } 177 178 179 private void pipelineInterceptRemove(PipelinedShapeModification aRemoveModification, ContributorTrackingSet trackedSet, NavigatorContentExtension overrideableExtension) { 180 181 182 try { 183 NavigatorContentExtension overridingExtension = null; 184 Set overridingExtensions = new LinkedHashSet (); 185 for (Iterator iter = trackedSet.iterator(); iter.hasNext();) { 186 Object element = (Object ) iter.next(); 187 if(element instanceof TreePath) { 188 overridingExtensions.addAll(Arrays.asList(overrideableExtension.getOverridingExtensionsForPossibleChild(((TreePath)element).getLastSegment()))); 189 } else { 190 overridingExtensions.addAll(Arrays.asList(overrideableExtension.getOverridingExtensionsForPossibleChild(element))); 191 } 192 } 193 194 for (Iterator extensionsItr = overridingExtensions.iterator(); extensionsItr.hasNext();) { 195 overridingExtension = (NavigatorContentExtension) extensionsItr.next(); 196 trackedSet.setContributor((NavigatorContentDescriptor) overridingExtension.getDescriptor()); 197 if (overridingExtension.getContentProvider() instanceof IPipelinedTreeContentProvider) { 198 ((IPipelinedTreeContentProvider) overridingExtension.getContentProvider()).interceptRemove(aRemoveModification); 199 } 200 trackedSet.setContributor(null); 201 if(overridingExtension.getDescriptor().hasOverridingExtensions()) 202 pipelineInterceptRemove(aRemoveModification, trackedSet, overridingExtension); 203 204 } 205 206 } catch (Throwable e) { 207 String msg = e.getMessage() != null ? e.getMessage() : e.toString(); 208 NavigatorPlugin.logError(0, msg, e); 209 } 210 } 211 212 231 public boolean interceptRefresh( 232 PipelinedViewerUpdate aRefreshSynchronization) { 233 234 boolean pipelined = false; 235 Object refreshable = null; 236 Set overrideableExtensions = new LinkedHashSet (); 237 for (Iterator iter = aRefreshSynchronization.getRefreshTargets().iterator(); iter.hasNext();) { 238 refreshable = iter.next(); 239 overrideableExtensions.addAll(contentService.findOverrideableContentExtensionsForPossibleChild(refreshable)); 240 } 241 for (Iterator overrideableExtensionItr = overrideableExtensions.iterator(); overrideableExtensionItr.hasNext();) { 242 pipelined |= pipelineInterceptRefresh((NavigatorContentExtension) overrideableExtensionItr.next(), aRefreshSynchronization, refreshable); 243 } 244 245 return pipelined; 246 247 } 248 249 private boolean pipelineInterceptRefresh(NavigatorContentExtension overrideableExtension, 250 PipelinedViewerUpdate aRefreshSynchronization, Object refreshable) { 251 252 boolean intercepted = false; 253 254 NavigatorContentExtension[] overridingExtensionsForPossibleChild = overrideableExtension.getOverridingExtensionsForPossibleChild(refreshable); 255 for (int i=0; i<overridingExtensionsForPossibleChild.length; i++) { 256 try { 257 if (overridingExtensionsForPossibleChild[i].getContentProvider() instanceof IPipelinedTreeContentProvider) { 258 259 intercepted |= ((IPipelinedTreeContentProvider) overridingExtensionsForPossibleChild[i] 260 .getContentProvider()) 261 .interceptRefresh(aRefreshSynchronization); 262 263 if (overridingExtensionsForPossibleChild[i].getDescriptor().hasOverridingExtensions()) 264 intercepted |= pipelineInterceptRefresh(overridingExtensionsForPossibleChild[i], aRefreshSynchronization, refreshable); 265 } 266 } catch (Throwable e) { 267 String msg = e.getMessage() != null ? e.getMessage() : e.toString(); 268 NavigatorPlugin.logError(0, msg, e); 269 } 270 } 271 272 return intercepted; 273 } 274 275 276 277 297 public boolean interceptUpdate( 298 PipelinedViewerUpdate anUpdateSynchronization) { 299 300 boolean pipelined = false; 301 Object refreshable = null; 302 303 Set overrideableExtensions = new LinkedHashSet (); 304 for (Iterator iter = anUpdateSynchronization.getRefreshTargets().iterator(); iter.hasNext();) { 305 refreshable = iter.next(); 306 overrideableExtensions.addAll(contentService.findOverrideableContentExtensionsForPossibleChild(refreshable)); 307 } 308 for (Iterator overrideableExtensionItr = overrideableExtensions.iterator(); overrideableExtensionItr.hasNext();) { 309 pipelined |= pipelineInterceptUpdate((NavigatorContentExtension) overrideableExtensionItr.next(), anUpdateSynchronization, refreshable); 310 } 311 312 return pipelined; 313 314 } 315 316 private boolean pipelineInterceptUpdate(NavigatorContentExtension overrideableExtension, 317 PipelinedViewerUpdate anUpdateSynchronization, Object refreshable) { 318 319 boolean intercepted = false; 320 NavigatorContentExtension[] overridingExtensionsForPossibleChild = overrideableExtension.getOverridingExtensionsForPossibleChild(refreshable); 321 for (int i=0; i<overridingExtensionsForPossibleChild.length; i++) { 322 try { 323 if (overridingExtensionsForPossibleChild[i].getContentProvider() instanceof IPipelinedTreeContentProvider) { 324 325 intercepted |= ((IPipelinedTreeContentProvider) overridingExtensionsForPossibleChild[i] 326 .getContentProvider()) 327 .interceptUpdate(anUpdateSynchronization); 328 329 if (overridingExtensionsForPossibleChild[i].getDescriptor().hasOverridingExtensions()) 330 intercepted |= pipelineInterceptUpdate(overridingExtensionsForPossibleChild[i], anUpdateSynchronization, refreshable); 331 } 332 } catch (Throwable e) { 333 String msg = e.getMessage() != null ? e.getMessage() : e.toString(); 334 NavigatorPlugin.logError(0, msg, e); 335 } 336 } 337 338 return intercepted; 339 } 340 341 } 342 | Popular Tags |