KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > externaltools > internal > ui > BuilderLabelProvider


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.ui.externaltools.internal.ui;
12
13 import org.eclipse.core.resources.ICommand;
14 import org.eclipse.core.resources.ResourcesPlugin;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IExtension;
17 import org.eclipse.core.runtime.Platform;
18 import org.eclipse.debug.core.ILaunchConfiguration;
19 import org.eclipse.debug.core.ILaunchConfigurationType;
20 import org.eclipse.debug.ui.DebugUITools;
21 import org.eclipse.debug.ui.IDebugModelPresentation;
22 import org.eclipse.jface.viewers.LabelProvider;
23 import org.eclipse.osgi.util.NLS;
24 import org.eclipse.swt.graphics.Image;
25 import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
26 import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
27 import org.eclipse.ui.externaltools.internal.ui.BuilderPropertyPage.ErrorConfig;
28
29
30 class BuilderLabelProvider extends LabelProvider {
31         private static final String JavaDoc IMG_BUILDER = "icons/full/obj16/builder.gif"; //$NON-NLS-1$;
32
private static final String JavaDoc IMG_INVALID_BUILD_TOOL = "icons/full/obj16/invalid_build_tool.gif"; //$NON-NLS-1$
33
IDebugModelPresentation debugModelPresentation= DebugUITools.newDebugModelPresentation();
34
35         private Image builderImage = ExternalToolsPlugin.getDefault().getImageDescriptor(IMG_BUILDER).createImage();
36         private Image invalidBuildToolImage = ExternalToolsPlugin.getDefault().getImageDescriptor(IMG_INVALID_BUILD_TOOL).createImage();
37         
38         public String JavaDoc getText(Object JavaDoc element) {
39             if (element instanceof ICommand) {
40                 return getCommandText((ICommand) element);
41             } else if (element instanceof ILaunchConfiguration || element instanceof ILaunchConfigurationType) {
42                 return getDebugModelText(element);
43             } else if (element instanceof ErrorConfig) {
44                 return ExternalToolsUIMessages.BuilderPropertyPage_invalidBuildTool;
45             }
46             return super.getText(element);
47         }
48         
49         public Image getImage(Object JavaDoc element) {
50             if (element instanceof ICommand) {
51                 return getCommandImage();
52             } else if (element instanceof ILaunchConfiguration || element instanceof ILaunchConfigurationType) {
53                 return getDebugModelImage(element);
54             } else if (element instanceof ErrorConfig) {
55                 return invalidBuildToolImage;
56             }
57             return super.getImage(element);
58         }
59         
60         public String JavaDoc getCommandText(ICommand command) {
61             String JavaDoc builderID = command.getBuilderName();
62             return getBuilderName(builderID);
63         }
64         
65         private String JavaDoc getBuilderName(String JavaDoc builderID) {
66             // Get the human-readable name of the builder
67
IExtension extension = Platform.getExtensionRegistry().getExtension(ResourcesPlugin.PI_RESOURCES, ResourcesPlugin.PT_BUILDERS, builderID);
68             String JavaDoc builderName;
69             if (extension != null) {
70                 builderName = extension.getLabel();
71             } else {
72                 builderName = NLS.bind(ExternalToolsUIMessages.BuilderPropertyPage_missingBuilder, new Object JavaDoc[] { builderID });
73             }
74             return builderName;
75         }
76         
77         /**
78          * Returns the image for build commands.
79          *
80          * @return the build command image
81          */

82         public Image getCommandImage() {
83             return builderImage;
84         }
85         
86         /**
87          * Returns a text label for the given object from a debug
88          * model presentation.
89          * @param element the element
90          * @return a text label from a debug model presentation
91          */

92         public String JavaDoc getDebugModelText(Object JavaDoc element) {
93             if (element instanceof ILaunchConfiguration) {
94                 try {
95                     String JavaDoc disabledBuilderName= ((ILaunchConfiguration) element).getAttribute(IExternalToolConstants.ATTR_DISABLED_BUILDER, (String JavaDoc)null);
96                     if (disabledBuilderName != null) {
97                         //really a disabled builder wrapped as a launch configuration
98
return getBuilderName(disabledBuilderName);
99                     }
100                 } catch (CoreException e) {
101                 }
102             }
103             return debugModelPresentation.getText(element);
104         }
105         
106         /**
107          * Returns an image for the given object from a debug
108          * model presentation.
109          * @param element the element
110          * @return an image from a debug model presentation
111          */

112         public Image getDebugModelImage(Object JavaDoc element) {
113             if (element instanceof ILaunchConfiguration) {
114                 try {
115                     String JavaDoc disabledBuilderName= ((ILaunchConfiguration) element).getAttribute(IExternalToolConstants.ATTR_DISABLED_BUILDER, (String JavaDoc)null);
116                     if (disabledBuilderName != null) {
117                         //really a disabled builder wrapped as a launch configuration
118
return builderImage;
119                     }
120                 } catch (CoreException e) {
121                 }
122             }
123             return debugModelPresentation.getImage(element);
124         }
125             /* (non-Javadoc)
126          * @see org.eclipse.jface.viewers.IBaseLabelProvider#dispose()
127          */

128         public void dispose() {
129             builderImage.dispose();
130             invalidBuildToolImage.dispose();
131         }
132 }
133
Popular Tags