1 11 package org.eclipse.team.internal.ui.synchronize; 12 13 import java.util.*; 14 15 import org.eclipse.compare.CompareConfiguration; 16 import org.eclipse.compare.structuremergeviewer.DiffNode; 17 import org.eclipse.jface.resource.ImageDescriptor; 18 import org.eclipse.jface.resource.JFaceResources; 19 import org.eclipse.jface.viewers.*; 20 import org.eclipse.osgi.util.NLS; 21 import org.eclipse.swt.SWT; 22 import org.eclipse.swt.graphics.*; 23 import org.eclipse.team.core.synchronize.SyncInfo; 24 import org.eclipse.team.internal.ui.*; 25 import org.eclipse.team.ui.ISharedImages; 26 import org.eclipse.team.ui.synchronize.ISynchronizeModelElement; 27 import org.eclipse.ui.model.WorkbenchLabelProvider; 28 29 35 public class SynchronizeModelElementLabelProvider extends LabelProvider implements IColorProvider, IFontProvider { 36 37 private Map fgImageCache; 39 40 CompareConfiguration compareConfig = new CompareConfiguration(); 42 43 private WorkbenchLabelProvider workbenchLabelProvider = new WorkbenchLabelProvider(); 46 47 private Font busyFont; 49 50 public SynchronizeModelElementLabelProvider() { 51 } 52 53 57 public Color getForeground(Object element) { 58 return null; 59 } 60 61 65 public Color getBackground(Object element) { 66 return null; 67 } 68 69 72 public Font getFont(Object element) { 73 if (element instanceof ISynchronizeModelElement) { 74 ISynchronizeModelElement node = (ISynchronizeModelElement)element; 75 if(node.getProperty(ISynchronizeModelElement.BUSY_PROPERTY)) { 76 if (busyFont == null) { 77 Font defaultFont = JFaceResources.getDefaultFont(); 78 FontData[] data = defaultFont.getFontData(); 79 for (int i = 0; i < data.length; i++) { 80 data[i].setStyle(SWT.ITALIC); 81 } 82 busyFont = new Font(TeamUIPlugin.getStandardDisplay(), data); 83 } 84 return busyFont; 85 } 86 } 87 return null; 88 } 89 90 94 public Image getImage(Object element) { 95 Image base = workbenchLabelProvider.getImage(element); 96 if (base != null) { 97 if (element instanceof ISynchronizeModelElement) { 98 ISynchronizeModelElement syncNode = (ISynchronizeModelElement) element; 99 int kind = syncNode.getKind(); 100 Image decoratedImage; 101 decoratedImage = getCompareImage(base, kind); 102 return propagateConflicts(decoratedImage, syncNode); 106 } 107 } 108 return base; 109 } 110 111 115 public String getText(Object element) { 116 String base = workbenchLabelProvider.getText(element); 117 if (element instanceof DiffNode) { 118 if (TeamUIPlugin.getPlugin().getPreferenceStore().getBoolean(IPreferenceIds.SYNCVIEW_VIEW_SYNCINFO_IN_LABEL)) { 119 int kind = ((DiffNode) element).getKind(); 122 if (kind != SyncInfo.IN_SYNC) { 123 String syncKindString = SyncInfo.kindToString(kind); 124 return NLS.bind(TeamUIMessages.TeamSubscriberSyncPage_labelWithSyncKind, new String [] { base, syncKindString }); } 126 } 127 } 128 return base; 129 } 130 131 protected Image getCompareImage(Image base, int kind) { 132 switch (kind & SyncInfo.DIRECTION_MASK) { 133 case SyncInfo.OUTGOING : 134 kind = (kind & ~SyncInfo.OUTGOING) | SyncInfo.INCOMING; 135 break; 136 case SyncInfo.INCOMING : 137 kind = (kind & ~SyncInfo.INCOMING) | SyncInfo.OUTGOING; 138 break; 139 } 140 return compareConfig.getImage(base, kind); 141 } 142 143 private Image propagateConflicts(Image base, ISynchronizeModelElement element) { 144 145 ImageDescriptor[] overlayImages = new ImageDescriptor[4]; 146 boolean hasOverlay = false; 147 148 if (element.getProperty(ISynchronizeModelElement.BUSY_PROPERTY)) { 150 overlayImages[IDecoration.TOP_LEFT] = TeamUIPlugin.getImageDescriptor(ISharedImages.IMG_HOURGLASS_OVR); 151 hasOverlay = true; 152 } 153 int kind = element.getKind(); 155 if ((kind & SyncInfo.DIRECTION_MASK) != SyncInfo.CONFLICTING) { 156 if (hasDecendantConflicts(element)) { 159 overlayImages[IDecoration.BOTTOM_RIGHT] = TeamUIPlugin.getImageDescriptor(ISharedImages.IMG_CONFLICT_OVR); 160 hasOverlay = true; 161 } 162 } 163 if (hasErrorMarker(element)) { 164 overlayImages[IDecoration.BOTTOM_LEFT] = TeamUIPlugin.getImageDescriptor(ISharedImages.IMG_ERROR_OVR); 165 hasOverlay = true; 166 } else if (hasWarningMarker(element)) { 167 overlayImages[IDecoration.BOTTOM_LEFT] = TeamUIPlugin.getImageDescriptor(ISharedImages.IMG_WARNING_OVR); 168 hasOverlay = true; 169 } 170 if (hasOverlay) { 171 ImageDescriptor overlay = new DecorationOverlayIcon(base, overlayImages, new Point(base.getBounds().width, base.getBounds().height)); 172 if (fgImageCache == null) { 173 fgImageCache = new HashMap(10); 174 } 175 Image conflictDecoratedImage = (Image) fgImageCache.get(overlay); 176 if (conflictDecoratedImage == null) { 177 conflictDecoratedImage = overlay.createImage(); 178 fgImageCache.put(overlay, conflictDecoratedImage); 179 } 180 return conflictDecoratedImage; 181 } 182 return base; 183 } 184 185 190 private boolean hasDecendantConflicts(ISynchronizeModelElement node) { 191 return node.getProperty(ISynchronizeModelElement.PROPAGATED_CONFLICT_PROPERTY); 192 } 193 194 198 private boolean hasErrorMarker(ISynchronizeModelElement node) { 199 return node.getProperty(ISynchronizeModelElement.PROPAGATED_ERROR_MARKER_PROPERTY); 200 } 201 202 206 private boolean hasWarningMarker(ISynchronizeModelElement node) { 207 return node.getProperty(ISynchronizeModelElement.PROPAGATED_WARNING_MARKER_PROPERTY); 208 } 209 210 214 public void dispose() { 215 workbenchLabelProvider.dispose(); 216 if(busyFont != null) { 217 busyFont.dispose(); 218 } 219 compareConfig.dispose(); 220 if (fgImageCache != null) { 221 Iterator it = fgImageCache.values().iterator(); 222 while (it.hasNext()) { 223 Image element = (Image) it.next(); 224 element.dispose(); 225 } 226 } 227 } 228 } 229 | Popular Tags |