KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.*;
14
15 import org.eclipse.core.runtime.*;
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.ui.views.properties.*;
20
21 public class FeatureEntryPropertySource extends FeaturePropertySource {
22     protected Vector descriptors;
23     public final static String JavaDoc KEY_ID = "FeatureEditor.ReferenceProp.id"; //$NON-NLS-1$
24
public final static String JavaDoc KEY_VERSION =
25         "FeatureEditor.ReferenceProp.version"; //$NON-NLS-1$
26
public final static String JavaDoc KEY_DOWNLOAD_SIZE =
27         "FeatureEditor.ReferenceProp.download-size"; //$NON-NLS-1$
28
public final static String JavaDoc KEY_INSTALL_SIZE =
29         "FeatureEditor.ReferenceProp.install-size"; //$NON-NLS-1$
30

31     private final static String JavaDoc P_ID = "id"; //$NON-NLS-1$
32
private final static String JavaDoc P_OS = "os"; //$NON-NLS-1$
33
private final static String JavaDoc P_WS = "ws"; //$NON-NLS-1$
34
private final static String JavaDoc P_NL = "nl"; //$NON-NLS-1$
35
private final static String JavaDoc P_ARCH = "arch"; //$NON-NLS-1$
36
private final static String JavaDoc P_INSTALL_SIZE = "install-size"; //$NON-NLS-1$
37
private final static String JavaDoc P_DOWNLOAD_SIZE = "download-size"; //$NON-NLS-1$
38

39     public FeatureEntryPropertySource(IFeatureEntry entry) {
40         super(entry);
41     }
42
43     protected void createPropertyDescriptors() {
44         descriptors = new Vector();
45         PropertyDescriptor desc =
46             new PropertyDescriptor(P_ID, PDEPlugin.getResourceString(KEY_ID));
47         descriptors.addElement(desc);
48         desc =
49             createTextPropertyDescriptor(
50                 P_INSTALL_SIZE,
51                 PDEPlugin.getResourceString(KEY_INSTALL_SIZE));
52         descriptors.addElement(desc);
53         desc =
54             createTextPropertyDescriptor(
55                 P_DOWNLOAD_SIZE,
56                 PDEPlugin.getResourceString(KEY_DOWNLOAD_SIZE));
57         descriptors.addElement(desc);
58
59         desc = createChoicePropertyDescriptor(P_OS, P_OS, getOSChoices());
60         descriptors.addElement(desc);
61         desc = createChoicePropertyDescriptor(P_WS, P_WS, getWSChoices());
62         descriptors.addElement(desc);
63         desc = createChoicePropertyDescriptor(P_NL, P_NL, getNLChoices());
64         descriptors.addElement(desc);
65         desc = createChoicePropertyDescriptor(P_ARCH, P_ARCH, getArchChoices());
66         descriptors.addElement(desc);
67     }
68     
69     public IFeatureEntry getEntry() {
70         return (IFeatureEntry)object;
71     }
72
73     public IPropertyDescriptor[] getPropertyDescriptors() {
74         if (descriptors == null) {
75             createPropertyDescriptors();
76         }
77         return toDescriptorArray(descriptors);
78     }
79
80     private PropertyDescriptor createChoicePropertyDescriptor(
81         String JavaDoc name,
82         String JavaDoc displayName,
83         Choice[] choices) {
84         return new PortabilityChoiceDescriptor(
85             name,
86             displayName,
87             choices,
88             !isEditable());
89     }
90
91     public Object JavaDoc getPropertyValue(Object JavaDoc name) {
92         if (name.equals(P_ID)) {
93             return getEntry().getId();
94         }
95
96         if (name.equals(P_INSTALL_SIZE)) {
97             long installSize = getEntry().getInstallSize();
98             if (installSize == -1)
99                 return ""; //$NON-NLS-1$
100
else
101                 return "" + installSize; //$NON-NLS-1$
102
}
103         if (name.equals(P_DOWNLOAD_SIZE)) {
104             long downloadSize = getEntry().getDownloadSize();
105             if (downloadSize == -1)
106                 return ""; //$NON-NLS-1$
107
else
108                 return "" + downloadSize; //$NON-NLS-1$
109
}
110         if (name.equals(P_OS)) {
111             return getEntry().getOS();
112         }
113         if (name.equals(P_WS)) {
114             return getEntry().getWS();
115         }
116         if (name.equals(P_NL)) {
117             return getEntry().getNL();
118         }
119         if (name.equals(P_ARCH)) {
120             return getEntry().getArch();
121         }
122         return null;
123     }
124     public void setElement(IFeatureEntry entry) {
125         object = entry;
126     }
127     public void setPropertyValue(Object JavaDoc name, Object JavaDoc value) {
128         String JavaDoc svalue = value.toString();
129         String JavaDoc realValue =
130             svalue == null | svalue.length() == 0 ? null : svalue;
131         try {
132             if (name.equals(P_OS)) {
133                 getEntry().setOS(realValue);
134             } else if (name.equals(P_WS)) {
135                 getEntry().setWS(realValue);
136             } else if (name.equals(P_NL)) {
137                 getEntry().setNL(realValue);
138             } else if (name.equals(P_ARCH)) {
139                 getEntry().setArch(realValue);
140             } else if (name.equals(P_DOWNLOAD_SIZE)) {
141                 long lvalue = getLong(realValue);
142                 getEntry().setDownloadSize(lvalue);
143             } else if (name.equals(P_INSTALL_SIZE)) {
144                 long lvalue = getLong(realValue);
145                 getEntry().setInstallSize(lvalue);
146             }
147         } catch (CoreException e) {
148             PDEPlugin.logException(e);
149         }
150     }
151
152     private long getLong(String JavaDoc svalue) {
153         if (svalue == null)
154             return -1;
155         try {
156             return Long.parseLong(svalue);
157         } catch (NumberFormatException JavaDoc e) {
158             return -1;
159         }
160     }
161
162     public static Choice[] getOSChoices() {
163         return TargetPlatform.getOSChoices();
164     }
165
166     public static Choice[] getWSChoices() {
167         return TargetPlatform.getWSChoices();
168     }
169
170     public static Choice[] getArchChoices() {
171         return TargetPlatform.getArchChoices();
172     }
173
174     public static Choice[] getNLChoices() {
175         return TargetPlatform.getNLChoices();
176     }
177 }
178
Popular Tags