KickJava   Java API By Example, From Geeks To Geeks.

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


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.core.plugin.*;
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 FeatureChildPropertySource extends FeaturePropertySource {
22     protected Vector descriptors;
23     public final static String JavaDoc KEY_ID = "FeatureEditor.ChildProp.id"; //$NON-NLS-1$
24
public final static String JavaDoc KEY_VERSION = "FeatureEditor.ChildProp.version"; //$NON-NLS-1$
25
public final static String JavaDoc KEY_OPTIONAL =
26         "FeatureEditor.ChildProp.optional"; //$NON-NLS-1$
27
public final static String JavaDoc KEY_MATCH = "FeatureEditor.ChildProp.match"; //$NON-NLS-1$
28
public final static String JavaDoc KEY_NAME = "FeatureEditor.ChildProp.name"; //$NON-NLS-1$
29
public final static String JavaDoc KEY_SEARCH_LOCATION =
30         "FeatureEditor.ChildProp.search-location"; //$NON-NLS-1$
31
private final static String JavaDoc P_ID = "id"; //$NON-NLS-1$
32
private final static String JavaDoc P_VERSION = "version"; //$NON-NLS-1$
33
private final static String JavaDoc P_OPTIONAL = "optional"; //$NON-NLS-1$
34
private final static String JavaDoc P_MATCH = "match"; //$NON-NLS-1$
35
private final static String JavaDoc P_NAME = "name"; //$NON-NLS-1$
36
private final static String JavaDoc P_SEARCH_LOCATION = "search-location"; //$NON-NLS-1$
37
private final static String JavaDoc P_OS = "os"; //$NON-NLS-1$
38
private final static String JavaDoc P_WS = "ws"; //$NON-NLS-1$
39
private final static String JavaDoc P_ARCH = "arch"; //$NON-NLS-1$
40

41     public FeatureChildPropertySource(IFeatureChild child) {
42         super(child);
43     }
44
45     protected void createPropertyDescriptors() {
46         descriptors = new Vector();
47         PropertyDescriptor desc =
48             createTextPropertyDescriptor(
49                 P_ID,
50                 PDEPlugin.getResourceString(KEY_ID));
51         descriptors.addElement(desc);
52         desc =
53             createTextPropertyDescriptor(
54                 P_VERSION,
55                 PDEPlugin.getResourceString(KEY_VERSION));
56         descriptors.addElement(desc);
57
58         desc =
59             createTextPropertyDescriptor(
60                 P_NAME,
61                 PDEPlugin.getResourceString(KEY_NAME));
62         descriptors.addElement(desc);
63
64         desc =
65             createChoicePropertyDescriptor(
66                 P_MATCH,
67                 PDEPlugin.getResourceString(KEY_MATCH),
68                 IMatchRules.RULE_NAME_TABLE);
69         descriptors.addElement(desc);
70         desc =
71             createChoicePropertyDescriptor(
72                 P_OPTIONAL,
73                 PDEPlugin.getResourceString(KEY_OPTIONAL),
74                 new String JavaDoc[] { "false", "true" }); //$NON-NLS-1$ //$NON-NLS-2$
75
descriptors.addElement(desc);
76         desc =
77             createChoicePropertyDescriptor(
78                 P_SEARCH_LOCATION,
79                 PDEPlugin.getResourceString(KEY_SEARCH_LOCATION),
80                 new String JavaDoc[] { "root", "self", "both" }); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
81
descriptors.addElement(desc);
82         // Hiding this support for 2.1
83
/*
84         desc =
85             createChoicePropertyDescriptor(
86                 P_OS,
87                 P_OS,
88                 TargetPlatform.getOSChoices());
89         descriptors.addElement(desc);
90         desc =
91             createChoicePropertyDescriptor(
92                 P_WS,
93                 P_WS,
94                 TargetPlatform.getWSChoices());
95         descriptors.addElement(desc);
96         desc =
97             createChoicePropertyDescriptor(
98                 P_ARCH,
99                 P_ARCH,
100                 TargetPlatform.getArchChoices());
101         descriptors.addElement(desc);
102         */

103
104     }
105
106     /*private PropertyDescriptor createChoicePropertyDescriptor(
107         String name,
108         String displayName,
109         Choice[] choices) {
110         return new PortabilityChoiceDescriptor(
111             name,
112             displayName,
113             choices,
114             !isEditable());
115     }*/

116
117     public IFeatureChild getChild() {
118         return (IFeatureChild) object;
119     }
120
121     public IPropertyDescriptor[] getPropertyDescriptors() {
122         if (descriptors == null) {
123             createPropertyDescriptors();
124         }
125         return toDescriptorArray(descriptors);
126     }
127
128     public Object JavaDoc getPropertyValue(Object JavaDoc name) {
129         if (name.equals(P_ID)) {
130             return getNonzeroValue(getChild().getId());
131         }
132
133         if (name.equals(P_VERSION)) {
134             return getNonzeroValue(getChild().getVersion());
135         }
136
137         if (name.equals(P_OPTIONAL)) {
138             return getChild().isOptional() ? new Integer JavaDoc(1) : new Integer JavaDoc(0);
139         }
140         if (name.equals(P_NAME)) {
141             return getChild().getName();
142         }
143         if (name.equals(P_SEARCH_LOCATION)) {
144             int loc = getChild().getSearchLocation();
145             return new Integer JavaDoc(loc);
146         }
147         if (name.equals(P_MATCH)) {
148             return new Integer JavaDoc(getChild().getMatch());
149         }
150         if (name.equals(P_OS)) {
151             return getChild().getOS();
152         }
153         if (name.equals(P_WS)) {
154             return getChild().getWS();
155         }
156         if (name.equals(P_ARCH)) {
157             return getChild().getArch();
158         }
159         return null;
160     }
161
162     private String JavaDoc getNonzeroValue(Object JavaDoc obj) {
163         return obj != null ? obj.toString() : ""; //$NON-NLS-1$
164
}
165
166     public void setElement(IFeatureEntry entry) {
167         object = entry;
168     }
169
170     public void setPropertyValue(Object JavaDoc name, Object JavaDoc value) {
171         String JavaDoc svalue = value.toString();
172         String JavaDoc realValue =
173             svalue == null | svalue.length() == 0 ? null : svalue;
174         try {
175             if (name.equals(P_ID)) {
176                 getChild().setId(realValue);
177             } else if (name.equals(P_VERSION)) {
178                 getChild().setVersion(realValue);
179             } else if (name.equals(P_NAME)) {
180                 getChild().setName(realValue);
181             } else if (name.equals(P_OPTIONAL)) {
182                 Integer JavaDoc index = (Integer JavaDoc) value;
183                 getChild().setOptional(index.intValue() == 1);
184             } else if (name.equals(P_MATCH)) {
185                 Integer JavaDoc index = (Integer JavaDoc) value;
186                 getChild().setMatch(index.intValue());
187             } else if (name.equals(P_SEARCH_LOCATION)) {
188                 Integer JavaDoc index = (Integer JavaDoc) value;
189                 getChild().setSearchLocation(index.intValue());
190             } else if (name.equals(P_OS)) {
191                 getChild().setOS(realValue);
192             } else if (name.equals(P_WS)) {
193                 getChild().setWS(realValue);
194             } else if (name.equals(P_ARCH)) {
195                 getChild().setArch(realValue);
196             }
197         } catch (CoreException e) {
198             PDEPlugin.logException(e);
199         }
200     }
201 }
202
Popular Tags