1 11 package org.eclipse.jdt.internal.ui.wizards.buildpaths; 12 13 import java.util.ArrayList ; 14 15 import org.eclipse.core.runtime.IPath; 16 17 import org.eclipse.swt.SWT; 18 import org.eclipse.swt.graphics.Color; 19 import org.eclipse.swt.graphics.Image; 20 import org.eclipse.swt.widgets.Display; 21 22 import org.eclipse.jface.resource.ImageRegistry; 23 import org.eclipse.jface.viewers.DecorationOverlayIcon; 24 import org.eclipse.jface.viewers.IColorProvider; 25 import org.eclipse.jface.viewers.IDecoration; 26 import org.eclipse.jface.viewers.LabelProvider; 27 28 import org.eclipse.ui.ISharedImages; 29 import org.eclipse.ui.PlatformUI; 30 31 import org.eclipse.jdt.internal.corext.util.Messages; 32 33 import org.eclipse.jdt.internal.ui.JavaPlugin; 34 import org.eclipse.jdt.internal.ui.JavaPluginImages; 35 import org.eclipse.jdt.internal.ui.wizards.NewWizardMessages; 36 37 38 public class CPVariableElementLabelProvider extends LabelProvider implements IColorProvider { 39 40 private Image fJARImage; 42 private Image fFolderImage; 43 private Color fResolvedBackground; 44 45 private Image fDeprecatedJARImage; 46 private Image fDeprecatedFolderImage; 47 48 private boolean fHighlightReadOnly; 49 50 public CPVariableElementLabelProvider(boolean highlightReadOnly) { 51 ImageRegistry reg= JavaPlugin.getDefault().getImageRegistry(); 52 fJARImage= reg.get(JavaPluginImages.IMG_OBJS_EXTJAR); 53 fFolderImage= PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER); 54 55 fDeprecatedJARImage= new DecorationOverlayIcon(fJARImage, JavaPluginImages.DESC_OVR_DEPRECATED, IDecoration.TOP_LEFT).createImage(); 56 fDeprecatedFolderImage= new DecorationOverlayIcon(fFolderImage, JavaPluginImages.DESC_OVR_DEPRECATED, IDecoration.TOP_LEFT).createImage(); 57 58 fHighlightReadOnly= highlightReadOnly; 59 fResolvedBackground= null; 60 } 61 62 65 public Image getImage(Object element) { 66 if (element instanceof CPVariableElement) { 67 CPVariableElement curr= (CPVariableElement) element; 68 IPath path= curr.getPath(); 69 if (path.toFile().isFile()) { 70 return curr.isDeprecated() ? fDeprecatedJARImage : fJARImage; 71 } 72 return curr.isDeprecated() ? fDeprecatedFolderImage : fFolderImage; 73 } 74 return super.getImage(element); 75 } 76 77 80 public String getText(Object element) { 81 if (element instanceof CPVariableElement) { 82 CPVariableElement curr= (CPVariableElement)element; 83 String name= curr.getName(); 84 IPath path= curr.getPath(); 85 86 String result= name; 87 ArrayList restrictions= new ArrayList (2); 88 89 if (curr.isReadOnly() && fHighlightReadOnly) { 90 restrictions.add(NewWizardMessages.CPVariableElementLabelProvider_read_only); 91 } 92 if (curr.isDeprecated()) { 93 restrictions.add(NewWizardMessages.CPVariableElementLabelProvider_deprecated); 94 } 95 if (restrictions.size() == 1) { 96 result= Messages.format(NewWizardMessages.CPVariableElementLabelProvider_one_restriction, new Object [] {result, restrictions.get(0)}); 97 } else if (restrictions.size() == 2) { 98 result= Messages.format(NewWizardMessages.CPVariableElementLabelProvider_two_restrictions, new Object [] {result, restrictions.get(0), restrictions.get(1)}); 99 } 100 101 if (path != null) { 102 String appendix; 103 if (!path.isEmpty()) { 104 appendix= path.toOSString(); 105 } else { 106 appendix= NewWizardMessages.CPVariableElementLabelProvider_empty; 107 } 108 result= Messages.format(NewWizardMessages.CPVariableElementLabelProvider_appendix, new Object [] {result, appendix}); 109 } 110 111 return result; 112 } 113 114 115 return super.getText(element); 116 } 117 118 121 public Color getForeground(Object element) { 122 return null; 123 } 124 125 128 public Color getBackground(Object element) { 129 if (element instanceof CPVariableElement) { 130 CPVariableElement curr= (CPVariableElement) element; 131 if (fHighlightReadOnly && curr.isReadOnly()) { 132 if (fResolvedBackground == null) { 133 Display display= Display.getCurrent(); 134 fResolvedBackground= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND); 135 } 136 return fResolvedBackground; 137 } 138 } 139 return null; 140 } 141 142 145 public void dispose() { 146 super.dispose(); 147 fDeprecatedFolderImage.dispose(); 148 fDeprecatedJARImage.dispose(); 149 } 150 151 } 152 | Popular Tags |