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: */package org.netbeans.modules.vmd.midp.converter.wizard;
041:
042: import org.netbeans.modules.vmd.api.model.*;
043: import org.netbeans.modules.vmd.api.model.common.DocumentSupport;
044: import org.netbeans.modules.vmd.api.model.support.ArraySupport;
045: import org.netbeans.modules.vmd.midp.components.MidpDocumentSupport;
046: import org.netbeans.modules.vmd.midp.components.MidpTypes;
047: import org.netbeans.modules.vmd.midp.components.categories.DisplayablesCategoryCD;
048: import org.netbeans.modules.vmd.midp.components.displayables.*;
049: import org.netbeans.modules.vmd.midp.components.items.ChoiceSupport;
050: import org.netbeans.modules.vmd.midp.components.sources.CommandEventSourceCD;
051: import org.netbeans.modules.vmd.midp.components.sources.ListElementEventSourceCD;
052: import org.netbeans.modules.vmd.midp.components.sources.ListSelectCommandEventSourceCD;
053:
054: import java.util.ArrayList;
055: import java.util.HashMap;
056: import java.util.List;
057:
058: /**
059: * @author David Kaspar
060: */
061: public class ConverterDisplayables {
062:
063: // Created: NO, Adds: YES
064: static void convertDisplayable(
065: HashMap<String, ConverterItem> id2item, ConverterItem item,
066: DesignComponent displayable) {
067: Converter.convertClass(item, displayable);
068: DesignDocument document = displayable.getDocument();
069: MidpDocumentSupport.getCategoryComponent(document,
070: DisplayablesCategoryCD.TYPEID)
071: .addComponent(displayable);
072:
073: ConverterUtil.convertStringWithUserCode(displayable,
074: DisplayableCD.PROP_TITLE, item
075: .getPropertyValue("title")); // NOI18N
076:
077: ConverterItem tickerItem = Converter.convertConverterItem(
078: id2item, item.getPropertyValue("ticker"), document); // NOI18N
079: if (tickerItem != null) {
080: DesignComponent ticker = tickerItem.getRelatedComponent();
081: if (ticker != null)
082: displayable.writeProperty(DisplayableCD.PROP_TICKER,
083: PropertyValue.createComponentReference(ticker));
084: }
085:
086: ArrayList<String> commandsList = item
087: .getContainerPropertyValue("commands"); // NOI18N
088: if (commandsList != null)
089: for (String commandValue : commandsList) {
090: ConverterItem commandActionItem = id2item
091: .get(commandValue);
092: if (commandActionItem == null)
093: continue;
094: ConverterActions.convertCommandAction(id2item,
095: commandActionItem, document);
096: DesignComponent eventSource = commandActionItem
097: .getRelatedComponent();
098: if (eventSource != null) {
099: MidpDocumentSupport.addEventSource(displayable,
100: DisplayableCD.PROP_COMMANDS, eventSource);
101: eventSource
102: .writeProperty(
103: CommandEventSourceCD.PROP_DISPLAYABLE,
104: PropertyValue
105: .createComponentReference(displayable));
106: } else
107: Debug.warning("Unrecognized command", item,
108: commandValue); // NOI18N
109: }
110: }
111:
112: // Created: NO, Adds: NO
113: static void convertScreen(HashMap<String, ConverterItem> id2item,
114: ConverterItem item, DesignComponent screen) {
115: convertDisplayable(id2item, item, screen);
116: }
117:
118: // Created: YES, Adds: NO
119: static void convertForm(HashMap<String, ConverterItem> id2item,
120: ConverterItem item, DesignDocument document) {
121: convertFormCore(id2item, item, document
122: .createComponent(FormCD.TYPEID));
123: }
124:
125: // Created: NO, Adds: NO
126: static void convertFormCore(HashMap<String, ConverterItem> id2item,
127: ConverterItem item, DesignComponent form) {
128: convertScreen(id2item, item, form);
129:
130: ArrayList<String> itemsList = item
131: .getContainerPropertyValue("items"); // NOI18N
132: if (itemsList != null)
133: for (String itemValue : itemsList) {
134: DesignComponent itemComponent = Converter
135: .convertConverterItemComponent(id2item,
136: itemValue, form.getDocument());
137: if (itemComponent != null) {
138: form.addComponent(itemComponent);
139: ArraySupport.append(form, FormCD.PROP_ITEMS,
140: itemComponent);
141: }
142: }
143: }
144:
145: // Created: YES, Adds: NO
146: static void convertTextBox(HashMap<String, ConverterItem> id2item,
147: ConverterItem item, DesignDocument document) {
148: convertTextBoxCore(id2item, item, document
149: .createComponent(TextBoxCD.TYPEID));
150: }
151:
152: // Created: NO, Adds: NO
153: static void convertTextBoxCore(
154: HashMap<String, ConverterItem> id2item, ConverterItem item,
155: DesignComponent textbox) {
156: convertScreen(id2item, item, textbox);
157:
158: ConverterUtil.convertStringWithUserCode(textbox,
159: TextBoxCD.PROP_STRING, item.getPropertyValue("string")); // NOI18N
160: ConverterUtil.convertInteger(textbox, TextBoxCD.PROP_MAX_SIZE,
161: item.getPropertyValue("maxSize")); // NOI18N
162: ConverterUtil.convertString(textbox,
163: TextBoxCD.PROP_INITIAL_INPUT_MODE, item
164: .getPropertyValue("initialInputMode")); // NOI18N
165: ConverterUtil.convertInteger(textbox,
166: TextBoxCD.PROP_CONSTRAINTS, item
167: .getPropertyValue("constraints")); // NOI18N
168: }
169:
170: // Created: YES, Adds: NO
171: static void convertList(HashMap<String, ConverterItem> id2item,
172: ConverterItem item, DesignDocument document) {
173: ComponentProducer producer = DocumentSupport
174: .getComponentProducer(document, ListCD.TYPEID
175: .toString());
176: DesignComponent list = producer.createComponent(document)
177: .getMainComponent();
178: convertListCore(id2item, item, list);
179: }
180:
181: // Created: NO, Adds: NO
182: static void convertListCore(HashMap<String, ConverterItem> id2item,
183: ConverterItem item, DesignComponent list) {
184: convertScreen(id2item, item, list);
185:
186: ConverterItem selectCommandActionItem = id2item.get(item
187: .getPropertyValue("selectCommandAction")); // NOI18N
188: List<DesignComponent> selectCommandEventSourceComponents = DocumentSupport
189: .gatherSubComponentsOfType(list,
190: ListSelectCommandEventSourceCD.TYPEID);
191: DesignComponent selectCommandEventSource = selectCommandEventSourceComponents
192: .get(0);
193: Converter.convertObject(selectCommandActionItem,
194: selectCommandEventSource);
195: ConverterActions.convertCommandActionHandler(id2item,
196: selectCommandActionItem, selectCommandEventSource);
197:
198: if (item.isPropertyValueSet("selectCommand")) { // NOI18N
199: DesignComponent selectCommand = Converter
200: .convertConverterItemComponent(id2item, item
201: .getPropertyValue("selectCommand"), list
202: .getDocument()); // NOI18N
203: if (selectCommand != null) {
204: List<DesignComponent> commandEventSources = DocumentSupport
205: .gatherSubComponentsOfType(list,
206: CommandEventSourceCD.TYPEID);
207: boolean found = false;
208: for (DesignComponent commandEventSource : commandEventSources) {
209: DesignComponent foundCommand = commandEventSource
210: .readProperty(
211: CommandEventSourceCD.PROP_COMMAND)
212: .getComponent();
213: if (selectCommand == foundCommand) {
214: found = true;
215: list
216: .writeProperty(
217: ListCD.PROP_SELECT_COMMAND,
218: PropertyValue
219: .createComponentReference(commandEventSource));
220: break;
221: }
222: }
223: if (!found)
224: Debug.warning("selectCommand not found for", item); // NOI18N
225: } else
226: list.writeProperty(ListCD.PROP_SELECT_COMMAND,
227: PropertyValue.createNull());
228: }
229:
230: String choiceTypeValue = item.getPropertyValue("choiceType"); // NOI18N
231: if ("EXCLUSIVE".equals(choiceTypeValue)) // NOI18N
232: list.writeProperty(ListCD.PROP_LIST_TYPE, MidpTypes
233: .createIntegerValue(ChoiceSupport.VALUE_EXCLUSIVE));
234: else if ("IMPLICIT".equals(choiceTypeValue)) // NOI18N
235: list.writeProperty(ListCD.PROP_LIST_TYPE, MidpTypes
236: .createIntegerValue(ChoiceSupport.VALUE_IMPLICIT));
237: else if ("MULTIPLE".equals(choiceTypeValue)) // NOI18N
238: list.writeProperty(ListCD.PROP_LIST_TYPE, MidpTypes
239: .createIntegerValue(ChoiceSupport.VALUE_MULTIPLE));
240:
241: String fitPolicyValue = item.getPropertyValue("fitPolicy"); // NOI18N
242: if ("TEXT_WRAP_DEFAULT".equals(fitPolicyValue)) // NOI18N
243: list
244: .writeProperty(
245: ListCD.PROP_FIT_POLICY,
246: MidpTypes
247: .createIntegerValue(ChoiceSupport.VALUE_TEXT_WRAP_DEFAULT));
248: else if ("TEXT_WRAP_OFF".equals(fitPolicyValue)) // NOI18N
249: list
250: .writeProperty(
251: ListCD.PROP_FIT_POLICY,
252: MidpTypes
253: .createIntegerValue(ChoiceSupport.VALUE_TEXT_WRAP_OFF));
254: else if ("TEXT_WRAP_ON".equals(fitPolicyValue)) // NOI18N
255: list
256: .writeProperty(
257: ListCD.PROP_FIT_POLICY,
258: MidpTypes
259: .createIntegerValue(ChoiceSupport.VALUE_TEXT_WRAP_ON));
260:
261: ArrayList<String> elementsList = item
262: .getContainerPropertyValue("elements"); // NOI18N
263: if (elementsList != null)
264: for (String elementValue : elementsList) {
265: DesignComponent listElement = Converter
266: .convertConverterItemComponent(id2item,
267: elementValue, list.getDocument());
268: if (listElement == null) {
269: Debug
270: .warning("ListElement not found",
271: elementValue); // NOI18N
272: continue;
273: }
274: list.addComponent(listElement);
275: ArraySupport.append(list, ListCD.PROP_ELEMENTS,
276: listElement);
277: }
278:
279: ConverterUtil.convertBoolean(list,
280: ListCD.PROP_INDEX_BASED_SWITCH, item
281: .getPropertyValue("indexBasedSwitch")); // NOI18N
282: }
283:
284: // Created: YES, Adds: NO
285: static void convertAlert(HashMap<String, ConverterItem> id2item,
286: ConverterItem item, DesignDocument document) {
287: convertAlertCore(id2item, item, document
288: .createComponent(AlertCD.TYPEID));
289: }
290:
291: // Created: NO, Adds: NO
292: static void convertAlertCore(
293: HashMap<String, ConverterItem> id2item, ConverterItem item,
294: DesignComponent alert) {
295: convertScreen(id2item, item, alert);
296:
297: ConverterUtil.convertStringWithUserCode(alert,
298: AlertCD.PROP_STRING, item.getPropertyValue("string")); // NOI18N
299: ConverterUtil.convertInteger(alert, AlertCD.PROP_TIMEOUT, item
300: .getPropertyValue("timeout")); // NOI18N
301:
302: DesignComponent image = Converter
303: .convertConverterItemComponent(id2item, item
304: .getPropertyValue("image"), alert.getDocument()); // NOI18N
305: if (image != null)
306: alert.writeProperty(ListElementEventSourceCD.PROP_IMAGE,
307: PropertyValue.createComponentReference(image));
308:
309: String type = item.getPropertyValue("type"); // NOI18N
310: if ("ALERT".equals(type)) // NOI18N
311: alert.writeProperty(AlertCD.PROP_ALERT_TYPE, MidpTypes
312: .createAlertTypeValue(MidpTypes.AlertType.ALARM));
313: else if ("CONFIRMATION".equals(type)) // NOI18N
314: alert
315: .writeProperty(
316: AlertCD.PROP_ALERT_TYPE,
317: MidpTypes
318: .createAlertTypeValue(MidpTypes.AlertType.CONFIRMATION));
319: else if ("ERROR".equals(type)) // NOI18N
320: alert.writeProperty(AlertCD.PROP_ALERT_TYPE, MidpTypes
321: .createAlertTypeValue(MidpTypes.AlertType.ERROR));
322: else if ("INFO".equals(type)) // NOI18N
323: alert.writeProperty(AlertCD.PROP_ALERT_TYPE, MidpTypes
324: .createAlertTypeValue(MidpTypes.AlertType.INFO));
325: else if ("WARNING".equals(type)) // NOI18N
326: alert.writeProperty(AlertCD.PROP_ALERT_TYPE, MidpTypes
327: .createAlertTypeValue(MidpTypes.AlertType.WARNING));
328:
329: DesignComponent indicator = Converter
330: .convertConverterItemComponent(id2item, item
331: .getPropertyValue("indicator"), alert
332: .getDocument()); // NOI18N
333: if (indicator != null) {
334: alert.addComponent(indicator);
335: alert.writeProperty(AlertCD.PROP_INDICATOR, PropertyValue
336: .createComponentReference(indicator));
337: }
338: }
339:
340: // Created: NO, Adds: NO
341: static void convertCanvas(HashMap<String, ConverterItem> id2item,
342: ConverterItem item, DesignComponent canvas) {
343: convertDisplayable(id2item, item, canvas);
344:
345: ConverterUtil.convertBoolean(canvas,
346: CanvasCD.PROP_IS_FULL_SCREEN, item
347: .getPropertyValue("fullScreen")); // NOI18N
348: }
349:
350: }
|