1 11 package org.eclipse.team.core.variants; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.core.runtime.IPath; 15 import org.eclipse.team.core.Team; 16 import org.eclipse.team.core.TeamException; 17 import org.eclipse.team.core.subscribers.ISubscriberChangeEvent; 18 import org.eclipse.team.core.subscribers.SubscriberChangeEvent; 19 import org.eclipse.team.internal.core.TeamPlugin; 20 import org.eclipse.team.internal.core.subscribers.ThreeWayBaseTree; 21 22 36 public abstract class ThreeWaySubscriber extends ResourceVariantTreeSubscriber implements ISynchronizerChangeListener { 37 38 private ThreeWayResourceComparator comparator; 39 private ThreeWayBaseTree baseTree; 40 private ThreeWayRemoteTree remoteTree; 41 private ThreeWaySynchronizer synchronizer; 42 43 49 protected ThreeWaySubscriber(ThreeWaySynchronizer synchronizer) { 50 this.synchronizer = synchronizer; 51 baseTree = new ThreeWayBaseTree(this); 52 getSynchronizer().addListener(this); 53 } 54 55 58 protected final IResourceVariantTree getBaseTree() { 59 return baseTree; 60 } 61 62 65 protected final IResourceVariantTree getRemoteTree() { 66 if (remoteTree == null) { 67 remoteTree = createRemoteTree(); 68 } 69 return remoteTree; 70 } 71 72 75 public final IResourceVariantComparator getResourceComparator() { 76 if (comparator == null) { 77 comparator = new ThreeWayResourceComparator(this.getSynchronizer()); 78 } 79 return comparator; 80 } 81 82 85 public void syncStateChanged(IResource[] resources) { 86 fireTeamResourceChange(SubscriberChangeEvent.asSyncChangedDeltas(this, resources)); 87 } 88 89 96 public boolean isSupervised(IResource resource) throws TeamException { 97 if (!isChildOfRoot(resource)) return false; 98 if (getSynchronizer().isIgnored(resource)) return false; 99 if (Team.isIgnoredHint(resource)) return false; 100 return true; 101 } 102 103 107 public ThreeWaySynchronizer getSynchronizer() { 108 return synchronizer; 109 } 110 111 120 public abstract IResourceVariant getResourceVariant(IResource resource, byte[] bytes) throws TeamException; 121 122 129 protected abstract ThreeWayRemoteTree createRemoteTree(); 130 131 140 protected void handleRootChanged(IResource resource, boolean added) { 141 if (added) { 142 rootAdded(resource); 143 } else { 144 rootRemoved(resource); 145 } 146 } 147 148 private void rootAdded(IResource resource) { 149 SubscriberChangeEvent delta = new SubscriberChangeEvent(this, ISubscriberChangeEvent.ROOT_ADDED, resource); 150 fireTeamResourceChange(new SubscriberChangeEvent[] { delta }); 151 } 152 153 private void rootRemoved(IResource resource) { 154 try { 155 getSynchronizer().flush(resource, IResource.DEPTH_INFINITE); 156 } catch (TeamException e) { 157 TeamPlugin.log(e); 158 } 159 SubscriberChangeEvent delta = new SubscriberChangeEvent(this, ISubscriberChangeEvent.ROOT_REMOVED, resource); 160 fireTeamResourceChange(new SubscriberChangeEvent[] { delta }); 161 } 162 163 private boolean isChildOfRoot(IResource resource) { 164 IResource[] roots = roots(); 165 IPath fullPath = resource.getFullPath(); 166 for (int i = 0; i < roots.length; i++) { 167 IResource root = roots[i]; 168 if (root.getFullPath().isPrefixOf(fullPath)) { 169 return true; 170 } 171 } 172 return false; 173 } 174 } 175 | Popular Tags |