1 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 IMG_BUILDER = "icons/full/obj16/builder.gif"; private static final String IMG_INVALID_BUILD_TOOL = "icons/full/obj16/invalid_build_tool.gif"; 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 getText(Object 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 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 getCommandText(ICommand command) { 61 String builderID = command.getBuilderName(); 62 return getBuilderName(builderID); 63 } 64 65 private String getBuilderName(String builderID) { 66 IExtension extension = Platform.getExtensionRegistry().getExtension(ResourcesPlugin.PI_RESOURCES, ResourcesPlugin.PT_BUILDERS, builderID); 68 String builderName; 69 if (extension != null) { 70 builderName = extension.getLabel(); 71 } else { 72 builderName = NLS.bind(ExternalToolsUIMessages.BuilderPropertyPage_missingBuilder, new Object [] { builderID }); 73 } 74 return builderName; 75 } 76 77 82 public Image getCommandImage() { 83 return builderImage; 84 } 85 86 92 public String getDebugModelText(Object element) { 93 if (element instanceof ILaunchConfiguration) { 94 try { 95 String disabledBuilderName= ((ILaunchConfiguration) element).getAttribute(IExternalToolConstants.ATTR_DISABLED_BUILDER, (String )null); 96 if (disabledBuilderName != null) { 97 return getBuilderName(disabledBuilderName); 99 } 100 } catch (CoreException e) { 101 } 102 } 103 return debugModelPresentation.getText(element); 104 } 105 106 112 public Image getDebugModelImage(Object element) { 113 if (element instanceof ILaunchConfiguration) { 114 try { 115 String disabledBuilderName= ((ILaunchConfiguration) element).getAttribute(IExternalToolConstants.ATTR_DISABLED_BUILDER, (String )null); 116 if (disabledBuilderName != null) { 117 return builderImage; 119 } 120 } catch (CoreException e) { 121 } 122 } 123 return debugModelPresentation.getImage(element); 124 } 125 128 public void dispose() { 129 builderImage.dispose(); 130 invalidBuildToolImage.dispose(); 131 } 132 } 133 | Popular Tags |