Source Code Cross Referenced for Store.java in  » Ajax » gwtext-2.01 » com » gwtext » client » data » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Ajax » gwtext 2.01 » com.gwtext.client.data 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


0001:        /*
0002:         * GWT-Ext Widget Library
0003:         * Copyright(c) 2007-2008, GWT-Ext.
0004:         * licensing@gwt-ext.com
0005:         * 
0006:         * http://www.gwt-ext.com/license
0007:         */
0008:
0009:        package com.gwtext.client.data;
0010:
0011:        import com.google.gwt.core.client.JavaScriptObject;
0012:        import com.gwtext.client.core.JsObject;
0013:        import com.gwtext.client.core.RegExp;
0014:        import com.gwtext.client.core.SortDir;
0015:        import com.gwtext.client.core.UrlParam;
0016:        import com.gwtext.client.data.event.StoreListener;
0017:        import com.gwtext.client.util.JavaScriptObjectHelper;
0018:
0019:        //todo baseParams, sortInfo in constructor
0020:
0021:        //todo fireRowsSorted missing?
0022:
0023:        /**
0024:         * The Store class encapsulates a client side cache of {@link Record} objects which provide input data for widgets such
0025:         * as the {@link com.gwtext.client.widgets.grid.GridPanel}, or the {@link com.gwtext.client.widgets.form.ComboBox}.
0026:         * <p/>
0027:         * A Store object uses an implementation of {@link DataProxy} to access a data object unless you call loadData() directly
0028:         * and pass in your data. The Store object has no knowledge of the format of the data returned by the Proxy.
0029:         * <p/>
0030:         * A Store object uses its configured implementation of {@link Reader} to {@link Record} instances from the data object.
0031:         * These records are cached and made available through accessor functions. Usage :
0032:         * <p/>
0033:         * <pre>
0034:         * <code>
0035:         * <p/>
0036:         * Object[][] states = new Object[][]{
0037:         *               new Object[]{"AL", "Alabama"},
0038:         *               new Object[]{"AK", "Alaska"},
0039:         *               new Object[]{"AZ", "Arizona"},
0040:         *               new Object[]{"AR", "Arkansas"},
0041:         *               new Object[]{"CA", "California"}};
0042:         * <p/>
0043:         * Reader reader = new ArrayReader(new RecordDef(
0044:         *                new FieldDef[]{
0045:         *                       new StringFieldDef("abbr"),
0046:         *                       new StringFieldDef("state")
0047:         *               }));
0048:         * <p/>
0049:         * Store store = new Store(proxy, reader);
0050:         * </code>
0051:         * </pre>
0052:         *
0053:         * @see com.gwtext.client.data.XmlReader
0054:         * @see com.gwtext.client.data.JsonReader
0055:         * @see com.gwtext.client.data.HttpProxy
0056:         * @see com.gwtext.client.data.MemoryProxy
0057:         */
0058:        public class Store extends JsObject {
0059:
0060:            protected JavaScriptObject configJS = JavaScriptObjectHelper
0061:                    .createObject();
0062:
0063:            protected Store() {
0064:            }
0065:
0066:            public Store(JavaScriptObject jsObj) {
0067:                super (jsObj);
0068:            }
0069:
0070:            private static Store instance(JavaScriptObject jsObj) {
0071:                return new Store(jsObj);
0072:            }
0073:
0074:            //http://extjs.com/forum/showthread.php?t=3564&highlight=memoryproxy
0075:            /**
0076:             * Create a Store using the specified {@link RecordDef}. Data can be added to the Store using
0077:             * {@link #add(Record)}
0078:             *
0079:             * @param recordDef the record def
0080:             */
0081:            public Store(RecordDef recordDef) {
0082:                setRecordDef(recordDef);
0083:            }
0084:
0085:            /**
0086:             * Create a Store using the specified {@link Reader}.
0087:             *
0088:             * @param reader the reader
0089:             */
0090:            public Store(Reader reader) {
0091:                setReader(reader);
0092:            }
0093:
0094:            /**
0095:             * Create a Store using the specified {@link com.gwtext.client.data.DataProxy} and {@link Reader}.
0096:             *
0097:             * @param dataProxy the data proxy
0098:             * @param reader    the reader
0099:             */
0100:            public Store(DataProxy dataProxy, Reader reader) {
0101:                setDataProxy(dataProxy);
0102:                setReader(reader);
0103:            }
0104:
0105:            /**
0106:             * Create a Store using the specified {@link com.gwtext.client.data.DataProxy} and {@link Reader}.
0107:             *
0108:             * @param dataProxy  the data proxy
0109:             * @param reader     the reader
0110:             * @param remoteSort true to enable remote sort of the data
0111:             */
0112:            public Store(DataProxy dataProxy, Reader reader, boolean remoteSort) {
0113:                setDataProxy(dataProxy);
0114:                setReader(reader);
0115:                setRemoteSort(remoteSort);
0116:            }
0117:
0118:            /**
0119:             * Create a Store using the specified configuration.
0120:             *
0121:             * @param dataProxy        the data proxy
0122:             * @param reader           the reader
0123:             * @param baseParams       base params which are to be sent as parameters on any HTTP request. Used only for Http based proxies.
0124:             * @param initialSortState the initial sort field name and direction
0125:             * @param remoteSort       true to enable remote sort
0126:             */
0127:            public Store(DataProxy dataProxy, Reader reader,
0128:                    UrlParam[] baseParams, SortState initialSortState,
0129:                    boolean remoteSort) {
0130:                setDataProxy(dataProxy);
0131:                setReader(reader);
0132:                setBaseParams(baseParams);
0133:                setInitialSortState(initialSortState);
0134:                setRemoteSort(remoteSort);
0135:            }
0136:
0137:            native JavaScriptObject create(JavaScriptObject config) /*-{
0138:                   return new $wnd.Ext.data.Store(config);
0139:               }-*/;
0140:
0141:            public JavaScriptObject getJsObj() {
0142:                if (jsObj == null) {
0143:                    jsObj = create(configJS);
0144:                }
0145:                return jsObj;
0146:            }
0147:
0148:            /**
0149:             * Base params which are to be sent as parameters on any HTTP request. Used only for Http based proxies.
0150:             *
0151:             * @param baseParams the base params
0152:             */
0153:            private native void setBaseParamsCreated(UrlParam[] baseParams) /*-{
0154:                   var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0155:                   var baseParamsJS = @com.gwtext.client.core.NameValuePair::getJsObj([Lcom/gwtext/client/core/NameValuePair;)(baseParams);
0156:                   store.baseParams = baseParamsJS;
0157:               }-*/;
0158:
0159:            /**
0160:             * Return the base params.
0161:             *
0162:             * @return the base params                      
0163:             */
0164:            public UrlParam[] getBaseParams() {
0165:                JavaScriptObject baseParamsNative = getBaseParams(getJsObj());
0166:
0167:                JavaScriptObject[] urlParamsJ = JavaScriptObjectHelper
0168:                        .toArray(baseParamsNative);
0169:                UrlParam[] baseParams = new UrlParam[urlParamsJ.length];
0170:                for (int i = 0; i < urlParamsJ.length; i++) {
0171:                    UrlParam urlParam = new UrlParam(urlParamsJ[i]);
0172:                    baseParams[i] = urlParam;
0173:                }
0174:                return baseParams;
0175:            }
0176:
0177:            private native JavaScriptObject getBaseParams(JavaScriptObject store) /*-{
0178:                   var params = new Array();
0179:                   var i = 0;
0180:                   var o = store.baseParams;
0181:                   for(var key in o){
0182:                       var ov = o[key];
0183:                       var param = @com.gwtext.client.core.UrlParam::instance(Ljava/lang/String;Ljava/lang/String;)(key, ov);
0184:                       params[i] = param.@com.gwtext.client.core.JsObject::getJsObj()();
0185:                       i++;
0186:                   }
0187:                   return params;
0188:               }-*/;
0189:
0190:            /**
0191:             * Add a Record to the Store and fires the add event.
0192:             *
0193:             * @param record the Record to add
0194:             */
0195:            public native void add(Record record) /*-{
0196:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0197:            	var recordJ = record.@com.gwtext.client.core.JsObject::getJsObj()();
0198:            	return store.add(recordJ);
0199:               }-*/;
0200:
0201:            /**
0202:             * Add Records to the Store and fires the add event.
0203:             *
0204:             * @param records the Records to add
0205:             */
0206:            public void add(Record[] records) {
0207:                JavaScriptObject[] recordsJS = new JavaScriptObject[records.length];
0208:                for (int i = 0; i < records.length; i++) {
0209:                    Record record = records[i];
0210:                    recordsJS[i] = record.getJsObj();
0211:                }
0212:                JavaScriptObject nativeRecordsArray = JavaScriptObjectHelper
0213:                        .convertToJavaScriptArray(recordsJS);
0214:                add(getJsObj(), nativeRecordsArray);
0215:            }
0216:
0217:            private native void add(JavaScriptObject store,
0218:                    JavaScriptObject nativeRecordsArray)/*-{
0219:            		store.add(nativeRecordsArray);
0220:                }-*/;
0221:
0222:            /**
0223:             * (Local sort only) Inserts the passed the record in the Store at the index where it should go based on the
0224:             * current sort information.
0225:             *
0226:             * @param record the record to add
0227:             */
0228:            public native void addSorted(Record record) /*-{
0229:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0230:            	var recordJ = record.@com.gwtext.client.core.JsObject::getJsObj()();
0231:            	return store.addSorted(recordJ);
0232:               }-*/;
0233:
0234:            /**
0235:             * Revert to a view of the Record cache / snapshot with no filtering applied.  A snapshot of the data is taken when {@link #filter(String, String)} is called.
0236:             * Records added to the Store after filter is caleld will be lost if clearFilter is subsequently called.
0237:             */
0238:            public native void clearFilter() /*-{
0239:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0240:            	return store.clearFilter();
0241:               }-*/;
0242:
0243:            /**
0244:             * Revert to a view of the Record cache with no filtering applied.
0245:             *
0246:             * @param suppressEvent if true the filter is cleared silently without notifying listeners
0247:             */
0248:            public native void clearFilter(boolean suppressEvent) /*-{
0249:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0250:            	return store.clearFilter(suppressEvent);
0251:               }-*/;
0252:
0253:            /**
0254:             * Commit all Records with outstanding changes. To handle updates for changes, subscribe to the Store's "update" event,
0255:             * and perform updating when the third parameter {@link Record#COMMIT}.
0256:             */
0257:            public native void commitChanges() /*-{
0258:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0259:            	return store.commitChanges();
0260:               }-*/;
0261:
0262:            //todo add collect() method
0263:
0264:            /**
0265:             * Calls the specified function for each of the Records in the cache.
0266:             *
0267:             * @param cb the Store traversal callback
0268:             */
0269:            public native void each(StoreTraversalCallback cb)/*-{
0270:                    var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0271:                    store.each(function(r) {
0272:                        var rj = @com.gwtext.client.data.Record::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(r);
0273:                        return cb.@com.gwtext.client.data.StoreTraversalCallback::execute(Lcom/gwtext/client/data/Record;)(rj);
0274:                    });
0275:                }-*/;
0276:
0277:            /**
0278:             * Filter the records by a specified property using a Regular expression.
0279:             *
0280:             * @param field  the filed to filter on
0281:             * @param regexp the regular expression to test field value against
0282:             */
0283:            public native void filter(String field, RegExp regexp) /*-{
0284:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0285:                   var re = regexp.@com.gwtext.client.core.JsObject::getJsObj()();
0286:                   store.filter(field, re);
0287:            }-*/;
0288:
0289:            /**
0290:             * Filter the records by a specified property .
0291:             *
0292:             * @param field the filed to filter on
0293:             * @param value a string that the field should start with
0294:             */
0295:            public native void filter(String field, String value) /*-{
0296:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0297:            	store.filter(field, value);
0298:            }-*/;
0299:
0300:            /**
0301:             * Filter the records by a specified property .
0302:             *
0303:             * @param field    the filed to filter on
0304:             * @param value    a string that the field should start with
0305:             * @param anyMatch true to match any part not just the beginning
0306:             */
0307:            public native void filter(String field, String value,
0308:                    boolean anyMatch) /*-{
0309:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0310:            	store.filter(field, value, anyMatch);
0311:            }-*/;
0312:
0313:            /**
0314:             * Filter by a function. The specified function will be called with each record in this data source. If the function returns
0315:             * true the record is included, otherwise it is filtered.
0316:             *
0317:             * @param cb the filter function
0318:             */
0319:            public native void filterBy(StoreTraversalCallback cb)/*-{
0320:                    var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0321:                    store.filterBy(function(r) {
0322:                        var rj = @com.gwtext.client.data.Record::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(r);
0323:                        return cb.@com.gwtext.client.data.StoreTraversalCallback::execute(Lcom/gwtext/client/data/Record;)(rj);
0324:                    });
0325:                }-*/;
0326:
0327:            /**
0328:             * Returns the record at the specified index. This method is functionally equivalent to {@link #getAt(int)}.
0329:             *
0330:             * @param index the Store index
0331:             * @return the Record at index
0332:             */
0333:            public Record getRecordAt(int index) {
0334:                return getAt(index);
0335:            }
0336:
0337:            /**
0338:             * Returns the record at the specified index.
0339:             *
0340:             * @param index the Store index
0341:             * @return the Record at index
0342:             */
0343:            public native Record getAt(int index) /*-{
0344:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0345:            	var rec = store.getAt(index);
0346:            	if(rec == null || rec === undefined) return null;
0347:            	return @com.gwtext.client.data.Record::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(rec);
0348:               }-*/;
0349:
0350:            /**
0351:             * Get the Record with the specified id.
0352:             *
0353:             * @param id the Record ID
0354:             * @return the matched Record or null if no match found
0355:             */
0356:            public native Record getById(String id) /*-{
0357:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0358:            	var rec = store.getById(id);
0359:            	if(rec == null || rec === undefined) return null;
0360:            	return @com.gwtext.client.data.Record::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(rec);
0361:            }-*/;
0362:
0363:            /**
0364:             * Gets the number of cached records. If using paging, this may not be the total size of the dataset. If the data
0365:             * object used by the Reader contains the dataset size, then the getTotalCount() function returns the data set size
0366:             *
0367:             * @return the Record count
0368:             */
0369:            public native int getCount() /*-{
0370:                   var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0371:                   return store.getCount();
0372:               }-*/;
0373:
0374:            /**
0375:             * Gets all records modified since the last commit. Modified records are persisted across load operations (e.g., during paging).
0376:             *
0377:             * @return the modified Records. Returns an empty array if no records were modified
0378:             */
0379:            public Record[] getModifiedRecords() {
0380:                JavaScriptObject nativeArray = getModifiedRecords(getJsObj());
0381:                return convertFromNativeRecordsArray(nativeArray);
0382:            }
0383:
0384:            private static Record[] convertFromNativeRecordsArray(
0385:                    JavaScriptObject nativeArray) {
0386:                JavaScriptObject[] recordsj = JavaScriptObjectHelper
0387:                        .toArray(nativeArray);
0388:                Record[] records = new Record[recordsj.length];
0389:                for (int i = 0; i < recordsj.length; i++) {
0390:                    JavaScriptObject record = recordsj[i];
0391:                    records[i] = new Record(record);
0392:                }
0393:                return records;
0394:            }
0395:
0396:            private native JavaScriptObject getModifiedRecords(
0397:                    JavaScriptObject store)/*-{
0398:            		return store.getModifiedRecords();
0399:            	}-*/;
0400:
0401:            /**
0402:             * Returns a range of Records between specified indices.
0403:             *
0404:             * @param startIndex the starting index (0 based)
0405:             * @param endIndex   the ending index
0406:             * @return array of Records
0407:             */
0408:            public Record[] getRange(int startIndex, int endIndex) {
0409:                JavaScriptObject nativeArray = getRange(getJsObj(), startIndex,
0410:                        endIndex);
0411:                return convertFromNativeRecordsArray(nativeArray);
0412:            }
0413:
0414:            private native JavaScriptObject getRange(JavaScriptObject store,
0415:                    int startIndex, int endIndex)/*-{
0416:            		return store.getRange(startIndex, endIndex);
0417:            	}-*/;
0418:
0419:            /**
0420:             * Returns the sort state of the Store.
0421:             *
0422:             * @return the Store sort state
0423:             */
0424:            public SortState getSortState() {
0425:                JavaScriptObject sortState = getSortState(getJsObj());
0426:                return new SortState(JavaScriptObjectHelper.getAttribute(
0427:                        sortState, "field"), SortDir
0428:                        .getValue(JavaScriptObjectHelper.getAttribute(
0429:                                sortState, "direction")));
0430:            }
0431:
0432:            private native JavaScriptObject getSortState(JavaScriptObject store)/*-{
0433:            		return store.getSortState();
0434:            	}-*/;
0435:
0436:            /**
0437:             * Gets the total number of records in the dataset as returned by the server. If using paging, for this to
0438:             * be accurate, the data object used by the Reader must contain the dataset size.
0439:             *
0440:             * @return total record count
0441:             */
0442:            public native int getTotalCount() /*-{
0443:                   var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0444:                   return store.getTotalCount();
0445:               }-*/;
0446:
0447:            /**
0448:             * Get the index within the cache of the passed Record.
0449:             *
0450:             * @param record the Record to find
0451:             * @return the index of the passed Record. Returns -1 if not found
0452:             */
0453:            public native int indexOf(Record record)/*-{
0454:                    var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0455:                    var rec = record.@com.gwtext.client.core.JsObject::getJsObj()();
0456:                    return store.indexOf(rec);
0457:                }-*/;
0458:
0459:            /**
0460:             * Get the index within the cache of the Record with the passed id.
0461:             *
0462:             * @param id the Record ID
0463:             * @return the index of the Record. Returns -1 if not found
0464:             */
0465:            public native int indexOfId(String id)/*-{
0466:                    var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0467:                    return store.indexOfId(id);
0468:                }-*/;
0469:
0470:            /**
0471:             * Inserts Records to the Store at the given index and fires the add event.
0472:             *
0473:             * @param index  the start index at which to insert the passed Record
0474:             * @param record the Record to insert
0475:             */
0476:            public native void insert(int index, Record record) /*-{
0477:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0478:            	var recordJ = record.@com.gwtext.client.core.JsObject::getJsObj()();
0479:            	return store.insert(index, recordJ);
0480:               }-*/;
0481:
0482:            /**
0483:             * Inserts Records to the Store at the given index and fires the add event.
0484:             *
0485:             * @param index   the start index at which to insert the passed Records
0486:             * @param records the Records to insert
0487:             */
0488:            public void insert(int index, Record[] records) {
0489:                JavaScriptObject[] recordsJS = new JavaScriptObject[records.length];
0490:                for (int i = 0; i < records.length; i++) {
0491:                    Record record = records[i];
0492:                    recordsJS[i] = record.getJsObj();
0493:                }
0494:                JavaScriptObject nativeRecordsArray = JavaScriptObjectHelper
0495:                        .convertToJavaScriptArray(recordsJS);
0496:                insert(index, getJsObj(), nativeRecordsArray);
0497:            }
0498:
0499:            private native void insert(int index, JavaScriptObject store,
0500:                    JavaScriptObject nativeRecordsArray)/*-{
0501:            		store.insert(index, nativeRecordsArray);
0502:                }-*/;
0503:
0504:            /**
0505:             * Loads the Record cache from the configured Proxy using the configured Reader.
0506:             * <br/><br/>
0507:             * If using remote paging, then the first load call must specify the start and limit properties
0508:             * to establish the initial position within the dataset by calling {@link #load(int, int)} , and the number of Records
0509:             * to cache on each read from the Proxy. It is important to note that for remote data sources, loading is asynchronous,
0510:             * and this call will return before the new data has been loaded. Perform any post-processing in a "load" event handler.
0511:             */
0512:            public native void load() /*-{
0513:                   var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0514:                   store.load();
0515:            }-*/;
0516:
0517:            /**
0518:             * Loads the Record cache from the configured Proxy using the configured Reader.
0519:             * <br/><br/>
0520:             * If using remote paging, then the first load call must specify the start and limit properties
0521:             * to establish the initial position within the dataset by calling {@link #load(int, int)} , and the number of Records
0522:             * to cache on each read from the Proxy. It is important to note that for remote data sources, loading is asynchronous,
0523:             * and this call will return before the new data has been loaded. Perform any post-processing in a "load" event handler.
0524:             *
0525:             * @param start start position
0526:             * @param limit limit
0527:             */
0528:            public native void load(int start, int limit) /*-{
0529:                   var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0530:                   store.load({params:{start:start, limit:limit}});
0531:            }-*/;
0532:
0533:            /**
0534:             * Loads the Record cache from the configured Proxy using the configured Reader.
0535:             * <br/><br/>
0536:             * If using remote paging, then the first load call must specify the start and limit properties
0537:             * to establish the initial position within the dataset by calling {@link #load(int, int)} , and the number of Records
0538:             * to cache on each read from the Proxy. It is important to note that for remote data sources, loading is asynchronous,
0539:             * and this call will return before the new data has been loaded. Perform any post-processing in a "load" event handler.
0540:             *
0541:             * @param params the load params
0542:             */
0543:            public void load(UrlParam[] params) {
0544:                load(params, false);
0545:
0546:            }
0547:
0548:            /**
0549:             * Loads the Record cache from the configured Proxy using the configured Reader.
0550:             * <br/><br/>
0551:             * If using remote paging, then the first load call must specify the start and limit properties
0552:             * to establish the initial position within the dataset by calling {@link #load(int, int)} , and the number of Records
0553:             * to cache on each read from the Proxy. It is important to note that for remote data sources, loading is asynchronous,
0554:             * and this call will return before the new data has been loaded. Perform any post-processing in a "load" event handler.
0555:             *
0556:             * @param params the load params
0557:             * @param add true to append loaded records rather than replace the current cache
0558:             */
0559:            public void load(UrlParam[] params, boolean add) {
0560:                JavaScriptObject configJS = JavaScriptObjectHelper
0561:                        .createObject();
0562:                if (params != null && params.length > 0) {
0563:                    JavaScriptObjectHelper.setAttribute(configJS, "params",
0564:                            UrlParam.getJsObj(params));
0565:                }
0566:                JavaScriptObjectHelper.setAttribute(configJS, "add", add);
0567:                load(configJS);
0568:            }
0569:
0570:            private native void load(JavaScriptObject configJS) /*-{
0571:                   var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0572:                   store.load(configJS);
0573:               }-*/;
0574:
0575:            /**
0576:             * Reloads the Record cache from the configured Proxy using the configured Reader and the options
0577:             * from the last load operation performed.
0578:             */
0579:            public native void reload() /*-{
0580:                   var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0581:                   store.reload();
0582:            }-*/;
0583:
0584:            /**
0585:             * Load data from a local Json String
0586:             *
0587:             * @param jsonString the Json String
0588:             * @param append     true to append to the Store
0589:             */
0590:            public native void loadJsonData(String jsonString, boolean append) /*-{
0591:                   var json = $wnd.Ext.util.JSON.decode(jsonString);
0592:                   var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0593:                   store.loadData(json, append);
0594:               }-*/;
0595:
0596:            /**
0597:             * Load data from XML returned from a URL.
0598:             *
0599:             * @param url    the url that returns the XML data
0600:             * @param append true to append records
0601:             */
0602:            public native void loadXmlDataFromUrl(String url, boolean append) /*-{
0603:                   var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0604:                   $wnd.Ext.Ajax.request( {method:"GET", url: url,
0605:                       callback: function(connection, options, response) {
0606:                           store.loadData(response.responseXML, append);
0607:                       } } );
0608:               }-*/;
0609:
0610:            /**
0611:             * Load data from a local XML String.
0612:             *
0613:             * @param xmlString the XML data
0614:             * @param append    true to append records
0615:             */
0616:            public native void loadXmlData(String xmlString, boolean append) /*-{
0617:                   var doc = function() {
0618:                       var objdoc;
0619:
0620:                       if (window.ActiveXObject) {
0621:                           objdoc = new ActiveXObject ("Microsoft.XMLDOM");
0622:                           objdoc.async =  "false";
0623:                           objdoc.loadXML(xmlString);
0624:                       }
0625:                       else {
0626:                           objdoc = new DOMParser().parseFromString(xmlString, "text/xml");
0627:                       }
0628:                       return objdoc;
0629:                   }();
0630:                   var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0631:                   store.loadData(doc, append);
0632:               }-*/;
0633:
0634:            /**
0635:             * Sets the Store's DataProxy.
0636:             *
0637:             * @param proxy the data proxy
0638:             */
0639:            private native void setDataProxyCreated(DataProxy proxy) /*-{
0640:                   var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0641:                   var proxyJS = proxy.@com.gwtext.client.core.JsObject::getJsObj()();
0642:                   store.proxy = proxyJS;
0643:               }-*/;
0644:
0645:            /**
0646:             * Reloads the Record cache from the configured Proxy using the configured Reader and the options
0647:             * from the last load operation performed.
0648:             *
0649:             * @param params the request params
0650:             */
0651:            public void reload(UrlParam[] params) {
0652:                reload(params, false);
0653:
0654:            }
0655:
0656:            /**
0657:             * Reloads the Record cache from the configured Proxy using the configured Reader and the options
0658:             * from the last load operation performed.
0659:             *
0660:             * @param params the request params
0661:             * @param add true to append loaded records rather than replace the current cache
0662:             */
0663:            public void reload(UrlParam[] params, boolean add) {
0664:                JavaScriptObject configJS = JavaScriptObjectHelper
0665:                        .createObject();
0666:                if (params != null && params.length > 0) {
0667:                    JavaScriptObjectHelper.setAttribute(configJS, "params",
0668:                            UrlParam.getJsObj(params));
0669:                }
0670:                JavaScriptObjectHelper.setAttribute(configJS, "add", add);
0671:                reload(configJS);
0672:            }
0673:
0674:            private native void reload(JavaScriptObject configJS) /*-{
0675:                   var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0676:                   store.reload(configJS);
0677:               }-*/;
0678:
0679:            /**
0680:             * Query the records by a specified property.
0681:             *
0682:             * @param field the field to query on
0683:             * @param value a string that the field should start with
0684:             * @return array of match records or empty array if no match found
0685:             */
0686:            public Record[] query(String field, String value) {
0687:                JavaScriptObject nativeArray = doQuery(field, value, false);
0688:                return convertFromNativeRecordsArray(nativeArray);
0689:            }
0690:
0691:            private native JavaScriptObject doQuery(String field, String value,
0692:                    boolean anyMatch) /*-{
0693:                   var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0694:                   var records = store.query(field, value, anyMatch);
0695:                   return records.items;
0696:               }-*/;
0697:
0698:            /**
0699:             * Query the records by a specified property.
0700:             *
0701:             * @param field    the field to query on
0702:             * @param value    a string that the field should start with
0703:             * @param anyMatch true to match any part not just the beginning
0704:             * @return array of match records or empty array if no match found
0705:             */
0706:            public Record[] query(String field, String value, boolean anyMatch) {
0707:                JavaScriptObject nativeArray = doQuery(field, value, anyMatch);
0708:                return convertFromNativeRecordsArray(nativeArray);
0709:            }
0710:
0711:            /**
0712:             * Query the records by a specified property.
0713:             *
0714:             * @param field  the field to query on
0715:             * @param regexp a RegExp to test against the field
0716:             * @return array of match records or empty array if no match found
0717:             */
0718:            public Record[] query(String field, RegExp regexp) {
0719:                JavaScriptObject nativeArray = doQuery(field, regexp);
0720:                return convertFromNativeRecordsArray(nativeArray);
0721:            }
0722:
0723:            private native JavaScriptObject doQuery(String field, RegExp regexp) /*-{
0724:                   var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0725:                   var re = regexp.@com.gwtext.client.core.JsObject::getJsObj()();
0726:                   var records = store.query(field, re);
0727:                   return records.items;
0728:               }-*/;
0729:
0730:            /**
0731:             * Query by a function. The specified function will be called with each record in this data source.
0732:             * If the function returns true the record is included in the results.
0733:             *
0734:             * @param queryFunction the query function
0735:             * @return array of match records or empty array if no match found
0736:             */
0737:            public Record[] queryBy(StoreQueryFunction queryFunction) {
0738:                JavaScriptObject nativeArray = doQueryBy(queryFunction);
0739:                return convertFromNativeRecordsArray(nativeArray);
0740:            }
0741:
0742:            private native JavaScriptObject doQueryBy(
0743:                    StoreQueryFunction queryFunction) /*-{
0744:                   var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0745:                   var results = store.queryBy(function(record, id) {
0746:                       id = (id === undefined)? null: id.toString();
0747:                       var recordJ = @com.gwtext.client.data.Record::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(record);
0748:                       return queryFunction.@com.gwtext.client.data.StoreQueryFunction::test(Lcom/gwtext/client/data/Record;Ljava/lang/String;)(recordJ, id);
0749:                   });
0750:                   return results.items;
0751:               }-*/;
0752:
0753:            /**
0754:             * Cancel outstanding changes on all changed records.
0755:             */
0756:            public native void rejectChanges() /*-{
0757:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0758:            	store.rejectChanges();
0759:            }-*/;
0760:
0761:            /**
0762:             * Remove a Record from the Store and fires the remove event.
0763:             *
0764:             * @param record the record to remove
0765:             */
0766:            public native void remove(Record record) /*-{
0767:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0768:            	var recordJ = record.@com.gwtext.client.core.JsObject::getJsObj()();
0769:            	return store.remove(recordJ);
0770:               }-*/;
0771:
0772:            /**
0773:             * Remove all Records from the Store and fires the clear event.
0774:             */
0775:            public native void removeAll() /*-{
0776:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0777:            	store.removeAll();
0778:            }-*/;
0779:
0780:            /**
0781:             * Sets the default sort column and order to be used by the next load operation.
0782:             *
0783:             * @param field   the name of the field to sort by
0784:             * @param sortDir the sort order
0785:             */
0786:            public void setDefaultSort(String field, SortDir sortDir) {
0787:                setDefaultSort(field, sortDir.getDirection());
0788:            }
0789:
0790:            /**
0791:             * Sets the default sort column and order to be used by the next load operation.
0792:             *
0793:             * @param field   the name of the field to sort by
0794:             * @param sortDir the sort order, "ASC" or "DESC" (defaults to "ASC")
0795:             * @deprecated Use {@link #setDefaultSort(String, com.gwtext.client.core.SortDir)}
0796:             */
0797:            public native void setDefaultSort(String field, String sortDir) /*-{
0798:                   var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0799:                   store.setDefaultSort(field, sortDir);
0800:               }-*/;
0801:
0802:            /**
0803:             * Sort the Records. If remote sorting is used, the sort is performed on the server, and the cache is reloaded.
0804:             * If local sorting is used, the cache is sorted internally.
0805:             *
0806:             * @param field the name of the field to sort by
0807:             */
0808:            public native void sort(String field) /*-{
0809:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0810:            	store.sort(field);
0811:            }-*/;
0812:
0813:            /**
0814:             * Sort the Records. If remote sorting is used, the sort is performed on the server, and the cache is reloaded.
0815:             * If local sorting is used, the cache is sorted internally.
0816:             *
0817:             * @param field     the name of the field to sort by
0818:             * @param direction the sort order
0819:             */
0820:            public void sort(String field, SortDir direction) {
0821:                sort(field, direction.getDirection());
0822:            }
0823:
0824:            /**
0825:             * Sort the Records. If remote sorting is used, the sort is performed on the server, and the cache is reloaded.
0826:             * If local sorting is used, the cache is sorted internally.
0827:             *
0828:             * @param field     the name of the field to sort by
0829:             * @param direction the sort order, "ASC" or "DESC" (defaults to "ASC")
0830:             * @deprecated Use {@link #sort(String, com.gwtext.client.core.SortDir)}
0831:             */
0832:            public native void sort(String field, String direction) /*-{
0833:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0834:            	store.sort(field, direction);
0835:            }-*/;
0836:
0837:            /**
0838:             * Sums the value of property for each record between start and end and returns the result.
0839:             *
0840:             * @param field field on your records
0841:             * @return the sum
0842:             */
0843:            public native float sum(String field) /*-{
0844:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0845:            	return store.sum(field);
0846:            }-*/;
0847:
0848:            /**
0849:             * Sums the value of property for each record between start and end and returns the result.
0850:             *
0851:             * @param field      field on your records
0852:             * @param startIndex the record index to start at (defaults to 0)
0853:             * @param endIndex   the last record index to include
0854:             * @return the sum
0855:             */
0856:            public native float sum(String field, int startIndex, int endIndex) /*-{
0857:            	var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0858:            	return store.sum(field, startIndex, endIndex);
0859:            }-*/;
0860:
0861:            /**
0862:             * Return all the Records in the Store.
0863:             *
0864:             * @return the Records
0865:             */
0866:            public Record[] getRecords() {
0867:                JavaScriptObject nativeArray = getRecords(getJsObj());
0868:                return convertFromNativeRecordsArray(nativeArray);
0869:            }
0870:
0871:            private native JavaScriptObject getRecords(JavaScriptObject store)/*-{
0872:            		return store.getRange();
0873:            	}-*/;
0874:
0875:            private static StoreLoadException createStoreLoadException(
0876:                    String message) {
0877:                return new StoreLoadException(message);
0878:            }
0879:
0880:            private static HttpStoreLoadException createHttpStoreLoadExeption(
0881:                    int httpStatus, String message) {
0882:                return new HttpStoreLoadException(httpStatus, message);
0883:            }
0884:
0885:            private static boolean isThrowable(Object object) {
0886:                return object instanceof  Throwable;
0887:            }
0888:
0889:            /**
0890:             * Add a Store listener.
0891:             *
0892:             * @param listener the listener
0893:             */
0894:            public native void addStoreListener(StoreListener listener) /*-{
0895:                var store = this.@com.gwtext.client.core.JsObject::getJsObj()();
0896:                   var storeJ = this;
0897:
0898:            	store.addListener('add',
0899:            				function(self, records, index) {
0900:            					var recordsJ = @com.gwtext.client.data.Store::convertFromNativeRecordsArray(Lcom/google/gwt/core/client/JavaScriptObject;)(records);
0901:            					listener.@com.gwtext.client.data.event.StoreListener::onAdd(Lcom/gwtext/client/data/Store;[Lcom/gwtext/client/data/Record;I)(storeJ, recordsJ, index);
0902:            				}
0903:            	);
0904:
0905:            	store.addListener('beforeload',
0906:                       function(self) {
0907:                           return listener.@com.gwtext.client.data.event.StoreListener::doBeforeLoad(Lcom/gwtext/client/data/Store;)(storeJ);
0908:                       }
0909:            	);
0910:
0911:            	store.addListener('clear',
0912:                       function(self) {
0913:                           return listener.@com.gwtext.client.data.event.StoreListener::onClear(Lcom/gwtext/client/data/Store;)(storeJ);
0914:                       }
0915:            	);
0916:
0917:            	store.addListener('datachanged',
0918:                       function(self) {
0919:                           return listener.@com.gwtext.client.data.event.StoreListener::onDataChanged(Lcom/gwtext/client/data/Store;)(storeJ);
0920:                       }
0921:            	);
0922:
0923:            	store.addListener('load',
0924:                       function(self, records) {
0925:                           var recordsJ = @com.gwtext.client.data.Store::convertFromNativeRecordsArray(Lcom/google/gwt/core/client/JavaScriptObject;)(records);
0926:                           return listener.@com.gwtext.client.data.event.StoreListener::onLoad(Lcom/gwtext/client/data/Store;[Lcom/gwtext/client/data/Record;)(storeJ, recordsJ);
0927:                       }
0928:            	);
0929:
0930:            	store.addListener('remove',
0931:                       function(self, record, index) {
0932:                           var recordJ = @com.gwtext.client.data.Record::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(record);
0933:                           return listener.@com.gwtext.client.data.event.StoreListener::onRemove(Lcom/gwtext/client/data/Store;Lcom/gwtext/client/data/Record;I)(storeJ, recordJ, index);
0934:                       }
0935:            	);
0936:
0937:            	store.addListener('update',
0938:                       function(self, record, operation) {
0939:                           var recordJ = @com.gwtext.client.data.Record::instance(Lcom/google/gwt/core/client/JavaScriptObject;)(record);
0940:                           var operationJ = null;
0941:                           if(operation =='edit') {
0942:                               operationJ = @com.gwtext.client.data.Record::EDIT;
0943:                           } else if(operation == 'reject') {
0944:                               operationJ = @com.gwtext.client.data.Record::REJECT;
0945:                           } else if (operation == 'commit') {
0946:                               operationJ = @com.gwtext.client.data.Record::COMMIT;
0947:                           }
0948:                           return listener.@com.gwtext.client.data.event.StoreListener::onUpdate(Lcom/gwtext/client/data/Store;Lcom/gwtext/client/data/Record;Lcom/gwtext/client/data/Record$Operation;)(storeJ, recordJ, operationJ);
0949:                       }
0950:            	);
0951:
0952:                   store.addListener('loadexception',
0953:                       function(proxy, arg1, response, e) {
0954:                           var err = null;
0955:                           var isException = false;
0956:                           if(e != null && e !== undefined) {
0957:                               isException = @com.gwtext.client.data.Store::isThrowable(Ljava/lang/Object;)(e);
0958:                           }
0959:                           if(isException) {
0960:                               err = e;
0961:                           } else if(e !== undefined && e.message != null && e.message !== undefined) {
0962:                               err = @com.gwtext.client.data.Store::createStoreLoadException(Ljava/lang/String;)(e.message);
0963:                           } else if(response != null && response.responseText != null && response.responseText !== undefined) {
0964:                               err = err = @com.gwtext.client.data.Store::createHttpStoreLoadExeption(ILjava/lang/String;)(response.status, response.responseText);
0965:                           } else if (response != null) {
0966:                               err = @com.gwtext.client.data.Store::createStoreLoadException(Ljava/lang/String;)(response.toString());
0967:                           }
0968:                           listener.@com.gwtext.client.data.event.StoreListener::onLoadException(Ljava/lang/Throwable;)(err);
0969:                       }
0970:            	);
0971:                }-*/;
0972:
0973:            //config options
0974:            /**
0975:             * If true, this store's load method is automatically called after creation.
0976:             *
0977:             * @param autoLoad true to auto laod
0978:             */
0979:            public void setAutoLoad(boolean autoLoad) {
0980:                JavaScriptObjectHelper.setAttribute(configJS, "autoLoad",
0981:                        autoLoad);
0982:            }
0983:
0984:            /**
0985:             * Url params which are to be sent as parameters on any HTTP request.
0986:             *
0987:             * @param baseParams the base params
0988:             */
0989:            public void setBaseParams(UrlParam[] baseParams) {
0990:                if (!isCreated()) {
0991:                    if (baseParams != null && baseParams.length > 0) {
0992:                        JavaScriptObject paramObj = UrlParam
0993:                                .getJsObj(baseParams);
0994:                        JavaScriptObjectHelper.setAttribute(configJS,
0995:                                "baseParams", paramObj);
0996:                    }
0997:                } else {
0998:                    setBaseParamsCreated(baseParams);
0999:                }
1000:            }
1001:
1002:            /**
1003:             * The Proxy object which provides access to a data object..
1004:             *
1005:             * @param proxy the data proxy
1006:             */
1007:            public void setDataProxy(DataProxy proxy) {
1008:                if (!isCreated()) {
1009:                    JavaScriptObjectHelper.setAttribute(configJS, "proxy",
1010:                            proxy.getJsObj());
1011:                } else {
1012:                    setDataProxyCreated(proxy);
1013:                }
1014:            }
1015:
1016:            /**
1017:             * True to clear all modified record information each time the store is loaded or when a record is removed. (defaults to false).
1018:             *
1019:             * @param pruneModifiedRecords true to prune modified records
1020:             */
1021:            public void setPruneModifiedRecords(boolean pruneModifiedRecords) {
1022:                JavaScriptObjectHelper.setAttribute(configJS,
1023:                        "pruneModifiedRecords", pruneModifiedRecords);
1024:            }
1025:
1026:            /**
1027:             * The Reader object which processes the data object and returns an Array of Ext.data.record objects which are cached
1028:             * keyed by their id property.
1029:             *
1030:             * @param reader the reader
1031:             */
1032:            public void setReader(Reader reader) {
1033:                JavaScriptObjectHelper.setAttribute(configJS, "reader", reader
1034:                        .getJsObj());
1035:            }
1036:
1037:            /**
1038:             * True if sorting is to be handled by requesting the Proxy to provide a refreshed version of the data object in sorted order, as opposed to sorting the Record cache in place (defaults to false).
1039:             * If remote sorting is specified, then clicking on a column header causes the current page to be requested from the server with the addition of the following two parameters:
1040:             * <p/>
1041:             * sort : String  The name (as specified in the Record's Field definition) of the field to sort on.
1042:             * dir : String The direction of the sort, "ASC" or "DESC".
1043:             *
1044:             * @param remoteSort true to enable remote sort
1045:             */
1046:            public void setRemoteSort(boolean remoteSort) {
1047:                JavaScriptObjectHelper.setAttribute(configJS, "remoteSort",
1048:                        remoteSort);
1049:            }
1050:
1051:            /**
1052:             * The initial field to sort and its direction
1053:             *
1054:             * @param sortInfo the sort info
1055:             */
1056:            public void setSortInfo(SortState sortInfo) {
1057:                JavaScriptObjectHelper.setAttribute(configJS, "sortInfo",
1058:                        sortInfo.getJsObj());
1059:            }
1060:
1061:            /**
1062:             * If passed, the id to use to register with the StoreMgr.
1063:             *
1064:             * @param storeId the store ID
1065:             */
1066:            public void setStoreId(String storeId) {
1067:                JavaScriptObjectHelper.setAttribute(configJS, "storeId",
1068:                        storeId);
1069:            }
1070:
1071:            /**
1072:             * If passed, an HttpProxy is created for the passed URL.
1073:             *
1074:             * @param url the url
1075:             */
1076:            public void setUrl(String url) {
1077:                JavaScriptObjectHelper.setAttribute(configJS, "url", url);
1078:            }
1079:
1080:            /**
1081:             * Sets the record def for the Store.
1082:             *
1083:             * @param recordDef the stores record def 
1084:             */
1085:            public void setRecordDef(RecordDef recordDef) {
1086:                JavaScriptObjectHelper.setAttribute(configJS, "recordType",
1087:                        recordDef.getJsObj());
1088:            }
1089:
1090:            /**
1091:             * Set the initial sort state.
1092:             *
1093:             * @param initialSortState the initial sort state
1094:             */
1095:            public void setInitialSortState(SortState initialSortState) {
1096:                if (initialSortState != null) {
1097:                    JavaScriptObject sortStateParamObj = JavaScriptObjectHelper
1098:                            .createObject();
1099:                    JavaScriptObjectHelper.setAttribute(sortStateParamObj,
1100:                            "field", initialSortState.getField());
1101:                    JavaScriptObjectHelper.setAttribute(sortStateParamObj,
1102:                            "direction", initialSortState.getDirection()
1103:                                    .getDirection());
1104:                    JavaScriptObjectHelper.setAttribute(configJS, "sortInfo ",
1105:                            sortStateParamObj);
1106:                }
1107:            }
1108:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.