KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > views > AntViewLabelProvider


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

11 package org.eclipse.ant.internal.ui.views;
12
13 import org.eclipse.ant.internal.ui.model.AntImageDescriptor;
14 import org.eclipse.ant.internal.ui.model.AntUIImages;
15 import org.eclipse.ant.internal.ui.model.IAntUIConstants;
16 import org.eclipse.ant.internal.ui.views.elements.ProjectNode;
17 import org.eclipse.ant.internal.ui.views.elements.TargetNode;
18 import org.eclipse.jface.resource.CompositeImageDescriptor;
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.jface.viewers.IColorProvider;
21 import org.eclipse.jface.viewers.ILabelProvider;
22 import org.eclipse.jface.viewers.ILabelProviderListener;
23 import org.eclipse.swt.SWT;
24 import org.eclipse.swt.graphics.Color;
25 import org.eclipse.swt.graphics.Image;
26 import org.eclipse.swt.widgets.Display;
27
28 /**
29  * A label provider that provides labels for elements displayed in the
30  * <code>AntView</code>
31  */

32 public class AntViewLabelProvider implements ILabelProvider, IColorProvider {
33
34     /**
35      * @see org.eclipse.jface.viewers.ILabelProvider#getImage(java.lang.Object)
36      */

37     public Image getImage(Object JavaDoc element) {
38         if (element instanceof ProjectNode) {
39             ProjectNode project= (ProjectNode) element;
40             int flags = 0;
41             if (project.isErrorNode()) {
42                 flags = flags | AntImageDescriptor.HAS_ERRORS;
43             }
44             CompositeImageDescriptor descriptor = new AntImageDescriptor(AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_PROJECT), flags);
45             return AntUIImages.getImage(descriptor);
46         } else if (element instanceof TargetNode) {
47             TargetNode target= (TargetNode) element;
48             int flags = 0;
49             ImageDescriptor base = null;
50             if (target.equals(target.getProject().getDefaultTarget())){
51                 base = AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_DEFAULT_TARGET);
52             } else if (target.getDescription() == null) {
53                 base = AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_TARGET_INTERNAL);
54             } else {
55                 base = AntUIImages.getImageDescriptor(IAntUIConstants.IMG_ANT_TARGET);
56             }
57             if (target.isErrorNode()) {
58                 flags = flags | AntImageDescriptor.HAS_ERRORS;
59             }
60             return AntUIImages.getImage(new AntImageDescriptor(base, flags));
61         }
62         return null;
63     }
64
65     /**
66      * @see org.eclipse.jface.viewers.ILabelProvider#getText(java.lang.Object)
67      */

68     public String JavaDoc getText(Object JavaDoc element) {
69         if (element instanceof TargetNode) {
70             TargetNode node= (TargetNode)element;
71             StringBuffer JavaDoc name= new StringBuffer JavaDoc(node.getName());
72             if (node.getName().equals(node.getProject().getDefaultTargetName())) {
73                 name.append(AntViewMessages.getString("TargetNode.default")); //$NON-NLS-1$
74
}
75             return name.toString();
76         } else if (element instanceof ProjectNode) {
77             ProjectNode project= (ProjectNode) element;
78             StringBuffer JavaDoc buffer= new StringBuffer JavaDoc(project.getName());
79             String JavaDoc defaultTarget= project.getDefaultTargetName();
80             if (defaultTarget != null) {
81                 buffer.append(" [").append(defaultTarget).append(']'); //$NON-NLS-1$
82
}
83             return buffer.toString();
84         } else {
85             return element.toString();
86         }
87     }
88
89     /**
90      * @see org.eclipse.jface.viewers.IBaseLabelProvider#addListener(org.eclipse.jface.viewers.ILabelProviderListener)
91      */

92     public void addListener(ILabelProviderListener listener) {
93     }
94
95     /**
96      * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
97      */

98     public void dispose() {
99     }
100
101     /**
102      * @see org.eclipse.jface.viewers.IBaseLabelProvider#isLabelProperty(java.lang.Object, java.lang.String)
103      */

104     public boolean isLabelProperty(Object JavaDoc element, String JavaDoc property) {
105         return false;
106     }
107
108     /**
109      * @see org.eclipse.jface.viewers.IBaseLabelProvider#removeListener(org.eclipse.jface.viewers.ILabelProviderListener)
110      */

111     public void removeListener(ILabelProviderListener listener) {
112     }
113
114     /* (non-Javadoc)
115      * @see org.eclipse.jface.viewers.IColorProvider#getForeground(java.lang.Object)
116      */

117     public Color getForeground(Object JavaDoc element) {
118         if (element instanceof TargetNode) {
119             TargetNode target= (TargetNode)element;
120             if (target == target.getProject().getDefaultTarget()) {
121                 return Display.getDefault().getSystemColor(SWT.COLOR_BLUE);
122             }
123         }
124         return null;
125     }
126
127     /* (non-Javadoc)
128      * @see org.eclipse.jface.viewers.IColorProvider#getBackground(java.lang.Object)
129      */

130     public Color getBackground(Object JavaDoc element) {
131         return null;
132     }
133 }
134
Popular Tags