1 11 package org.eclipse.compare.internal.patch; 12 13 import java.util.ArrayList ; 14 import java.util.Hashtable ; 15 import java.util.Iterator ; 16 import java.util.List ; 17 import java.util.Map ; 18 19 import org.eclipse.compare.internal.CompareUIPlugin; 20 import org.eclipse.compare.internal.DiffImage; 21 import org.eclipse.compare.structuremergeviewer.Differencer; 22 import org.eclipse.core.resources.IResource; 23 import org.eclipse.core.resources.ResourcesPlugin; 24 import org.eclipse.jface.resource.ImageDescriptor; 25 import org.eclipse.jface.viewers.ILabelDecorator; 26 import org.eclipse.jface.viewers.ILabelProviderListener; 27 import org.eclipse.osgi.util.NLS; 28 import org.eclipse.swt.graphics.Image; 29 30 public class PreviewPatchLabelDecorator implements ILabelDecorator { 31 32 33 private Map fImages= new Hashtable (10); 34 private List fDisposeOnShutdownImages= new ArrayList (); 35 36 ImageDescriptor errId= CompareUIPlugin.getImageDescriptor("ovr16/error_ov.gif"); 38 static final String error = "error"; static final String add = "add"; static final String delete = "del"; 42 public Image decorateImage(Image image, Object element) { 43 44 if (element instanceof Diff){ 45 Diff diff = (Diff) element; 46 switch (diff.getType()){ 47 case Differencer.ADDITION: 48 return getImageFor(add + (diff.fMatches ? "" : error), image, diff.fMatches); 50 case Differencer.DELETION: 51 return getImageFor(delete + (diff.fMatches ? "" : error), image, diff.fMatches); 53 default: 54 return getImageFor(diff.fMatches ? "" : error, image, diff.fMatches); } 56 } else if (element instanceof Hunk){ 57 Hunk hunk = (Hunk) element; 58 return getImageFor((hunk.fMatches ? "" : error),image, hunk.fMatches); } 60 61 return null; 62 } 63 64 private Image getImageFor(String id, Image image, boolean hasMatches) { 65 Image cached_image = (Image) fImages.get(id); 66 if (cached_image == null){ 67 DiffImage diffImage = new DiffImage(image, hasMatches ? null : errId, 16, false); 68 cached_image = diffImage.createImage(); 69 fImages.put(id, cached_image); 70 fDisposeOnShutdownImages.add(cached_image); 71 } 72 return cached_image; 73 } 74 75 public String decorateText(String text, Object element) { 76 if (element instanceof DiffProject){ 77 DiffProject project = (DiffProject)element; 78 IResource projectExistsInWorkspace = ResourcesPlugin.getWorkspace().getRoot().findMember(project.getProject().getFullPath()); 80 if(projectExistsInWorkspace == null) 81 return NLS.bind(PatchMessages.Diff_2Args, new String []{text, PatchMessages.PreviewPatchLabelDecorator_ProjectDoesNotExist}); 82 83 if (!project.getName().equals(project.getOriginalProjectName())) 84 return NLS.bind(PatchMessages.Diff_2Args, 85 new String []{project.getOriginalProjectName(), 86 NLS.bind(PatchMessages.PreviewPatchPage_Target, new String []{project.getName()})}); 87 88 } 89 return null; 90 } 91 92 public void dispose() { 93 if (fDisposeOnShutdownImages != null) { 94 Iterator i= fDisposeOnShutdownImages.iterator(); 95 while (i.hasNext()) { 96 Image img= (Image) i.next(); 97 if (!img.isDisposed()) 98 img.dispose(); 99 } 100 fImages= null; 101 } 102 } 103 104 public boolean isLabelProperty(Object element, String property) { 105 return false; 106 } 107 108 public void addListener(ILabelProviderListener listener) { 109 } 111 112 public void removeListener(ILabelProviderListener listener) { 113 } 115 } 116 | Popular Tags |