1 11 package org.eclipse.team.ui.synchronize; 12 13 import org.eclipse.core.resources.IProject; 14 import org.eclipse.core.resources.IResource; 15 import org.eclipse.core.resources.mapping.*; 16 import org.eclipse.core.runtime.CoreException; 17 import org.eclipse.core.runtime.IProgressMonitor; 18 import org.eclipse.team.core.RepositoryProviderType; 19 import org.eclipse.team.core.diff.IDiff; 20 import org.eclipse.team.core.subscribers.*; 21 import org.eclipse.team.internal.ui.Policy; 22 import org.eclipse.team.internal.ui.Utils; 23 import org.eclipse.team.ui.mapping.*; 24 25 35 public class SubscriberTeamStateProvider extends TeamStateProvider implements ISubscriberChangeListener { 36 37 private Subscriber subscriber; 38 39 45 public SubscriberTeamStateProvider(Subscriber subscriber) { 46 this.subscriber = subscriber; 47 subscriber.addListener(this); 48 } 49 50 53 public boolean hasDecoratedState(Object element) throws CoreException { 54 ResourceMapping mapping = Utils.getResourceMapping(element); 55 if (mapping != null) { 56 ResourceTraversal[] traversals = mapping.getTraversals( 57 ResourceMappingContext.LOCAL_CONTEXT, null); 58 for (int i = 0; i < traversals.length; i++) { 59 ResourceTraversal traversal = traversals[i]; 60 IResource[] resources = traversal.getResources(); 61 for (int j = 0; j < resources.length; j++) { 62 IResource resource = resources[j]; 63 if (getSubscriber().isSupervised(resource)) 64 return true; 65 } 66 } 67 } 68 return false; 69 } 70 71 84 protected final int getSynchronizationState(Object element, int stateMask, 85 IProgressMonitor monitor) throws CoreException { 86 ResourceMapping mapping = Utils.getResourceMapping(element); 87 if (mapping != null) { 88 return getSynchronizationState(mapping, stateMask, monitor); 89 } 90 return IDiff.NO_CHANGE; 91 } 92 93 private int getSynchronizationState(ResourceMapping mapping, int stateMask, IProgressMonitor monitor) throws CoreException { 94 ISynchronizationCompareAdapter compareAdapter = (ISynchronizationCompareAdapter)Utils.getAdapter(mapping.getModelProvider(), ISynchronizationCompareAdapter.class); 95 try { 96 if (compareAdapter != null) { 97 int state = compareAdapter.getSynchronizationState(this, mapping, stateMask, monitor); 98 if (state != -1) 99 return state; 100 } 101 return getSubscriber().getState(mapping, stateMask, monitor); 102 } catch (CoreException e) { 103 IProject[] projects = mapping.getProjects(); 104 for (int i = 0; i < projects.length; i++) { 105 IProject project = projects[i]; 106 if (project.isAccessible()) { 109 throw e; 110 } 111 } 112 } 113 return IDiff.NO_CHANGE; 114 } 115 116 119 public ITeamStateDescription getStateDescription(Object element, int stateMask, 120 String [] properties, IProgressMonitor monitor) throws CoreException { 121 monitor = Policy.monitorFor(monitor); 122 if (stateMask == USE_DECORATED_STATE_MASK) 123 stateMask = getDecoratedStateMask(element); 124 return new TeamStateDescription(getSynchronizationState(element, stateMask, monitor)); 125 } 126 127 130 public ResourceMappingContext getResourceMappingContext(Object element) { 131 return new SubscriberResourceMappingContext(subscriber, false); 132 } 133 134 139 protected final Subscriber getSubscriber() { 140 return subscriber; 141 } 142 143 148 public void dispose() { 149 subscriber.removeListener(this); 150 } 151 152 155 public void subscriberResourceChanged(ISubscriberChangeEvent[] deltas) { 156 fireStateChangeEvent(new TeamStateChangeEvent(deltas)); 157 } 158 159 162 public String [] getDecoratedProperties(Object element) { 163 return new String [0]; 164 } 165 } 166 | Popular Tags |