1 11 package org.eclipse.ant.internal.ui.preferences; 12 13 import org.eclipse.ant.core.AntCorePlugin; 14 import org.eclipse.ant.core.AntCorePreferences; 15 import org.eclipse.ant.core.IAntClasspathEntry; 16 import org.eclipse.ant.internal.ui.AntUIImages; 17 import org.eclipse.ant.internal.ui.IAntUIConstants; 18 import org.eclipse.jdt.ui.JavaUI; 19 import org.eclipse.jface.viewers.IColorProvider; 20 import org.eclipse.jface.viewers.ILabelProvider; 21 import org.eclipse.jface.viewers.ILabelProviderListener; 22 import org.eclipse.swt.SWT; 23 import org.eclipse.swt.graphics.Color; 24 import org.eclipse.swt.graphics.Image; 25 import org.eclipse.swt.widgets.Display; 26 import org.eclipse.ui.ISharedImages; 27 import org.eclipse.ui.PlatformUI; 28 29 32 public class AntClasspathLabelProvider implements ILabelProvider, IColorProvider { 33 34 35 private AntClasspathBlock fBlock; 36 37 public AntClasspathLabelProvider(AntClasspathBlock block) { 38 fBlock= block; 39 } 40 41 private Image getFolderImage() { 42 return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FOLDER); 43 } 44 45 private Image getJarImage() { 46 return JavaUI.getSharedImages().getImage(org.eclipse.jdt.ui.ISharedImages.IMG_OBJS_JAR); 47 } 48 49 public Image getClasspathImage() { 50 return AntUIImages.getImage(IAntUIConstants.IMG_TAB_CLASSPATH); 51 } 52 55 public Image getImage(Object element) { 56 String file; 57 if (element instanceof ClasspathEntry) { 58 ClasspathEntry entry = (ClasspathEntry) element; 59 if (entry.isEclipseRuntimeRequired()) { 60 return AntUIImages.getImage(IAntUIConstants.IMG_ANT_ECLIPSE_RUNTIME_OBJECT); 61 } 62 file= entry.toString(); 63 if (file.endsWith("/")) { return getFolderImage(); 65 } 66 return getJarImage(); 67 } 68 69 return getClasspathImage(); 70 } 71 72 75 public String getText(Object element) { 76 if (element instanceof IAntClasspathEntry) { 77 IAntClasspathEntry entry= (IAntClasspathEntry)element; 78 StringBuffer label= new StringBuffer (entry.getLabel()); 79 if (element instanceof GlobalClasspathEntries) { 80 if (((GlobalClasspathEntries)element).getType() == ClasspathModel.ANT_HOME) { 81 82 AntCorePreferences prefs= AntCorePlugin.getPlugin().getPreferences(); 83 String defaultAntHome= prefs.getDefaultAntHome(); 84 String currentAntHome= fBlock.getAntHome(); 85 label.append(" ("); if (defaultAntHome.equals(currentAntHome)) { 87 label.append(AntPreferencesMessages.AntClasspathLabelProvider_0); 88 } else { 89 label.append(fBlock.getAntHome()); 90 } 91 label.append(')'); 92 } 93 } 94 return label.toString(); 95 } 96 return element.toString(); 97 } 98 99 102 public Color getBackground(Object element) { 103 if (element instanceof GlobalClasspathEntries) { 104 int type= ((GlobalClasspathEntries) element).getType(); 105 if (type == ClasspathModel.CONTRIBUTED) { 106 Display display= Display.getCurrent(); 107 return display.getSystemColor(SWT.COLOR_INFO_BACKGROUND); 108 } 109 } else if (element instanceof ClasspathEntry) { 110 return getBackground(((ClasspathEntry) element).getParent()); 111 } 112 return null; 113 } 114 115 118 public Color getForeground(Object element) { 119 return null; 120 } 121 122 125 public void addListener(ILabelProviderListener listener) { 126 } 127 128 131 public void dispose() { 132 } 133 134 137 public boolean isLabelProperty(Object element, String property) { 138 return false; 139 } 140 141 144 public void removeListener(ILabelProviderListener listener) { 145 } 146 } 147 | Popular Tags |