KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.Property;
14 import org.eclipse.ant.core.Task;
15 import org.eclipse.ant.internal.core.AntObject;
16 import org.eclipse.ant.internal.ui.AntUIImages;
17 import org.eclipse.ant.internal.ui.IAntUIConstants;
18 import org.eclipse.jface.viewers.IColorProvider;
19 import org.eclipse.jface.viewers.ITableLabelProvider;
20 import org.eclipse.jface.viewers.LabelProvider;
21 import org.eclipse.swt.SWT;
22 import org.eclipse.swt.graphics.Color;
23 import org.eclipse.swt.graphics.Image;
24 import org.eclipse.swt.widgets.Display;
25 import org.eclipse.ui.ISharedImages;
26 import org.eclipse.ui.PlatformUI;
27 import org.eclipse.ui.ide.IDE;
28
29
30 /**
31  * Label provider for type elements
32  */

33 public class AntObjectLabelProvider extends LabelProvider implements ITableLabelProvider, IColorProvider {
34
35     /* (non-Javadoc)
36      * Method declared on IBaseLabelProvider.
37      */

38     public void dispose() {
39     }
40     
41     /* (non-Javadoc)
42      * Method declared on ITableLabelProvider.
43      */

44     public Image getColumnImage(Object JavaDoc element, int columnIndex) {
45         if (columnIndex != 0) {
46             return null;
47         }
48         if (element instanceof Property) {
49             Property prop= (Property) element;
50             if (prop.isDefault() && prop.isEclipseRuntimeRequired()) {
51                 return AntUIImages.getImage(IAntUIConstants.IMG_ANT_ECLIPSE_RUNTIME_OBJECT);
52             }
53             return getPropertyImage();
54         } else if (element instanceof AntObject){
55             AntObject object= (AntObject) element;
56             if (object.isDefault() && object.isEclipseRuntimeRequired()) {
57                 return AntUIImages.getImage(IAntUIConstants.IMG_ANT_ECLIPSE_RUNTIME_OBJECT);
58             }
59             if (element instanceof Task) {
60                 return getTaskImage();
61             }
62             return getTypeImage();
63         }
64         return PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJ_FILE);
65     }
66     
67     /* (non-Javadoc)
68      * Method declared on ITableLabelProvider.
69      */

70     public String JavaDoc getColumnText(Object JavaDoc element, int columnIndex) {
71         if (element instanceof Property) {
72             return getPropertyText((Property) element, columnIndex);
73         } else if (element instanceof AntObject) {
74             AntObject object = (AntObject) element;
75              switch (columnIndex) {
76                 case 0:
77                     return object.toString();
78                 case 1:
79                     return object.getClassName();
80                 case 2:
81                    return object.getLibraryEntry().getLabel();
82                 case 3:
83                     return object.getPluginLabel();
84             }
85         }
86          
87         return element.toString();
88     }
89     
90     public String JavaDoc getPropertyText(Property property, int columnIndex) {
91         switch (columnIndex) {
92             case 0:
93                 return property.getName();
94             case 1:
95                 return property.getValue(false);
96             case 2:
97                 if (property.isDefault()) {
98                     return property.getPluginLabel();
99                 }
100         }
101         return ""; //$NON-NLS-1$
102
}
103     
104     public static Image getTypeImage() {
105         return AntUIImages.getImage(IAntUIConstants.IMG_ANT_TYPE);
106     }
107     
108     public static Image getTaskImage() {
109         return PlatformUI.getWorkbench().getSharedImages().getImage(IDE.SharedImages.IMG_OBJS_TASK_TSK);
110     }
111
112     public static Image getPropertyImage() {
113         return AntUIImages.getImage(IAntUIConstants.IMG_PROPERTY);
114     }
115     
116     /* (non-Javadoc)
117      * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
118      */

119     public Color getForeground(Object JavaDoc element) {
120         return null;
121     }
122
123     /* (non-Javadoc)
124      * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
125      */

126     public Color getBackground(Object JavaDoc element) {
127         if (element instanceof AntObject) {
128             if (((AntObject) element).isDefault()) {
129                 Display display= Display.getCurrent();
130                 return display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
131             }
132         } else if (element instanceof Property) {
133             if (((Property) element).isDefault()) {
134                 Display display= Display.getCurrent();
135                 return display.getSystemColor(SWT.COLOR_INFO_BACKGROUND);
136             }
137         }
138         return null;
139     }
140 }
Popular Tags