1 11 package org.eclipse.team.internal.ui.mapping; 12 13 import java.util.HashSet ; 14 import java.util.Set ; 15 16 import org.eclipse.core.resources.*; 17 import org.eclipse.jface.viewers.*; 18 import org.eclipse.swt.graphics.Font; 19 import org.eclipse.swt.graphics.Image; 20 import org.eclipse.team.core.diff.*; 21 import org.eclipse.team.core.mapping.IResourceDiffTree; 22 import org.eclipse.team.core.mapping.ISynchronizationContext; 23 import org.eclipse.team.internal.ui.*; 24 import org.eclipse.team.internal.ui.synchronize.ImageManager; 25 import org.eclipse.team.ui.mapping.ITeamContentProviderManager; 26 import org.eclipse.team.ui.mapping.SynchronizationLabelProvider; 27 import org.eclipse.team.ui.synchronize.ISynchronizePageConfiguration; 28 import org.eclipse.ui.model.WorkbenchLabelProvider; 29 import org.eclipse.ui.navigator.ICommonContentExtensionSite; 30 31 34 public class ResourceModelLabelProvider extends 35 SynchronizationLabelProvider implements IFontProvider, IResourceChangeListener, ITreePathLabelProvider { 36 37 public static final FastDiffFilter CONFLICT_FILTER = new FastDiffFilter() { 38 public boolean select(IDiff diff) { 39 if (diff instanceof IThreeWayDiff) { 40 IThreeWayDiff twd = (IThreeWayDiff) diff; 41 return twd.getDirection() == IThreeWayDiff.CONFLICTING; 42 } 43 return false; 44 } 45 }; 46 47 private ILabelProvider provider; 48 private ResourceModelContentProvider contentProvider; 49 private ImageManager localImageManager; 50 51 public void init(ICommonContentExtensionSite site) { 52 ITreeContentProvider aContentProvider = site.getExtension().getContentProvider(); 53 if (aContentProvider instanceof ResourceModelContentProvider) { 54 contentProvider = (ResourceModelContentProvider) aContentProvider; 55 ResourcesPlugin.getWorkspace().addResourceChangeListener(this); 56 } 57 super.init(site); 58 } 59 60 public void dispose() { 61 ResourcesPlugin.getWorkspace().removeResourceChangeListener(this); 62 if (localImageManager != null) 63 localImageManager.dispose(); 64 if (provider != null) 65 provider.dispose(); 66 super.dispose(); 67 } 68 69 72 protected ILabelProvider getDelegateLabelProvider() { 73 if (provider == null) 74 provider = new WorkbenchLabelProvider(); 75 return provider ; 76 } 77 78 81 protected IDiff getDiff(Object elementOrPath) { 82 IResource resource = getResource(elementOrPath); 83 IResourceDiffTree tree = getDiffTree(elementOrPath); 84 if (tree != null && resource != null) { 85 IDiff delta = tree.getDiff(resource.getFullPath()); 86 return delta; 87 } 88 return null; 89 } 90 91 private IResource getResource(Object elementOrPath) { 92 Object element = internalGetElement(elementOrPath); 93 if (element instanceof IResource) { 94 return (IResource) element; 95 } 96 return null; 97 } 98 99 102 protected boolean isIncludeOverlays() { 103 return true; 104 } 105 106 109 protected boolean isBusy(Object elementOrPath) { 110 IResource resource = getResource(elementOrPath); 111 IResourceDiffTree tree = getDiffTree(elementOrPath); 112 if (tree != null && resource != null) { 113 return tree.getProperty(resource.getFullPath(), IDiffTree.P_BUSY_HINT); 114 } 115 return super.isBusy(elementOrPath); 116 } 117 118 private TreePath internalGetPath(Object elementOrPath) { 119 if (elementOrPath instanceof TreePath) { 120 return (TreePath) elementOrPath; 121 } 122 return null; 123 } 124 125 128 protected boolean hasDecendantConflicts(Object elementOrPath) { 129 IResource resource = getResource(elementOrPath); 130 IResourceDiffTree tree = getDiffTree(elementOrPath); 131 if (tree != null && resource != null) { 132 int depth = getTraversalCalculator().getLayoutDepth(resource, internalGetPath(elementOrPath)); 133 if (depth == IResource.DEPTH_INFINITE || resource.getType() == IResource.FILE) 134 return tree.getProperty(resource.getFullPath(), IDiffTree.P_HAS_DESCENDANT_CONFLICTS); 135 return tree.hasMatchingDiffs(getTraversalCalculator().getTraversals(resource, internalGetPath(elementOrPath)), CONFLICT_FILTER); 136 } 137 return super.hasDecendantConflicts(elementOrPath); 138 } 139 140 protected IResourceDiffTree getDiffTree(Object elementOrPath) { 141 ISynchronizationContext context = getContext(); 142 if (context != null) 143 return context.getDiffTree(); 144 return null; 145 } 146 147 150 public void resourceChanged(IResourceChangeEvent event) { 151 String [] markerTypes = new String [] {IMarker.PROBLEM}; 152 final Set handledResources = new HashSet (); 153 154 for (int idx = 0; idx < markerTypes.length; idx++) { 157 IMarkerDelta[] markerDeltas = event.findMarkerDeltas(markerTypes[idx], true); 158 for (int i = 0; i < markerDeltas.length; i++) { 159 IMarkerDelta delta = markerDeltas[i]; 160 IResource resource = delta.getResource(); 161 while (resource != null && resource.getType() != IResource.ROOT && !handledResources.contains(resource)) { 162 handledResources.add(resource); 163 resource = resource.getParent(); 164 } 165 } 166 } 167 168 if (!handledResources.isEmpty()) { 169 final IResource[] resources = (IResource[]) handledResources.toArray(new IResource[handledResources.size()]); 170 updateLabels(resources); 171 } 172 } 173 174 protected void updateLabels(final Object [] resources) { 175 Utils.asyncExec(new Runnable () { 176 public void run() { 177 contentProvider.getStructuredViewer().update( 178 resources, null); 179 } 180 }, contentProvider.getStructuredViewer()); 181 } 182 183 protected String getDelegateText(Object elementOrPath) { 184 if (getConfiguration() != null) { 185 String label = getTraversalCalculator().getLabel(elementOrPath); 186 if (label != null) 187 return label; 188 } 189 return super.getDelegateText(internalGetElement(elementOrPath)); 190 } 191 192 protected Image getDelegateImage(Object elementOrPath) { 193 if (getConfiguration() != null && getTraversalCalculator().isCompressedFolder(elementOrPath)) { 194 return getImageManager().getImage(TeamUIPlugin.getImageDescriptor(ITeamUIImages.IMG_COMPRESSED_FOLDER)); 195 } 196 return super.getDelegateImage(internalGetElement(elementOrPath)); 197 } 198 199 private Object internalGetElement(Object elementOrPath) { 200 if (elementOrPath instanceof TreePath) { 201 TreePath tp = (TreePath) elementOrPath; 202 return tp.getLastSegment(); 203 } 204 return elementOrPath; 205 } 206 207 protected ResourceModelTraversalCalculator getTraversalCalculator() { 208 return ResourceModelTraversalCalculator.getTraversalCalculator(getConfiguration()); 209 } 210 211 private ISynchronizePageConfiguration getConfiguration() { 212 return (ISynchronizePageConfiguration)getExtensionSite().getExtensionStateModel().getProperty(ITeamContentProviderManager.P_SYNCHRONIZATION_PAGE_CONFIGURATION); 213 } 214 215 public void updateLabel(ViewerLabel label, TreePath elementPath) { 216 label.setImage(getImage(elementPath)); 217 label.setText(getText(elementPath)); 218 Font f = getFont(elementPath); 219 if (f != null) 220 label.setFont(f); 221 } 222 223 protected ImageManager getImageManager() { 224 ISynchronizationContext context = getContext(); 225 if (context != null) { 226 return ImageManager.getImageManager(context); 227 } 228 if (localImageManager == null) { 229 localImageManager = new ImageManager(); 230 } 231 return localImageManager; 232 } 233 234 } 235 | Popular Tags |