KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > views > dependencies > DependenciesLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.pde.internal.ui.views.dependencies;
12
13 import org.eclipse.jface.viewers.LabelProvider;
14 import org.eclipse.osgi.service.resolver.BaseDescription;
15 import org.eclipse.osgi.service.resolver.BundleDescription;
16 import org.eclipse.osgi.service.resolver.BundleSpecification;
17 import org.eclipse.osgi.service.resolver.ExportPackageDescription;
18 import org.eclipse.osgi.service.resolver.ImportPackageSpecification;
19 import org.eclipse.osgi.service.resolver.VersionConstraint;
20 import org.eclipse.pde.core.plugin.IFragment;
21 import org.eclipse.pde.core.plugin.IFragmentModel;
22 import org.eclipse.pde.core.plugin.IPluginBase;
23 import org.eclipse.pde.core.plugin.IPluginImport;
24 import org.eclipse.pde.core.plugin.IPluginModelBase;
25 import org.eclipse.pde.core.plugin.PluginRegistry;
26 import org.eclipse.pde.internal.ui.PDELabelProvider;
27 import org.eclipse.pde.internal.ui.PDEPlugin;
28 import org.eclipse.pde.internal.ui.PDEPluginImages;
29 import org.eclipse.pde.internal.ui.util.SharedLabelProvider;
30 import org.eclipse.swt.graphics.Image;
31 import org.osgi.framework.Version;
32
33 public class DependenciesLabelProvider extends LabelProvider {
34     private PDELabelProvider fSharedProvider;
35
36     private boolean fShowReexport;
37
38     /**
39      * Constructor for PluginsLabelProvider.
40      */

41     public DependenciesLabelProvider(boolean showRexport) {
42         super();
43         fShowReexport = showRexport;
44         fSharedProvider = PDEPlugin.getDefault().getLabelProvider();
45         fSharedProvider.connect(this);
46     }
47
48     public void dispose() {
49         fSharedProvider.disconnect(this);
50         super.dispose();
51     }
52
53     public String JavaDoc getText(Object JavaDoc obj) {
54         if (obj instanceof IPluginImport) {
55             return ((IPluginImport) obj).getId();
56         } else if (obj instanceof String JavaDoc) {
57             return (String JavaDoc) obj;
58         } else if (obj instanceof IPluginModelBase) {
59             return ((IPluginModelBase) obj).getPluginBase(false).getId();
60         } else if (obj instanceof IPluginBase) {
61             return fSharedProvider.getObjectText((IPluginBase) obj);
62         } else if (obj instanceof BundleDescription) {
63             return getObjectText((BundleDescription)obj);
64         } else if (obj instanceof VersionConstraint) {
65             // ImportPackageSpecification, BundleSpecification
66
BaseDescription desc = ((VersionConstraint)obj).getSupplier();
67             if (desc instanceof BundleDescription)
68                 return getObjectText((BundleDescription)desc);
69             else if (desc instanceof ExportPackageDescription)
70                 return getObjectText(((ExportPackageDescription)desc).getExporter());
71             // if unresolved, just show name
72
return ((VersionConstraint)obj).getName();
73         }
74
75         return fSharedProvider.getText(obj);
76     }
77     
78     public String JavaDoc getObjectText(BundleDescription obj) {
79         String JavaDoc name = fSharedProvider.getObjectText(obj);
80         Version version = obj.getVersion();
81         // Bug 183417 - Bidi3.3: Elements' labels in the extensions page in the fragment manifest characters order is incorrect
82
// Use the PDELabelProvider.formatVersion function to properly format the version for all languages including bidi
83
return name + ' ' + PDELabelProvider.formatVersion(version.toString());
84     }
85
86     public Image getImage(Object JavaDoc obj) {
87         int flags = 0;
88         String JavaDoc id = null;
89         if (obj instanceof IPluginImport) {
90             IPluginImport iobj = (IPluginImport) obj;
91             id = iobj.getId();
92             if (fShowReexport && iobj.isReexported())
93                 flags = SharedLabelProvider.F_EXPORT;
94         } else if (obj instanceof String JavaDoc) {
95             id = (String JavaDoc) obj;
96         }
97         if (id != null) {
98             IPluginModelBase model = PluginRegistry.findModel(id);
99             if (model != null) {
100                 if (model.getUnderlyingResource() == null)
101                     flags |= SharedLabelProvider.F_EXTERNAL;
102             }
103         
104             if (model == null)
105                 flags = SharedLabelProvider.F_ERROR;
106
107             if(model != null && model instanceof IFragmentModel)
108                 return fSharedProvider.get(PDEPluginImages.DESC_FRAGMENT_OBJ, flags);
109             return fSharedProvider.get(PDEPluginImages.DESC_PLUGIN_OBJ, flags);
110         }
111         if (obj instanceof IPluginModelBase) {
112             if (((IPluginModelBase) obj).getUnderlyingResource() == null)
113                 flags |= SharedLabelProvider.F_EXTERNAL;
114             if(obj instanceof IFragmentModel)
115                 return fSharedProvider.get(PDEPluginImages.DESC_FRAGMENT_OBJ, flags);
116             return fSharedProvider.get(PDEPluginImages.DESC_PLUGIN_OBJ, flags);
117         }
118         if (obj instanceof IPluginBase) {
119             if (((IPluginBase) obj).getPluginModel().getUnderlyingResource() == null)
120                 flags |= SharedLabelProvider.F_EXTERNAL;
121             if(obj instanceof IFragment)
122                 return fSharedProvider.get(PDEPluginImages.DESC_FRAGMENT_OBJ, flags);
123             return fSharedProvider.get(PDEPluginImages.DESC_PLUGIN_OBJ, flags);
124         }
125         if (obj instanceof BundleDescription) {
126             id = ((BundleDescription)obj).getSymbolicName();
127         } else if (obj instanceof BundleSpecification) {
128             id = ((VersionConstraint)obj).getName();
129             if (fShowReexport) {
130                 if (((BundleSpecification)obj).isExported())
131                     flags |= SharedLabelProvider.F_EXPORT;
132             }
133         } else if (obj instanceof ImportPackageSpecification) {
134             BaseDescription export = ((ImportPackageSpecification)obj).getSupplier();
135             id = ((ExportPackageDescription)export).getExporter().getSymbolicName();
136         }
137         if (id != null) {
138             IPluginModelBase model = PluginRegistry.findModel(id);
139             if (model != null) {
140                 if (model.getUnderlyingResource() == null)
141                     flags |= SharedLabelProvider.F_EXTERNAL;
142             }
143             if (model == null)
144                 flags = SharedLabelProvider.F_ERROR;
145             if(model != null && model instanceof IFragmentModel)
146                 return fSharedProvider.get(PDEPluginImages.DESC_FRAGMENT_OBJ, flags);
147             return fSharedProvider.get(PDEPluginImages.DESC_PLUGIN_OBJ, flags);
148         }
149         return fSharedProvider.getImage(obj);
150     }
151
152 }
153
Popular Tags