KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > preferences > AntClasspathLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

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 /**
30  * Label provider for classpath elements
31  */

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     /* (non-Javadoc)
53      * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
54      */

55     public Image getImage(Object JavaDoc element) {
56         String JavaDoc 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("/")) { //$NON-NLS-1$
64
return getFolderImage();
65             }
66             return getJarImage();
67         }
68         
69         return getClasspathImage();
70     }
71
72     /* (non-Javadoc)
73      * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
74      */

75     public String JavaDoc getText(Object JavaDoc element) {
76         if (element instanceof IAntClasspathEntry) {
77             IAntClasspathEntry entry= (IAntClasspathEntry)element;
78             StringBuffer JavaDoc label= new StringBuffer JavaDoc(entry.getLabel());
79             if (element instanceof GlobalClasspathEntries) {
80                 if (((GlobalClasspathEntries)element).getType() == ClasspathModel.ANT_HOME) {
81             
82                     AntCorePreferences prefs= AntCorePlugin.getPlugin().getPreferences();
83                     String JavaDoc defaultAntHome= prefs.getDefaultAntHome();
84                     String JavaDoc currentAntHome= fBlock.getAntHome();
85                     label.append(" ("); //$NON-NLS-1$
86
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     /* (non-Javadoc)
100      * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
101      */

102     public Color getBackground(Object JavaDoc 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     /* (non-Javadoc)
116      * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
117      */

118     public Color getForeground(Object JavaDoc element) {
119         return null;
120     }
121
122     /* (non-Javadoc)
123      * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
124      */

125     public void addListener(ILabelProviderListener listener) {
126     }
127
128     /* (non-Javadoc)
129      * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
130      */

131     public void dispose() {
132     }
133
134     /* (non-Javadoc)
135      * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
136      */

137     public boolean isLabelProperty(Object JavaDoc element, String JavaDoc property) {
138         return false;
139     }
140
141     /* (non-Javadoc)
142      * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
143      */

144     public void removeListener(ILabelProviderListener listener) {
145     }
146 }
147
Popular Tags