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.ui.views.dependencies;
011:
012: import org.eclipse.jface.viewers.LabelProvider;
013: import org.eclipse.osgi.service.resolver.BaseDescription;
014: import org.eclipse.osgi.service.resolver.BundleDescription;
015: import org.eclipse.osgi.service.resolver.BundleSpecification;
016: import org.eclipse.osgi.service.resolver.ExportPackageDescription;
017: import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
018: import org.eclipse.osgi.service.resolver.VersionConstraint;
019: import org.eclipse.pde.core.plugin.IFragment;
020: import org.eclipse.pde.core.plugin.IFragmentModel;
021: import org.eclipse.pde.core.plugin.IPluginBase;
022: import org.eclipse.pde.core.plugin.IPluginImport;
023: import org.eclipse.pde.core.plugin.IPluginModelBase;
024: import org.eclipse.pde.core.plugin.PluginRegistry;
025: import org.eclipse.pde.internal.ui.PDELabelProvider;
026: import org.eclipse.pde.internal.ui.PDEPlugin;
027: import org.eclipse.pde.internal.ui.PDEPluginImages;
028: import org.eclipse.pde.internal.ui.util.SharedLabelProvider;
029: import org.eclipse.swt.graphics.Image;
030: import org.osgi.framework.Version;
031:
032: public class DependenciesLabelProvider extends LabelProvider {
033: private PDELabelProvider fSharedProvider;
034:
035: private boolean fShowReexport;
036:
037: /**
038: * Constructor for PluginsLabelProvider.
039: */
040: public DependenciesLabelProvider(boolean showRexport) {
041: super ();
042: fShowReexport = showRexport;
043: fSharedProvider = PDEPlugin.getDefault().getLabelProvider();
044: fSharedProvider.connect(this );
045: }
046:
047: public void dispose() {
048: fSharedProvider.disconnect(this );
049: super .dispose();
050: }
051:
052: public String getText(Object obj) {
053: if (obj instanceof IPluginImport) {
054: return ((IPluginImport) obj).getId();
055: } else if (obj instanceof String) {
056: return (String) obj;
057: } else if (obj instanceof IPluginModelBase) {
058: return ((IPluginModelBase) obj).getPluginBase(false)
059: .getId();
060: } else if (obj instanceof IPluginBase) {
061: return fSharedProvider.getObjectText((IPluginBase) obj);
062: } else if (obj instanceof BundleDescription) {
063: return getObjectText((BundleDescription) obj);
064: } else if (obj instanceof VersionConstraint) {
065: // ImportPackageSpecification, BundleSpecification
066: BaseDescription desc = ((VersionConstraint) obj)
067: .getSupplier();
068: if (desc instanceof BundleDescription)
069: return getObjectText((BundleDescription) desc);
070: else if (desc instanceof ExportPackageDescription)
071: return getObjectText(((ExportPackageDescription) desc)
072: .getExporter());
073: // if unresolved, just show name
074: return ((VersionConstraint) obj).getName();
075: }
076:
077: return fSharedProvider.getText(obj);
078: }
079:
080: public String getObjectText(BundleDescription obj) {
081: String name = fSharedProvider.getObjectText(obj);
082: Version version = obj.getVersion();
083: // Bug 183417 - Bidi3.3: Elements' labels in the extensions page in the fragment manifest characters order is incorrect
084: // Use the PDELabelProvider.formatVersion function to properly format the version for all languages including bidi
085: return name + ' '
086: + PDELabelProvider.formatVersion(version.toString());
087: }
088:
089: public Image getImage(Object obj) {
090: int flags = 0;
091: String id = null;
092: if (obj instanceof IPluginImport) {
093: IPluginImport iobj = (IPluginImport) obj;
094: id = iobj.getId();
095: if (fShowReexport && iobj.isReexported())
096: flags = SharedLabelProvider.F_EXPORT;
097: } else if (obj instanceof String) {
098: id = (String) obj;
099: }
100: if (id != null) {
101: IPluginModelBase model = PluginRegistry.findModel(id);
102: if (model != null) {
103: if (model.getUnderlyingResource() == null)
104: flags |= SharedLabelProvider.F_EXTERNAL;
105: }
106:
107: if (model == null)
108: flags = SharedLabelProvider.F_ERROR;
109:
110: if (model != null && model instanceof IFragmentModel)
111: return fSharedProvider.get(
112: PDEPluginImages.DESC_FRAGMENT_OBJ, flags);
113: return fSharedProvider.get(PDEPluginImages.DESC_PLUGIN_OBJ,
114: flags);
115: }
116: if (obj instanceof IPluginModelBase) {
117: if (((IPluginModelBase) obj).getUnderlyingResource() == null)
118: flags |= SharedLabelProvider.F_EXTERNAL;
119: if (obj instanceof IFragmentModel)
120: return fSharedProvider.get(
121: PDEPluginImages.DESC_FRAGMENT_OBJ, flags);
122: return fSharedProvider.get(PDEPluginImages.DESC_PLUGIN_OBJ,
123: flags);
124: }
125: if (obj instanceof IPluginBase) {
126: if (((IPluginBase) obj).getPluginModel()
127: .getUnderlyingResource() == null)
128: flags |= SharedLabelProvider.F_EXTERNAL;
129: if (obj instanceof IFragment)
130: return fSharedProvider.get(
131: PDEPluginImages.DESC_FRAGMENT_OBJ, flags);
132: return fSharedProvider.get(PDEPluginImages.DESC_PLUGIN_OBJ,
133: flags);
134: }
135: if (obj instanceof BundleDescription) {
136: id = ((BundleDescription) obj).getSymbolicName();
137: } else if (obj instanceof BundleSpecification) {
138: id = ((VersionConstraint) obj).getName();
139: if (fShowReexport) {
140: if (((BundleSpecification) obj).isExported())
141: flags |= SharedLabelProvider.F_EXPORT;
142: }
143: } else if (obj instanceof ImportPackageSpecification) {
144: BaseDescription export = ((ImportPackageSpecification) obj)
145: .getSupplier();
146: id = ((ExportPackageDescription) export).getExporter()
147: .getSymbolicName();
148: }
149: if (id != null) {
150: IPluginModelBase model = PluginRegistry.findModel(id);
151: if (model != null) {
152: if (model.getUnderlyingResource() == null)
153: flags |= SharedLabelProvider.F_EXTERNAL;
154: }
155: if (model == null)
156: flags = SharedLabelProvider.F_ERROR;
157: if (model != null && model instanceof IFragmentModel)
158: return fSharedProvider.get(
159: PDEPluginImages.DESC_FRAGMENT_OBJ, flags);
160: return fSharedProvider.get(PDEPluginImages.DESC_PLUGIN_OBJ,
161: flags);
162: }
163: return fSharedProvider.getImage(obj);
164: }
165:
166: }
|