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: /**
12: * Convenience class that creates a Store directly using field names and local array data. Usage :
13: * <p/>
14: * <pre>
15: * <code>
16: * <p/>
17: * Store store = new SimpleStore(new String[]{"theme", "label"}, new Object[][]{
18: * new Object[]{"xtheme-aero.css", "Aero Glass Theme"},
19: * new Object[]{"xtheme-gray.css", "Gray Theme"},
20: * new Object[]{"xtheme-vista.css", "Vista Dark Theme"}});
21: * </code>
22: * </pre>
23: */
24: public class SimpleStore extends Store {
25:
26: /**
27: * Construct a single field SimpleStore.
28: *
29: * @param field a single field
30: * @param data store data. all fields are treated as String's
31: */
32: public SimpleStore(String field, Object[] data) {
33: Object[][] dataArr = new Object[data.length][1];
34: for (int i = 0; i < data.length; i++) {
35: Object dataVal = data[i];
36: dataArr[i][0] = dataVal;
37: }
38: MemoryProxy proxy = new MemoryProxy(dataArr);
39: ArrayReader reader = new ArrayReader(new RecordDef(
40: new FieldDef[] { new StringFieldDef(field) }));
41: setDataProxy(proxy);
42: setReader(reader);
43: }
44:
45: public SimpleStore(String[] fields, Object[][] data) {
46: this (-1, fields, data);
47: }
48:
49: /**
50: * Construct a SimpleStore.
51: *
52: * @param id name of the ID field
53: * @param fields array of field names. All Fields are treated as Strings
54: * @param data store data
55: */
56: public SimpleStore(int id, String[] fields, Object[][] data) {
57:
58: MemoryProxy proxy = new MemoryProxy(data);
59:
60: FieldDef[] fieldDefs = new FieldDef[fields.length];
61: for (int i = 0; i < fields.length; i++) {
62: String field = fields[i];
63: fieldDefs[i] = new StringFieldDef(field);
64: }
65: RecordDef recordDef = new RecordDef(fieldDefs);
66: ArrayReader reader = null;
67: if (id != -1) {
68: reader = new ArrayReader(id, recordDef);
69: } else {
70: reader = new ArrayReader(recordDef);
71: }
72:
73: setDataProxy(proxy);
74: setReader(reader);
75: }
76:
77: /**
78: * Construct a SimpleStore.
79: *
80: * @param id name of the ID field
81: * @param fieldDefs the field definitions
82: * @param data store data
83: */
84: public SimpleStore(int id, FieldDef[] fieldDefs, Object[][] data) {
85: MemoryProxy proxy = new MemoryProxy(data);
86:
87: RecordDef recordDef = new RecordDef(fieldDefs);
88: ArrayReader reader = null;
89: if (id != -1) {
90: reader = new ArrayReader(id, recordDef);
91: } else {
92: reader = new ArrayReader(recordDef);
93: }
94: setDataProxy(proxy);
95: setReader(reader);
96: }
97: }
|