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.team.core.synchronize.ISyncInfoTreeChangeEvent; 17 import org.eclipse.team.core.synchronize.SyncInfoSet; 18 19 public class SyncInfoTreeChangeEvent extends SyncSetChangedEvent implements ISyncInfoTreeChangeEvent { 20 21 private Set removedSubtrees = new HashSet(); 22 private Set addedSubtrees = new HashSet(); 23 24 public SyncInfoTreeChangeEvent(SyncInfoSet set) { 25 super(set); 26 } 27 28 public void removedSubtreeRoot(IResource root) { 29 if (addedSubtrees.contains(root)) { 30 addedSubtrees.remove(root); 32 } else if (isDescendantOfAddedRoot(root)) { 33 } else { 35 for (Iterator iter = removedSubtrees.iterator(); iter.hasNext();) { 40 IResource element = (IResource) iter.next(); 41 if (root.equals(element)) return; 43 if (isParent(root, element)) { 44 iter.remove(); 46 } else if (isParent(element, root)) { 47 return; 49 } 50 } 51 removedSubtrees.add(root); 52 } 53 } 54 55 private boolean isParent(IResource root, IResource element) { 56 return root.getFullPath().isPrefixOf(element.getFullPath()); 57 } 58 59 public void addedSubtreeRoot(IResource parent) { 60 if (removedSubtrees.contains(parent)) { 61 reset(); 65 } else { 66 if (!isDescendantOfAddedRoot(parent)) { 68 addedSubtrees.add(parent); 69 } 70 } 71 } 72 73 private boolean isDescendantOfAddedRoot(IResource resource) { 74 for (Iterator iter = addedSubtrees.iterator(); iter.hasNext();) { 75 IResource root = (IResource) iter.next(); 76 if (isParent(root, resource)) { 77 return true; 79 } 80 } 81 return false; 82 } 83 84 public IResource[] getAddedSubtreeRoots() { 85 return (IResource[]) addedSubtrees.toArray(new IResource[addedSubtrees.size()]); 86 } 87 88 public IResource[] getRemovedSubtreeRoots() { 89 return (IResource[]) removedSubtrees.toArray(new IResource[removedSubtrees.size()]); 90 } 91 92 public boolean isEmpty() { 93 return super.isEmpty() && removedSubtrees.isEmpty() && addedSubtrees.isEmpty(); 94 } 95 } 96 | Popular Tags |