1 11 package org.eclipse.pde.internal.runtime.registry; 12 13 import java.io.IOException ; 14 import java.net.URL ; 15 16 import org.eclipse.core.runtime.FileLocator; 17 import org.eclipse.core.runtime.IConfigurationElement; 18 import org.eclipse.core.runtime.IExtension; 19 import org.eclipse.core.runtime.IExtensionPoint; 20 import org.eclipse.core.runtime.IPath; 21 import org.eclipse.core.runtime.Path; 22 import org.eclipse.jface.resource.ImageDescriptor; 23 import org.eclipse.jface.viewers.LabelProvider; 24 import org.eclipse.jface.viewers.TreeViewer; 25 import org.eclipse.osgi.util.NLS; 26 import org.eclipse.pde.internal.runtime.OverlayIcon; 27 import org.eclipse.pde.internal.runtime.PDERuntimeMessages; 28 import org.eclipse.pde.internal.runtime.PDERuntimePluginImages; 29 import org.eclipse.swt.graphics.Image; 30 import org.osgi.framework.Bundle; 31 32 public class RegistryBrowserLabelProvider extends LabelProvider { 33 34 private Image fPluginImage; 35 private Image fActivePluginImage; 36 private Image fUnresolvedPluginImage; 37 private Image fLibraryImage; 38 private Image fRuntimeImage; 39 private Image fGenericTagImage; 40 private Image fGenericAttrImage; 41 private Image fExtensionImage; 42 private Image fExtensionsImage; 43 private Image fExtensionPointImage; 44 private Image fExtensionPointsImage; 45 private Image fRequiresImage; 46 private Image fExpReqPluginImage; 47 private Image fReqPluginImage; 48 private Image fLocationImage; 49 private TreeViewer fViewer; 50 51 public RegistryBrowserLabelProvider(TreeViewer viewer) { 52 fViewer = viewer; 53 fPluginImage = PDERuntimePluginImages.DESC_PLUGIN_OBJ.createImage(); 54 fReqPluginImage = PDERuntimePluginImages.DESC_REQ_PLUGIN_OBJ.createImage(); 55 fExtensionPointImage = PDERuntimePluginImages.DESC_EXT_POINT_OBJ.createImage(); 56 fExtensionPointsImage = PDERuntimePluginImages.DESC_EXT_POINTS_OBJ.createImage(); 57 fExtensionImage = PDERuntimePluginImages.DESC_EXTENSION_OBJ.createImage(); 58 fExtensionsImage = PDERuntimePluginImages.DESC_EXTENSIONS_OBJ.createImage(); 59 fRequiresImage = PDERuntimePluginImages.DESC_REQ_PLUGINS_OBJ.createImage(); 60 fLibraryImage = PDERuntimePluginImages.DESC_JAVA_LIB_OBJ.createImage(); 61 fGenericTagImage = PDERuntimePluginImages.DESC_GENERIC_XML_OBJ.createImage(); 62 fGenericAttrImage = PDERuntimePluginImages.DESC_ATTR_XML_OBJ.createImage(); 63 fRuntimeImage = PDERuntimePluginImages.DESC_RUNTIME_OBJ.createImage(); 64 fLocationImage = PDERuntimePluginImages.DESC_LOCATION.createImage(); 65 66 ImageDescriptor activePluginDesc = 67 new OverlayIcon( 68 PDERuntimePluginImages.DESC_PLUGIN_OBJ, 69 new ImageDescriptor[][] {{ PDERuntimePluginImages.DESC_RUN_CO }}); 70 fActivePluginImage = activePluginDesc.createImage(); 71 72 ImageDescriptor unresolvedPluginDesc = 73 new OverlayIcon( 74 PDERuntimePluginImages.DESC_PLUGIN_OBJ, 75 new ImageDescriptor[][] {{ PDERuntimePluginImages.DESC_ERROR_CO }}); 76 fUnresolvedPluginImage = unresolvedPluginDesc.createImage(); 77 78 79 ImageDescriptor exportedRequiresDesc = 80 new OverlayIcon( 81 PDERuntimePluginImages.DESC_REQ_PLUGIN_OBJ, 82 new ImageDescriptor[][] {{ PDERuntimePluginImages.DESC_EXPORT_CO }}); 83 fExpReqPluginImage = exportedRequiresDesc.createImage(); 84 85 } 86 public void dispose() { 87 fPluginImage.dispose(); 88 fActivePluginImage.dispose(); 89 fUnresolvedPluginImage.dispose(); 90 fReqPluginImage.dispose(); 91 fExtensionPointImage.dispose(); 92 fExtensionPointsImage.dispose(); 93 fExtensionImage.dispose(); 94 fExtensionsImage.dispose(); 95 fRequiresImage.dispose(); 96 fExpReqPluginImage.dispose(); 97 fLibraryImage.dispose(); 98 fGenericTagImage.dispose(); 99 fGenericAttrImage.dispose(); 100 fRuntimeImage.dispose(); 101 fLocationImage.dispose(); 102 } 103 public Image getImage(Object element) { 104 if (element instanceof PluginObjectAdapter) 105 element = ((PluginObjectAdapter) element).getObject(); 106 107 if (element instanceof Bundle) { 108 Bundle bundle = (Bundle) element; 109 switch (bundle.getState()) { 110 case Bundle.ACTIVE: 111 return fActivePluginImage; 112 case Bundle.INSTALLED: 113 return fUnresolvedPluginImage; 114 case Bundle.UNINSTALLED: 115 return fUnresolvedPluginImage; 116 default: 117 return fPluginImage; 118 } 119 } 120 if (element instanceof IBundleFolder) { 121 int id = ((IBundleFolder) element).getFolderId(); 122 switch (id) { 123 case IBundleFolder.F_EXTENSIONS: 124 return fExtensionsImage; 125 case IBundleFolder.F_EXTENSION_POINTS: 126 return fExtensionPointsImage; 127 case IBundleFolder.F_IMPORTS: 128 return fRequiresImage; 129 case IBundleFolder.F_LIBRARIES: 130 return fRuntimeImage; 131 case IBundleFolder.F_LOCATION: 132 return fLocationImage; 133 } 134 return null; 135 } 136 if (element instanceof IExtension) 137 return fExtensionImage; 138 139 if (element instanceof IExtensionPoint) 140 return fExtensionPointImage; 141 142 if (element instanceof IBundlePrerequisite) 143 return ((IBundlePrerequisite)element).isExported() ? 144 fExpReqPluginImage : fReqPluginImage; 145 146 if (element instanceof IBundleLibrary) 147 return fLibraryImage; 148 149 if (element instanceof IConfigurationElement) 150 return fGenericTagImage; 151 152 if (element instanceof IConfigurationAttribute) 153 return fGenericAttrImage; 154 155 return null; 156 } 157 public String getText(Object element) { 158 if (element instanceof PluginObjectAdapter) 159 element = ((PluginObjectAdapter) element).getObject(); 160 if (element instanceof Bundle) { 161 String id = ((Bundle)element).getSymbolicName(); 162 String version = (String )((Bundle)element).getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION); 163 if (version == null) 164 return id; 165 return id + " (" + version + ")"; } 167 if (element instanceof IBundleFolder) { 168 switch (((IBundleFolder) element).getFolderId()) { 169 case IBundleFolder.F_IMPORTS : 170 return PDERuntimeMessages.RegistryView_folders_imports; 171 case IBundleFolder.F_LIBRARIES : 172 return PDERuntimeMessages.RegistryView_folders_libraries; 173 case IBundleFolder.F_EXTENSION_POINTS : 174 return PDERuntimeMessages.RegistryView_folders_extensionPoints; 175 case IBundleFolder.F_EXTENSIONS : 176 return PDERuntimeMessages.RegistryView_folders_extensions; 177 case IBundleFolder.F_LOCATION: 178 Bundle bundle = ((IBundleFolder) element).getBundle(); 179 URL bundleEntry = bundle.getEntry("/"); try { 181 bundleEntry = FileLocator.resolve(bundleEntry); 182 } catch (IOException e) { 183 } 184 IPath path = new Path(bundleEntry.getFile()); 185 String pathString = path.removeTrailingSeparator().toOSString(); 186 if (pathString.startsWith("file:")) pathString = pathString.substring(5); 188 if (pathString.endsWith("!")) pathString = pathString.substring(0, pathString.length() - 1); 190 return pathString; 191 } 192 } 193 if (element instanceof IExtension) { 194 if (((RegistryBrowserContentProvider)fViewer.getContentProvider()).isInExtensionSet) { 195 String name = ((IExtension) element).getLabel(); 196 String id = ((IExtension) element).getExtensionPointUniqueIdentifier(); 197 if (name != null && name.length() > 0) 198 return NLS.bind(PDERuntimeMessages.RegistryBrowserLabelProvider_nameIdBind, id, name); 199 return id; 200 } 201 202 String contributor = ((IExtension) element).getNamespaceIdentifier(); 203 return NLS.bind("contributed by: {0}", contributor); 205 } 206 if (element instanceof IExtensionPoint) { 207 String id = ((IExtensionPoint)element).getUniqueIdentifier(); 208 String name = ((IExtensionPoint)element).getLabel(); 209 if (name != null && name.length() > 0) 210 return NLS.bind(PDERuntimeMessages.RegistryBrowserLabelProvider_nameIdBind, id, name); 211 return id; 212 } 213 if (element instanceof IBundlePrerequisite) 214 return ((IBundlePrerequisite) element).getLabel(); 215 216 if (element instanceof IBundleLibrary) 217 return ((IBundleLibrary)element).getLibrary(); 218 219 if (element instanceof IConfigurationElement) { 220 String label = ((IConfigurationElement) element).getAttribute("label"); if (label == null) 222 label = ((IConfigurationElement) element).getName(); 223 224 if (label == null) 225 label = ((IConfigurationElement) element).getAttribute("name"); 227 if (label == null && ((IConfigurationElement) element).getAttribute("id") != null){ String [] labelSplit = ((IConfigurationElement) element).getAttribute("id").split("\\."); label = labelSplit.length == 0 ? null: labelSplit[labelSplit.length-1]; 230 } 231 return label; 232 } 233 if (element instanceof IConfigurationAttribute) 234 return ((IConfigurationAttribute)element).getLabel(); 235 236 return super.getText(element); 237 } 238 } 239 | Popular Tags |