1 11 package org.eclipse.team.ui.synchronize; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.core.resources.IResource; 17 import org.eclipse.team.core.subscribers.ISubscriberChangeEvent; 18 import org.eclipse.team.ui.mapping.ITeamStateChangeEvent; 19 20 27 public class TeamStateChangeEvent implements ITeamStateChangeEvent { 28 29 private Set changes = new HashSet (); 30 private Set addedRoots = new HashSet (); 31 private Set removedRoots = new HashSet (); 32 33 public TeamStateChangeEvent() { 34 super(); 35 } 36 37 41 public TeamStateChangeEvent(ISubscriberChangeEvent[] deltas) { 42 for (int i = 0; i < deltas.length; i++) { 43 ISubscriberChangeEvent event = deltas[i]; 44 IResource resource = event.getResource(); 45 if ((event.getFlags() & ISubscriberChangeEvent.ROOT_ADDED) != 0) 46 rootAdded(resource); 47 if ((event.getFlags() & ISubscriberChangeEvent.ROOT_REMOVED) != 0) 48 rootRemoved(resource); 49 if ((event.getFlags() & ISubscriberChangeEvent.SYNC_CHANGED) != 0) 50 changed(resource); 51 while (resource.getType() != IResource.PROJECT) { 53 resource = resource.getParent(); 54 changed(resource); 55 } 56 } 57 } 58 59 63 public void changed(IResource resource) { 64 changes.add(resource); 65 } 66 67 71 public void rootRemoved(IResource resource) { 72 removedRoots.add(resource); 73 } 74 75 79 public void rootAdded(IResource resource) { 80 addedRoots.add(resource); 81 } 82 83 86 public IResource[] getAddedRoots() { 87 return (IResource[]) addedRoots.toArray(new IResource[addedRoots.size()]); 88 } 89 90 93 public IResource[] getRemovedRoots() { 94 return (IResource[]) removedRoots.toArray(new IResource[removedRoots.size()]); 95 } 96 97 100 public IResource[] getChangedResources() { 101 return (IResource[]) changes.toArray(new IResource[changes.size()]); 102 } 103 104 107 public boolean hasChange(IResource resource) { 108 if (changes.contains(resource)) 109 return true; 110 if (isChildOfChangedRoot(resource)) { 111 return true; 112 } 113 return false; 114 } 115 116 private boolean isChildOfChangedRoot(IResource resource) { 117 if (resource == null || resource.getType() == IResource.ROOT) 118 return false; 119 if (addedRoots.contains(resource) || removedRoots.contains(resource)) 120 return true; 121 return isChildOfChangedRoot(resource.getParent()); 122 } 123 124 } 125 | Popular Tags |