KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > editor > feature > ReferencePropertySource


1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.pde.internal.ui.editor.feature;
12
13 import org.eclipse.core.runtime.*;
14 import org.eclipse.jface.viewers.*;
15 import org.eclipse.pde.core.plugin.*;
16 import org.eclipse.pde.internal.core.*;
17 import org.eclipse.pde.internal.core.ifeature.*;
18 import org.eclipse.pde.internal.ui.*;
19 import org.eclipse.swt.graphics.*;
20 import org.eclipse.ui.views.properties.*;
21
22 public class ReferencePropertySource extends FeatureEntryPropertySource {
23     private IPluginBase pluginBase;
24     private Image errorImage;
25     public final static String JavaDoc KEY_NAME = "FeatureEditor.ReferenceProp.name"; //$NON-NLS-1$
26
public final static String JavaDoc KEY_VERSION =
27         "FeatureEditor.ReferenceProp.version"; //$NON-NLS-1$
28
public final static String JavaDoc KEY_ORIGINAL_VERSION =
29         "FeatureEditor.ReferenceProp.originalVersion"; //$NON-NLS-1$
30

31     private final static String JavaDoc P_NAME = "name"; //$NON-NLS-1$
32
private final static String JavaDoc P_VERSION = "version"; //$NON-NLS-1$
33
private final static String JavaDoc P_REF_VERSION = "ref_version"; //$NON-NLS-1$
34

35     public class VersionProvider extends LabelProvider {
36         public Image getImage(Object JavaDoc obj) {
37             String JavaDoc originalVersion = getOriginalVersion();
38             IFeaturePlugin ref = getPluginReference();
39             boolean inSync = ref.getVersion().equals(originalVersion);
40             return inSync ? null : errorImage;
41         }
42     }
43
44     public ReferencePropertySource(
45         IFeaturePlugin reference,
46         Image errorImage) {
47         super(reference);
48         this.errorImage = errorImage;
49     }
50     private String JavaDoc getOriginalVersion() {
51         IPluginBase pluginBase = getPluginBase();
52         if (pluginBase == null)
53             return ""; //$NON-NLS-1$
54
return pluginBase.getVersion();
55     }
56     private IPluginBase getPluginBase() {
57         if (pluginBase == null) {
58             IFeaturePlugin reference = getPluginReference();
59             if (reference.getModel().getUnderlyingResource() == null)
60                 return null;
61             String JavaDoc id = reference.getId();
62             WorkspaceModelManager manager =
63                 PDECore.getDefault().getWorkspaceModelManager();
64             IPluginModelBase[] models = null;
65             if (reference.isFragment()) {
66                 models = manager.getFragmentModels();
67             } else {
68                 models = manager.getPluginModels();
69             }
70             for (int i = 0; i < models.length; i++) {
71                 IPluginModelBase modelBase = models[i];
72                 IPluginBase candidate = modelBase.getPluginBase();
73                 if (candidate.getId().equals(id)) {
74                     pluginBase = candidate;
75                     break;
76                 }
77             }
78         }
79         return pluginBase;
80     }
81     public IFeaturePlugin getPluginReference() {
82         return (IFeaturePlugin) object;
83     }
84     protected void createPropertyDescriptors() {
85         super.createPropertyDescriptors();
86         PropertyDescriptor desc;
87         desc =
88             new PropertyDescriptor(
89                 P_NAME,
90                 PDEPlugin.getResourceString(KEY_NAME));
91         descriptors.addElement(desc);
92         desc =
93             createTextPropertyDescriptor(
94                 P_VERSION,
95                 PDEPlugin.getResourceString(KEY_VERSION));
96         //desc.setLabelProvider(new VersionProvider());
97
descriptors.addElement(desc);
98         desc =
99             new PropertyDescriptor(
100                 P_REF_VERSION,
101                 PDEPlugin.getResourceString(KEY_ORIGINAL_VERSION));
102
103     }
104
105     public Object JavaDoc getPropertyValue(Object JavaDoc name) {
106         if (name.equals(P_NAME)) {
107             return getPluginReference().getLabel();
108         }
109         if (name.equals(P_VERSION)) {
110             return getPluginReference().getVersion();
111         }
112         if (name.equals(P_REF_VERSION)) {
113             return getOriginalVersion();
114         }
115         return super.getPropertyValue(name);
116     }
117     public void setElement(IFeaturePlugin plugin) {
118         object = plugin;
119     }
120     public void setPropertyValue(Object JavaDoc name, Object JavaDoc value) {
121         String JavaDoc svalue = value.toString();
122         String JavaDoc realValue =
123             svalue == null | svalue.length() == 0 ? null : svalue;
124         try {
125             if (name.equals(P_NAME)) {
126                 getPluginReference().setLabel(realValue);
127             } else if (name.equals(P_VERSION)) {
128                 getPluginReference().setVersion(realValue);
129             } else super.setPropertyValue(name, value);
130         } catch (CoreException e) {
131             PDEPlugin.logException(e);
132         }
133     }
134 }
135
Popular Tags