001: /*******************************************************************************
002: * Copyright (c) 2000, 2007 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.internal.runtime.registry;
011:
012: import java.io.IOException;
013: import java.net.URL;
014:
015: import org.eclipse.core.runtime.FileLocator;
016: import org.eclipse.core.runtime.IConfigurationElement;
017: import org.eclipse.core.runtime.IExtension;
018: import org.eclipse.core.runtime.IExtensionPoint;
019: import org.eclipse.core.runtime.IPath;
020: import org.eclipse.core.runtime.Path;
021: import org.eclipse.jface.resource.ImageDescriptor;
022: import org.eclipse.jface.viewers.LabelProvider;
023: import org.eclipse.jface.viewers.TreeViewer;
024: import org.eclipse.osgi.util.NLS;
025: import org.eclipse.pde.internal.runtime.OverlayIcon;
026: import org.eclipse.pde.internal.runtime.PDERuntimeMessages;
027: import org.eclipse.pde.internal.runtime.PDERuntimePluginImages;
028: import org.eclipse.swt.graphics.Image;
029: import org.osgi.framework.Bundle;
030:
031: public class RegistryBrowserLabelProvider extends LabelProvider {
032:
033: private Image fPluginImage;
034: private Image fActivePluginImage;
035: private Image fUnresolvedPluginImage;
036: private Image fLibraryImage;
037: private Image fRuntimeImage;
038: private Image fGenericTagImage;
039: private Image fGenericAttrImage;
040: private Image fExtensionImage;
041: private Image fExtensionsImage;
042: private Image fExtensionPointImage;
043: private Image fExtensionPointsImage;
044: private Image fRequiresImage;
045: private Image fExpReqPluginImage;
046: private Image fReqPluginImage;
047: private Image fLocationImage;
048: private TreeViewer fViewer;
049:
050: public RegistryBrowserLabelProvider(TreeViewer viewer) {
051: fViewer = viewer;
052: fPluginImage = PDERuntimePluginImages.DESC_PLUGIN_OBJ
053: .createImage();
054: fReqPluginImage = PDERuntimePluginImages.DESC_REQ_PLUGIN_OBJ
055: .createImage();
056: fExtensionPointImage = PDERuntimePluginImages.DESC_EXT_POINT_OBJ
057: .createImage();
058: fExtensionPointsImage = PDERuntimePluginImages.DESC_EXT_POINTS_OBJ
059: .createImage();
060: fExtensionImage = PDERuntimePluginImages.DESC_EXTENSION_OBJ
061: .createImage();
062: fExtensionsImage = PDERuntimePluginImages.DESC_EXTENSIONS_OBJ
063: .createImage();
064: fRequiresImage = PDERuntimePluginImages.DESC_REQ_PLUGINS_OBJ
065: .createImage();
066: fLibraryImage = PDERuntimePluginImages.DESC_JAVA_LIB_OBJ
067: .createImage();
068: fGenericTagImage = PDERuntimePluginImages.DESC_GENERIC_XML_OBJ
069: .createImage();
070: fGenericAttrImage = PDERuntimePluginImages.DESC_ATTR_XML_OBJ
071: .createImage();
072: fRuntimeImage = PDERuntimePluginImages.DESC_RUNTIME_OBJ
073: .createImage();
074: fLocationImage = PDERuntimePluginImages.DESC_LOCATION
075: .createImage();
076:
077: ImageDescriptor activePluginDesc = new OverlayIcon(
078: PDERuntimePluginImages.DESC_PLUGIN_OBJ,
079: new ImageDescriptor[][] { { PDERuntimePluginImages.DESC_RUN_CO } });
080: fActivePluginImage = activePluginDesc.createImage();
081:
082: ImageDescriptor unresolvedPluginDesc = new OverlayIcon(
083: PDERuntimePluginImages.DESC_PLUGIN_OBJ,
084: new ImageDescriptor[][] { { PDERuntimePluginImages.DESC_ERROR_CO } });
085: fUnresolvedPluginImage = unresolvedPluginDesc.createImage();
086:
087: ImageDescriptor exportedRequiresDesc = new OverlayIcon(
088: PDERuntimePluginImages.DESC_REQ_PLUGIN_OBJ,
089: new ImageDescriptor[][] { { PDERuntimePluginImages.DESC_EXPORT_CO } });
090: fExpReqPluginImage = exportedRequiresDesc.createImage();
091:
092: }
093:
094: public void dispose() {
095: fPluginImage.dispose();
096: fActivePluginImage.dispose();
097: fUnresolvedPluginImage.dispose();
098: fReqPluginImage.dispose();
099: fExtensionPointImage.dispose();
100: fExtensionPointsImage.dispose();
101: fExtensionImage.dispose();
102: fExtensionsImage.dispose();
103: fRequiresImage.dispose();
104: fExpReqPluginImage.dispose();
105: fLibraryImage.dispose();
106: fGenericTagImage.dispose();
107: fGenericAttrImage.dispose();
108: fRuntimeImage.dispose();
109: fLocationImage.dispose();
110: }
111:
112: public Image getImage(Object element) {
113: if (element instanceof PluginObjectAdapter)
114: element = ((PluginObjectAdapter) element).getObject();
115:
116: if (element instanceof Bundle) {
117: Bundle bundle = (Bundle) element;
118: switch (bundle.getState()) {
119: case Bundle.ACTIVE:
120: return fActivePluginImage;
121: case Bundle.UNINSTALLED:
122: return fUnresolvedPluginImage;
123: default:
124: return fPluginImage;
125: }
126: }
127: if (element instanceof IBundleFolder) {
128: int id = ((IBundleFolder) element).getFolderId();
129: switch (id) {
130: case IBundleFolder.F_EXTENSIONS:
131: return fExtensionsImage;
132: case IBundleFolder.F_EXTENSION_POINTS:
133: return fExtensionPointsImage;
134: case IBundleFolder.F_IMPORTS:
135: return fRequiresImage;
136: case IBundleFolder.F_LIBRARIES:
137: return fRuntimeImage;
138: case IBundleFolder.F_LOCATION:
139: return fLocationImage;
140: }
141: return null;
142: }
143: if (element instanceof IExtension)
144: return fExtensionImage;
145:
146: if (element instanceof IExtensionPoint)
147: return fExtensionPointImage;
148:
149: if (element instanceof IBundlePrerequisite)
150: return ((IBundlePrerequisite) element).isExported() ? fExpReqPluginImage
151: : fReqPluginImage;
152:
153: if (element instanceof IBundleLibrary)
154: return fLibraryImage;
155:
156: if (element instanceof IConfigurationElement)
157: return fGenericTagImage;
158:
159: if (element instanceof IConfigurationAttribute)
160: return fGenericAttrImage;
161:
162: return null;
163: }
164:
165: public String getText(Object element) {
166: if (element instanceof PluginObjectAdapter)
167: element = ((PluginObjectAdapter) element).getObject();
168: if (element instanceof Bundle) {
169: String id = ((Bundle) element).getSymbolicName();
170: String version = (String) ((Bundle) element).getHeaders()
171: .get(org.osgi.framework.Constants.BUNDLE_VERSION);
172: if (version == null)
173: return id;
174: return id + " (" + version + ")"; //$NON-NLS-1$ //$NON-NLS-2$
175: }
176: if (element instanceof IBundleFolder) {
177: switch (((IBundleFolder) element).getFolderId()) {
178: case IBundleFolder.F_IMPORTS:
179: return PDERuntimeMessages.RegistryView_folders_imports;
180: case IBundleFolder.F_LIBRARIES:
181: return PDERuntimeMessages.RegistryView_folders_libraries;
182: case IBundleFolder.F_EXTENSION_POINTS:
183: return PDERuntimeMessages.RegistryView_folders_extensionPoints;
184: case IBundleFolder.F_EXTENSIONS:
185: return PDERuntimeMessages.RegistryView_folders_extensions;
186: case IBundleFolder.F_LOCATION:
187: Bundle bundle = ((IBundleFolder) element).getBundle();
188: URL bundleEntry = bundle.getEntry("/"); //$NON-NLS-1$
189: try {
190: bundleEntry = FileLocator.resolve(bundleEntry);
191: } catch (IOException e) {
192: }
193: IPath path = new Path(bundleEntry.getFile());
194: String pathString = path.removeTrailingSeparator()
195: .toOSString();
196: if (pathString.startsWith("file:")) //$NON-NLS-1$
197: pathString = pathString.substring(5);
198: if (pathString.endsWith("!")) //$NON-NLS-1$
199: pathString = pathString.substring(0, pathString
200: .length() - 1);
201: return pathString;
202: }
203: }
204: if (element instanceof IExtension) {
205: if (((RegistryBrowserContentProvider) fViewer
206: .getContentProvider()).isInExtensionSet) {
207: String name = ((IExtension) element).getLabel();
208: String id = ((IExtension) element)
209: .getExtensionPointUniqueIdentifier();
210: if (name != null && name.length() > 0)
211: return NLS
212: .bind(
213: PDERuntimeMessages.RegistryBrowserLabelProvider_nameIdBind,
214: id, name);
215: return id;
216: }
217:
218: String contributor = ((IExtension) element)
219: .getNamespaceIdentifier();
220: return NLS.bind("contributed by: {0}", contributor); //$NON-NLS-1$
221:
222: }
223: if (element instanceof IExtensionPoint) {
224: String id = ((IExtensionPoint) element)
225: .getUniqueIdentifier();
226: String name = ((IExtensionPoint) element).getLabel();
227: if (name != null && name.length() > 0)
228: return NLS
229: .bind(
230: PDERuntimeMessages.RegistryBrowserLabelProvider_nameIdBind,
231: id, name);
232: return id;
233: }
234: if (element instanceof IBundlePrerequisite)
235: return ((IBundlePrerequisite) element).getLabel();
236:
237: if (element instanceof IBundleLibrary)
238: return ((IBundleLibrary) element).getLibrary();
239:
240: if (element instanceof IConfigurationElement) {
241: String label = ((IConfigurationElement) element)
242: .getAttribute("label"); //$NON-NLS-1$
243: if (label == null)
244: label = ((IConfigurationElement) element).getName();
245:
246: if (label == null)
247: label = ((IConfigurationElement) element)
248: .getAttribute("name"); //$NON-NLS-1$
249:
250: if (label == null
251: && ((IConfigurationElement) element)
252: .getAttribute("id") != null) { //$NON-NLS-1$
253: String[] labelSplit = ((IConfigurationElement) element)
254: .getAttribute("id").split("\\."); //$NON-NLS-1$ //$NON-NLS-2$
255: label = labelSplit.length == 0 ? null
256: : labelSplit[labelSplit.length - 1];
257: }
258: return label;
259: }
260: if (element instanceof IConfigurationAttribute)
261: return ((IConfigurationAttribute) element).getLabel();
262:
263: return super.getText(element);
264: }
265: }
|