01: /*
02: * GWT-Ext Widget Library
03: * Copyright(c) 2007-2008, GWT-Ext.
04: * licensing@gwt-ext.com
05: *
06: * http://www.gwt-ext.com/license
07: */
08:
09: package com.gwtext.client.data;
10:
11: import com.google.gwt.core.client.JavaScriptObject;
12: import com.gwtext.client.util.JavaScriptObjectHelper;
13:
14: /**
15: * Field that represents String data.
16: */
17: public class StringFieldDef extends FieldDef {
18:
19: /**
20: * Construct a new StringFieldDef.
21: *
22: * @param name the name of field
23: */
24: public StringFieldDef(String name) {
25: this (name, null, null);
26: }
27:
28: /**
29: * Construct a new StringFieldDef.
30: *
31: * @param name the name of field
32: * @param mapping the field mapping. Depending on the Reader used, mapping could be the array index position or an XPath expression when reading from XML
33: */
34: public StringFieldDef(String name, String mapping) {
35: this (name, mapping, null);
36: }
37:
38: /**
39: * Construct a new StringFieldDef.
40: *
41: * @param name the name of field
42: * @param mapping the field mapping. Depending on the Reader used, mapping could be the array index position or an XPath expression when reading from XML
43: */
44: public StringFieldDef(String name, int mapping) {
45: this (name, mapping, null);
46: }
47:
48: /**
49: * Construct a new StringFieldDef.
50: *
51: * @param name the field name
52: * @param mapping the field mapping. Depending on the Reader used, mapping could be the array index position or an XPath expression when readinf from XML
53: * @param converter format the incoming data before processing it
54: */
55: public StringFieldDef(String name, String mapping,
56: Converter converter) {
57: jsObj = create(name, mapping, converter);
58: }
59:
60: /**
61: * Construct a new StringFieldDef.
62: *
63: * @param name the field name
64: * @param mapping the field mapping. Depending on the Reader used, mapping could be the array index position or an XPath expression when readinf from XML
65: * @param converter format the incoming data before processing it
66: */
67: public StringFieldDef(String name, int mapping, Converter converter) {
68: this (name, String.valueOf(mapping), converter);
69: }
70:
71: private static JavaScriptObject create(String name, String mapping,
72: Converter converter) {
73: JavaScriptObject jsObj = JavaScriptObjectHelper.createObject();
74: JavaScriptObjectHelper.setAttribute(jsObj, "name", name);
75: JavaScriptObjectHelper.setAttribute(jsObj, "type", "string");
76: if (mapping != null)
77: JavaScriptObjectHelper.setAttribute(jsObj, "mapping",
78: mapping);
79: if (converter != null)
80: setConverter(jsObj, converter);
81: return jsObj;
82: }
83: }
|