KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > view > DependenciesLabelProvider


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.view;
12
13 import org.eclipse.jface.viewers.LabelProvider;
14 import org.eclipse.pde.core.plugin.IFragment;
15 import org.eclipse.pde.core.plugin.IFragmentModel;
16 import org.eclipse.pde.core.plugin.IPluginBase;
17 import org.eclipse.pde.core.plugin.IPluginImport;
18 import org.eclipse.pde.core.plugin.IPluginModelBase;
19 import org.eclipse.pde.internal.core.PDECore;
20 import org.eclipse.pde.internal.ui.PDELabelProvider;
21 import org.eclipse.pde.internal.ui.PDEPlugin;
22 import org.eclipse.pde.internal.ui.PDEPluginImages;
23 import org.eclipse.pde.internal.ui.util.SharedLabelProvider;
24 import org.eclipse.swt.graphics.Image;
25
26 public class DependenciesLabelProvider extends LabelProvider {
27     private PDELabelProvider fSharedProvider;
28
29     private boolean fShowReexport;
30
31     /**
32      * Constructor for PluginsLabelProvider.
33      */

34     public DependenciesLabelProvider(boolean showRexport) {
35         super();
36         fShowReexport = showRexport;
37         fSharedProvider = PDEPlugin.getDefault().getLabelProvider();
38         fSharedProvider.connect(this);
39     }
40
41     public void dispose() {
42         fSharedProvider.disconnect(this);
43         super.dispose();
44     }
45
46     public String JavaDoc getText(Object JavaDoc obj) {
47         if (obj instanceof IPluginImport) {
48             return ((IPluginImport) obj).getId();
49         } else if (obj instanceof String JavaDoc) {
50             return (String JavaDoc) obj;
51         } else if (obj instanceof IPluginModelBase) {
52             return ((IPluginModelBase) obj).getPluginBase(false).getId();
53         } else if (obj instanceof IPluginBase) {
54             return ((IPluginBase) obj).getId();
55         }
56
57         return fSharedProvider.getText(obj);
58     }
59
60     public Image getImage(Object JavaDoc obj) {
61         int flags = 0;
62         String JavaDoc id = null;
63         if (obj instanceof IPluginImport) {
64             IPluginImport iobj = (IPluginImport) obj;
65             id = iobj.getId();
66             if (fShowReexport && iobj.isReexported())
67                 flags = SharedLabelProvider.F_EXPORT;
68         } else if (obj instanceof String JavaDoc) {
69             id = (String JavaDoc) obj;
70         }
71         if (id != null) {
72             IPluginModelBase model = PDECore.getDefault().getModelManager().findModel(id);
73             if (model != null) {
74                 if (model.getUnderlyingResource() == null)
75                     flags |= SharedLabelProvider.F_EXTERNAL;
76             }
77         
78             if (model == null)
79                 flags = SharedLabelProvider.F_ERROR;
80
81             if(model != null && model instanceof IFragmentModel)
82                 return fSharedProvider.get(PDEPluginImages.DESC_FRAGMENT_OBJ, flags);
83             return fSharedProvider.get(PDEPluginImages.DESC_PLUGIN_OBJ, flags);
84         }
85         if (obj instanceof IPluginModelBase) {
86             if (((IPluginModelBase) obj).getUnderlyingResource() == null)
87                 flags |= SharedLabelProvider.F_EXTERNAL;
88             if(obj instanceof IFragmentModel)
89                 return fSharedProvider.get(PDEPluginImages.DESC_FRAGMENT_OBJ, flags);
90             return fSharedProvider.get(PDEPluginImages.DESC_PLUGIN_OBJ, flags);
91         }
92         if (obj instanceof IPluginBase) {
93             if (((IPluginBase) obj).getPluginModel().getUnderlyingResource() == null)
94                 flags |= SharedLabelProvider.F_EXTERNAL;
95             if(obj instanceof IFragment)
96                 return fSharedProvider.get(PDEPluginImages.DESC_FRAGMENT_OBJ, flags);
97             return fSharedProvider.get(PDEPluginImages.DESC_PLUGIN_OBJ, flags);
98         }
99         return fSharedProvider.getImage(obj);
100     }
101
102 }
103
Popular Tags