001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.vmd.midp.serialization;
042:
043: import org.netbeans.modules.vmd.api.model.ComponentDescriptor;
044: import org.netbeans.modules.vmd.api.model.Presenter;
045: import org.netbeans.modules.vmd.api.model.PresenterDeserializer;
046: import org.netbeans.modules.vmd.api.properties.DefaultPropertiesPresenter;
047: import org.netbeans.modules.vmd.midp.components.MidpDocumentSupport;
048: import org.netbeans.modules.vmd.midp.propertyeditors.*;
049: import org.w3c.dom.Node;
050:
051: import java.util.Arrays;
052: import java.util.List;
053: import org.openide.util.NbBundle;
054:
055: /**
056: * @author David Kaspar
057: */
058: public class MidpPropertyPresenterDeserializer extends
059: PresenterDeserializer {
060:
061: public static final String PROPERTY_NODE = "MidpProperty"; // NOI18N
062: public static final String DISPLAY_NAME_ATTR = "displayName"; // NOI18N
063: public static final String EDITOR_ATTR = "editor"; // NOI18N
064: public static final String PROPERTY_NAME_ATTR = "propertyName"; // NOI18N
065:
066: public static final String EDITOR_BOOLEAN = "boolean"; // NOI18N
067: public static final String EDITOR_CHAR = "char"; // NOI18N
068: public static final String EDITOR_BYTE = "byte"; // NOI18N
069: public static final String EDITOR_SHORT = "short"; // NOI18N
070: public static final String EDITOR_INT = "int"; // NOI18N
071: public static final String EDITOR_LONG = "long"; // NOI18N
072: public static final String EDITOR_FLOAT = "float"; // NOI18N
073: public static final String EDITOR_DOUBLE = "double"; // NOI18N
074: public static final String EDITOR_STRING = "java.lang.String"; // NOI18N
075: // TODO - public static final String EDITOR_IMAGE = "image"; // NOI18N
076: public static final String EDITOR_JAVA_CODE = "#javaCode"; // NOI18N
077:
078: public MidpPropertyPresenterDeserializer() {
079: super (MidpDocumentSupport.PROJECT_TYPE_MIDP);
080: }
081:
082: public PresenterFactory deserialize(Node node) {
083: if (!PROPERTY_NODE.equalsIgnoreCase(node.getNodeName()))
084: return null;
085: String displayName = XMLUtils.getAttributeValue(node,
086: DISPLAY_NAME_ATTR);
087: String editor = XMLUtils.getAttributeValue(node, EDITOR_ATTR);
088: String propertyName = XMLUtils.getAttributeValue(node,
089: PROPERTY_NAME_ATTR);
090: return new MidpPropertyPresenterFactory(displayName, editor,
091: propertyName);
092: }
093:
094: private static class MidpPropertyPresenterFactory extends
095: PresenterFactory {
096:
097: private String displayName;
098: private String editor;
099: private String propertyName;
100:
101: public MidpPropertyPresenterFactory(String displayName,
102: String editor, String propertyName) {
103: this .displayName = displayName;
104: this .editor = editor;
105: this .propertyName = propertyName;
106: }
107:
108: public List<Presenter> createPresenters(
109: ComponentDescriptor descriptor) {
110: DefaultPropertiesPresenter presenter = new DefaultPropertiesPresenter()
111: .addPropertiesCategory(MidpPropertiesCategories.CATEGORY_PROPERTIES);
112: if (EDITOR_BOOLEAN.equals(editor))
113: presenter.addProperty(displayName,
114: PropertyEditorBooleanUC.createInstance(),
115: propertyName);
116: else if (EDITOR_INT.equals(editor))
117: presenter
118: .addProperty(
119: displayName,
120: PropertyEditorNumber
121: .createIntegerInstance(
122: false,
123: NbBundle
124: .getMessage(
125: MidpPropertyPresenterDeserializer.class,
126: "LBL_INTEGER_STR")),
127: propertyName); // NOI18N
128: else if (EDITOR_FLOAT.equals(editor))
129: presenter
130: .addProperty(
131: displayName,
132: PropertyEditorNumber
133: .createFloatInstance(NbBundle
134: .getMessage(
135: MidpPropertyPresenterDeserializer.class,
136: "LBL_FLOAT_STR")),
137: propertyName); // NOI18N
138: else if (EDITOR_STRING.equals(editor))
139: presenter
140: .addProperty(
141: displayName,
142: PropertyEditorString
143: .createInstance(NbBundle
144: .getMessage(
145: MidpPropertyPresenterDeserializer.class,
146: "LBL_STRING")),
147: propertyName); // NOI18N
148: else if (EDITOR_JAVA_CODE.equals(editor))
149: presenter.addProperty(displayName,
150: PropertyEditorJavaString
151: .createInstance(descriptor
152: .getTypeDescriptor()
153: .getThisType()), propertyName);
154: else if (EDITOR_CHAR.equals(editor))
155: presenter
156: .addProperty(
157: displayName,
158: PropertyEditorNumber
159: .createCharInstance(
160: false,
161: NbBundle
162: .getMessage(
163: MidpPropertyPresenterDeserializer.class,
164: "LBL_CHAR_STR")),
165: propertyName); // NOI18N
166: else if (EDITOR_BYTE.equals(editor))
167: presenter
168: .addProperty(
169: displayName,
170: PropertyEditorNumber
171: .createByteInstance(
172: false,
173: NbBundle
174: .getMessage(
175: MidpPropertyPresenterDeserializer.class,
176: "LBL_BYTE_STR")),
177: propertyName); // NOI18N
178: else if (EDITOR_SHORT.equals(editor))
179: presenter
180: .addProperty(
181: displayName,
182: PropertyEditorNumber
183: .createShortInstance(
184: false,
185: NbBundle
186: .getMessage(
187: MidpPropertyPresenterDeserializer.class,
188: "LBL_SHORT_STR")),
189: propertyName); // NOI18N
190: else if (EDITOR_LONG.equals(editor))
191: presenter
192: .addProperty(
193: displayName,
194: PropertyEditorNumber
195: .createLongInstance(
196: false,
197: NbBundle
198: .getMessage(
199: MidpPropertyPresenterDeserializer.class,
200: "LBL_LONG_STR")),
201: propertyName); // NOI18N
202: else if (EDITOR_DOUBLE.equals(editor))
203: presenter
204: .addProperty(
205: displayName,
206: PropertyEditorNumber
207: .createDoubleInstance(NbBundle
208: .getMessage(
209: MidpPropertyPresenterDeserializer.class,
210: "LBL_DOUBLE_STR")),
211: propertyName); // NOI18N
212: else
213: return null;
214: return Arrays.<Presenter> asList(presenter);
215: }
216:
217: }
218:
219: }
|