1 11 package org.eclipse.team.internal.core.subscribers; 12 13 import java.util.*; 14 15 import org.eclipse.core.resources.IResource; 16 import org.eclipse.core.resources.mapping.ResourceMapping; 17 import org.eclipse.core.resources.mapping.ResourceTraversal; 18 import org.eclipse.core.runtime.*; 19 import org.eclipse.team.core.mapping.ISynchronizationScope; 20 import org.eclipse.team.core.mapping.ISynchronizationScopeChangeListener; 21 22 27 public abstract class AbstractSynchronizationScope implements ISynchronizationScope { 28 29 private ListenerList listeners = new ListenerList(ListenerList.IDENTITY); 30 31 34 public IResource[] getRoots() { 35 List result = new ArrayList(); 36 ResourceTraversal[] traversals = getTraversals(); 37 for (int i = 0; i < traversals.length; i++) { 38 ResourceTraversal traversal = traversals[i]; 39 IResource[] resources = traversal.getResources(); 40 for (int j = 0; j < resources.length; j++) { 41 IResource resource = resources[j]; 42 accumulateRoots(result, resource); 43 } 44 } 45 return (IResource[]) result.toArray(new IResource[result.size()]); 46 } 47 48 51 public boolean contains(IResource resource) { 52 ResourceTraversal[] traversals = getTraversals(); 53 for (int i = 0; i < traversals.length; i++) { 54 ResourceTraversal traversal = traversals[i]; 55 if (traversal.contains(resource)) 56 return true; 57 } 58 return false; 59 } 60 61 65 private void accumulateRoots(List roots, IResource resource) { 66 IPath resourcePath = resource.getFullPath(); 67 for (Iterator iter = roots.iterator(); iter.hasNext();) { 68 IResource root = (IResource) iter.next(); 69 IPath rootPath = root.getFullPath(); 70 if (rootPath.isPrefixOf(resourcePath)) 72 return; 73 if (resourcePath.isPrefixOf(rootPath)) 75 iter.remove(); 76 } 77 roots.add(resource); 79 } 80 81 86 public void fireTraversalsChangedEvent(final ResourceTraversal[] newTraversals, final ResourceMapping[] newMappings) { 87 Object [] allListeners = listeners.getListeners(); 88 for (int i = 0; i < allListeners.length; i++) { 89 final Object listener = allListeners[i]; 90 SafeRunner.run(new ISafeRunnable() { 91 public void run() throws Exception { 92 ((ISynchronizationScopeChangeListener)listener).scopeChanged(AbstractSynchronizationScope.this, newMappings, newTraversals); 93 } 94 public void handleException(Throwable exception) { 95 } 97 }); 98 } 99 } 100 101 104 public void addScopeChangeListener(ISynchronizationScopeChangeListener listener) { 105 listeners.add(listener); 106 } 107 108 111 public void removeScopeChangeListener(ISynchronizationScopeChangeListener listener) { 112 listeners.remove(listener); 113 } 114 115 } 116 | Popular Tags |