1 11 package org.eclipse.team.ui.synchronize; 12 13 import org.eclipse.compare.CompareConfiguration; 14 import org.eclipse.compare.structuremergeviewer.ICompareInput; 15 import org.eclipse.core.resources.IMarker; 16 import org.eclipse.core.resources.mapping.ModelProvider; 17 import org.eclipse.core.resources.mapping.ResourceMapping; 18 import org.eclipse.core.runtime.CoreException; 19 import org.eclipse.jface.resource.ImageDescriptor; 20 import org.eclipse.jface.resource.JFaceResources; 21 import org.eclipse.jface.viewers.*; 22 import org.eclipse.osgi.util.NLS; 23 import org.eclipse.swt.graphics.*; 24 import org.eclipse.team.core.diff.IDiff; 25 import org.eclipse.team.core.diff.IThreeWayDiff; 26 import org.eclipse.team.core.mapping.ISynchronizationContext; 27 import org.eclipse.team.core.synchronize.SyncInfo; 28 import org.eclipse.team.internal.ui.*; 29 import org.eclipse.team.internal.ui.mapping.ResourceDiffCompareInput; 30 import org.eclipse.team.internal.ui.synchronize.ImageManager; 31 import org.eclipse.team.ui.ISharedImages; 32 import org.eclipse.team.ui.TeamUI; 33 import org.eclipse.team.ui.mapping.*; 34 35 41 public abstract class AbstractSynchronizeLabelProvider implements ILabelProvider { 42 43 private ImageManager localImageManager; 44 45 48 public Image getImage(Object element) { 49 Image base = getDelegateImage(element); 50 if (isDecorationEnabled() && base != null) { 51 Image decorateImage = decorateImage(base, element); 52 base = decorateImage; 53 } 54 if (isIncludeOverlays() && base != null) { 55 base = addOverlays(base, element); 56 } 57 return base; 58 } 59 60 73 protected Image decorateImage(Image base, Object element) { 74 Image decoratedImage; 75 if (element instanceof ICompareInput) { 76 ICompareInput ci = (ICompareInput) element; 77 decoratedImage = getCompareImage(base, ci.getKind()); 78 } else { 79 IDiff node = getDiff(element); 80 decoratedImage = getCompareImage(base, node); 81 } 82 return decoratedImage; 86 } 87 88 93 protected Image getDelegateImage(Object element) { 94 ILabelProvider modelLabelProvider = getDelegateLabelProvider(); 95 Image base = modelLabelProvider.getImage(internalGetElement(element)); 96 if (base == null && element instanceof ModelProvider) { 97 ModelProvider mp = (ModelProvider) element; 98 base = getImageManager().getImage(getImageDescriptor(mp)); 99 } 100 return base; 101 } 102 103 private ImageDescriptor getImageDescriptor(ModelProvider provider) { 104 ITeamContentProviderManager manager = TeamUI.getTeamContentProviderManager(); 105 ITeamContentProviderDescriptor desc = manager.getDescriptor(provider.getId()); 106 return desc.getImageDescriptor(); 107 } 108 109 private Object internalGetElement(Object element) { 110 if (element instanceof TreePath) { 111 TreePath tp = (TreePath) element; 112 element = tp.getLastSegment(); 113 } 114 return element; 115 } 116 117 private Image getCompareImage(Image base, IDiff node) { 118 int compareKind = getCompareKind(node); 119 return getCompareImage(base, compareKind); 120 } 121 122 private Image getCompareImage(Image base, int compareKind) { 123 return getImageManager().getImage(base, compareKind); 124 } 125 126 private int getCompareKind(IDiff node) { 127 return ResourceDiffCompareInput.getCompareKind(node); 128 } 129 130 133 public String getText(Object element) { 134 String base = getDelegateText(element); 135 if (isSyncInfoInTextEnabled()) { 136 return decorateText(base, element); 137 } 138 return base; 139 } 140 141 146 protected String getDelegateText(Object element) { 147 ILabelProvider modelLabelProvider = getDelegateLabelProvider(); 148 element = internalGetElement(element); 149 String base = modelLabelProvider.getText(element); 150 if (base == null || base.length() == 0) { 151 if (element instanceof ModelProvider) { 152 ModelProvider provider = (ModelProvider) element; 153 base = Utils.getLabel(provider); 154 } 155 } 156 return base; 157 } 158 159 169 protected String decorateText(String base, Object element) { 170 IDiff node = getDiff(element); 171 if (node != null && node.getKind() != IDiff.NO_CHANGE) { 172 String syncKindString = node.toDiffString(); 173 return NLS.bind(TeamUIMessages.AbstractSynchronizationLabelProvider_0, new String [] { base, syncKindString }); 174 } 175 return base; 176 } 177 178 181 public void addListener(ILabelProviderListener listener) { 182 getDelegateLabelProvider().addListener(listener); 183 } 184 185 188 public void dispose() { 189 if (localImageManager != null) 190 localImageManager.dispose(); 191 } 192 193 196 public boolean isLabelProperty(Object element, String property) { 197 return getDelegateLabelProvider().isLabelProperty(internalGetElement(element), property); 198 } 199 200 203 public void removeListener(ILabelProviderListener listener) { 204 getDelegateLabelProvider().removeListener(listener); 205 } 206 207 214 protected boolean isSyncInfoInTextEnabled() { 215 return isDecorationEnabled() && TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.SYNCVIEW_VIEW_SYNCINFO_IN_LABEL); 216 } 217 218 225 protected abstract ILabelProvider getDelegateLabelProvider(); 226 227 231 protected abstract boolean isDecorationEnabled(); 232 233 241 protected IDiff getDiff(Object element) { 242 return null; 243 } 244 245 private Image addOverlays(Image base, Object element) { 246 if (!isIncludeOverlays()) 247 return base; 248 249 ImageDescriptor[] overlayImages = new ImageDescriptor[4]; 250 boolean hasOverlay = false; 251 252 if (isBusy(element)) { 254 overlayImages[IDecoration.TOP_LEFT] = TeamUIPlugin.getImageDescriptor(ISharedImages.IMG_HOURGLASS_OVR); 255 hasOverlay = true; 256 } 257 if (!isConflicting(element)) { 259 if (hasDecendantConflicts(element)) { 261 overlayImages[IDecoration.BOTTOM_RIGHT] = TeamUIPlugin.getImageDescriptor(ISharedImages.IMG_CONFLICT_OVR); 262 hasOverlay = true; 263 } 264 } 265 int severity = getMarkerSeverity(element); 266 if (severity == IMarker.SEVERITY_ERROR) { 267 overlayImages[IDecoration.BOTTOM_LEFT] = TeamUIPlugin.getImageDescriptor(ISharedImages.IMG_ERROR_OVR); 268 hasOverlay = true; 269 } else if (severity == IMarker.SEVERITY_WARNING) { 270 overlayImages[IDecoration.BOTTOM_LEFT] = TeamUIPlugin.getImageDescriptor(ISharedImages.IMG_WARNING_OVR); 271 hasOverlay = true; 272 } 273 if (hasOverlay) { 274 ImageDescriptor overlay = new DecorationOverlayIcon(base, overlayImages, new Point(base.getBounds().width, base.getBounds().height)); 275 return getImageManager().getImage(overlay); 276 } 277 return base; 278 } 279 280 289 protected boolean isIncludeOverlays() { 290 return false; 291 } 292 293 307 protected int getMarkerSeverity(Object element) { 308 ResourceMapping mapping = Utils.getResourceMapping(internalGetElement(element)); 309 int result = -1; 310 if (mapping != null) { 311 try { 312 IMarker[] markers = mapping.findMarkers(IMarker.PROBLEM, true, null); 313 for (int i = 0; i < markers.length; i++) { 314 IMarker marker = markers[i]; 315 Integer severity = (Integer ) marker.getAttribute(IMarker.SEVERITY); 316 if (severity != null) { 317 if (severity.intValue() == IMarker.SEVERITY_ERROR) { 318 return IMarker.SEVERITY_ERROR; 319 } else if (severity.intValue() == IMarker.SEVERITY_WARNING) { 320 result = IMarker.SEVERITY_WARNING; 321 } 322 } 323 } 324 } catch (CoreException e) { 325 } 327 } 328 return result; 329 } 330 331 338 protected boolean hasDecendantConflicts(Object element) { 339 return false; 340 } 341 342 private boolean isConflicting(Object element) { 343 IDiff node = getDiff(element); 344 if (node != null) { 345 if (node instanceof IThreeWayDiff) { 346 IThreeWayDiff twd = (IThreeWayDiff) node; 347 return twd.getDirection() == IThreeWayDiff.CONFLICTING; 348 } 349 } 350 return false; 351 } 352 353 360 protected boolean isBusy(Object element) { 361 return false; 362 } 363 364 372 public Font getFont(Object element) { 373 if(isBusy(internalGetElement(element))) { 374 return JFaceResources.getFontRegistry().getItalic(JFaceResources.DEFAULT_FONT); 375 } 376 return null; 377 } 378 379 private ImageManager getImageManager() { 380 ISynchronizationContext context = getContext(); 381 if (context != null) { 382 return ImageManager.getImageManager(context); 383 } 384 if (localImageManager == null) { 385 localImageManager = new ImageManager(); 386 } 387 return localImageManager; 388 } 389 390 private ISynchronizationContext getContext() { 391 if (this instanceof SynchronizationLabelProvider) { 392 SynchronizationLabelProvider slp = (SynchronizationLabelProvider) this; 393 return slp.getContext(); 394 } 395 return null; 396 } 397 398 } 399 | Popular Tags |