com.extjs.gxt.ui.client.store
Class Store<M extends ModelData>

java.lang.Object
  extended by com.extjs.gxt.ui.client.event.BaseObservable
      extended by com.extjs.gxt.ui.client.store.Store<M>
Type Parameters:
M - the model data type
All Implemented Interfaces:
Observable
Direct Known Subclasses:
ListStore, TreeStore

public abstract class Store<M extends ModelData>
extends BaseObservable

The store class encapsulates a client side cache of ModelData objects which provide input data for components such as the ComboBox and ListView.

Events:
Store.Filter : StoreEvent(store)
Fires when filters are applied and removed from the store.
Store.Update : StoreEvent(store, model, record)
Fires when a model has been updated via its record.
Store.Clear : StoreEvent(store)
Fires when the data cache has been cleared.


Field Summary
static EventType Add
          Add event type.
static EventType BeforeDataChanged
          BeforeDataChanged event type.
static EventType BeforeSort
          BeforeSort event type.
static EventType Clear
          Clear event type.
static EventType DataChanged
          DataChanged event type.
static EventType Filter
          Filter event type.
static EventType Remove
          Remove event type.
static EventType Sort
          Filter event type.
static EventType Update
          Update event type.
 
Constructor Summary
Store()
           
 
Method Summary
 void addFilter(StoreFilter<M> filter)
          Adds a filter to the store.
 void addStoreListener(StoreListener<M> listener)
          Adds a store listener.
 void applyFilters(java.lang.String property)
          Applies the current filters to the store.
 void clearFilters()
          Revert to a view of this store with no filtering applied.
 void commitChanges()
          Commit all items with outstanding changes.
 boolean contains(ModelData item)
          Returns true if the item is in this store.
 boolean equals(M model1, M model2)
          Returns true if the two models are equal as defined by the model comparer.
 void filter(java.lang.String property)
          Filters the store using the given property.
 void filter(java.lang.String property, java.lang.String beginsWith)
          Filters the store using the given property.
 M findModel(M model)
          Returns the matching model in the cache using the model comparer to test for equality.
 M findModel(java.lang.String key)
           
 M findModel(java.lang.String property, java.lang.Object value)
          Returns the first model whose property matches the given value.
 java.util.List<M> findModels(java.lang.String property, java.lang.Object value)
          Returns a list of all matching models whose property matches the given value.
 java.util.List<StoreFilter<M>> getFilters()
          Returns the store's filters.
 ModelKeyProvider<M> getKeyProvider()
          Returns the model key provider.
 ModelComparer<M> getModelComparer()
          Returns the comparer used to compare model instances.
 java.util.List<M> getModels()
          Returns the store's models.
 java.util.List<Record> getModifiedRecords()
          Gets all records modified since the last commit.
 Record getRecord(M model)
          Returns the record instance for the item.
 StoreSorter<M> getStoreSorter()
          Returns the store sorter.
 boolean hasRecord(M model)
          Returns true if a record exists for the given model.
 boolean isFiltered()
          Returns true if this store is currently filtered.
 boolean isMonitorChanges()
          Returns true if the store is monitoring changes.
 void rejectChanges()
          Cancel outstanding changes on all changed records.
 void removeAll()
          Remove all items from the store and fires the Clear event.
 void removeFilter(StoreFilter<M> filter)
          Removes a previously added filter.
 void removeStoreListener(StoreListener<M> listener)
          Removes a store listener.
 void setKeyProvider(ModelKeyProvider<M> keyProvider)
          Sets the model key provider which is used to uniquely identify a model from an id.
 void setModelComparer(ModelComparer<M> comparer)
          Sets the comparer to be used when comparing model instances.
 void setMonitorChanges(boolean monitorChanges)
          Sets whether the store should listen to change events on its children (defaults to false).
 void setStoreSorter(StoreSorter<M> storeSorter)
          Sets the store's sorter.
 void update(M model)
          Notifies the store that the model has been updated and fires the Update event.
 
Methods inherited from class com.extjs.gxt.ui.client.event.BaseObservable
addListener, fireEvent, fireEvent, getFiresEvents, getListeners, hasActiveEvent, hasListeners, hasListeners, removeAllListeners, removeListener, setFiresEvents
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BeforeDataChanged

public static final EventType BeforeDataChanged
BeforeDataChanged event type.


BeforeSort

public static final EventType BeforeSort
BeforeSort event type.


DataChanged

public static final EventType DataChanged
DataChanged event type.


Filter

public static final EventType Filter
Filter event type.


Sort

public static final EventType Sort
Filter event type.


Add

public static final EventType Add
Add event type.


Remove

public static final EventType Remove
Remove event type.


Update

public static final EventType Update
Update event type.


Clear

public static final EventType Clear
Clear event type.

Constructor Detail

Store

public Store()
Method Detail

addFilter

public void addFilter(StoreFilter<M> filter)
Adds a filter to the store.

Parameters:
filter - the store filter to add

addStoreListener

public void addStoreListener(StoreListener<M> listener)
Adds a store listener.

Parameters:
listener - the listener to add

applyFilters

public void applyFilters(java.lang.String property)
Applies the current filters to the store.

Parameters:
property - the optional active property

clearFilters

public void clearFilters()
Revert to a view of this store with no filtering applied.


commitChanges

public void commitChanges()
Commit all items with outstanding changes. To handle updates for changes, subscribe to the Store's Update event, and perform updating when the operation parameter is Record.RecordUpdate.COMMIT.


contains

public boolean contains(ModelData item)
Returns true if the item is in this store.

Parameters:
item - the item
Returns:
true if container

equals

public boolean equals(M model1,
                      M model2)
Returns true if the two models are equal as defined by the model comparer.

Parameters:
model1 - the first model
model2 - the second model
Returns:
true if equals

filter

public void filter(java.lang.String property)
Filters the store using the given property.

Parameters:
property - the property to filter by

filter

public void filter(java.lang.String property,
                   java.lang.String beginsWith)
Filters the store using the given property.

Parameters:
property - the property to filter by
beginsWith - a string the value should begin with

findModel

public M findModel(M model)
Returns the matching model in the cache using the model comparer to test for equality.

Parameters:
model - the model
Returns:
the matching model or null if no match

findModel

public M findModel(java.lang.String key)

findModel

public M findModel(java.lang.String property,
                   java.lang.Object value)
Returns the first model whose property matches the given value.

Parameters:
property - the property name
value - the value to match
Returns:
the model or null if no match

findModels

public java.util.List<M> findModels(java.lang.String property,
                                    java.lang.Object value)
Returns a list of all matching models whose property matches the given value.

Parameters:
property - the property name
value - the value to match
Returns:
the list of matching models

getFilters

public java.util.List<StoreFilter<M>> getFilters()
Returns the store's filters.

Returns:
the filters

getKeyProvider

public ModelKeyProvider<M> getKeyProvider()
Returns the model key provider.

Returns:
the key provider

getModelComparer

public ModelComparer<M> getModelComparer()
Returns the comparer used to compare model instances.

Returns:
the comparer

getModels

public java.util.List<M> getModels()
Returns the store's models.

Returns:
the items

getModifiedRecords

public java.util.List<Record> getModifiedRecords()
Gets all records modified since the last commit. Modified records are persisted across load operations (e.g., during paging).

Returns:
a list of modified records

getRecord

public Record getRecord(M model)
Returns the record instance for the item. Records are created on-demand and are cleared after a stores modifications are accepted or rejected.

Parameters:
model - the item
Returns:
the record for the item

getStoreSorter

public StoreSorter<M> getStoreSorter()
Returns the store sorter.

Returns:
the store sorter

hasRecord

public boolean hasRecord(M model)
Returns true if a record exists for the given model.

Parameters:
model - the model
Returns:
true if a record exists

isFiltered

public boolean isFiltered()
Returns true if this store is currently filtered.

Returns:
true if the store is filtered

isMonitorChanges

public boolean isMonitorChanges()
Returns true if the store is monitoring changes.

Returns:
the monitor changes state

rejectChanges

public void rejectChanges()
Cancel outstanding changes on all changed records.


removeAll

public void removeAll()
Remove all items from the store and fires the Clear event.


removeFilter

public void removeFilter(StoreFilter<M> filter)
Removes a previously added filter.

Parameters:
filter - the filter to remove

removeStoreListener

public void removeStoreListener(StoreListener<M> listener)
Removes a store listener.

Parameters:
listener - the store listener to remove

setKeyProvider

public void setKeyProvider(ModelKeyProvider<M> keyProvider)
Sets the model key provider which is used to uniquely identify a model from an id. The store itself, does not use the key provider.

Parameters:
keyProvider - the model key provider

setModelComparer

public void setModelComparer(ModelComparer<M> comparer)
Sets the comparer to be used when comparing model instances.

Parameters:
comparer - the comparer

setMonitorChanges

public void setMonitorChanges(boolean monitorChanges)
Sets whether the store should listen to change events on its children (defaults to false). This method should be called prior to any models being added to the store when monitoring changes. Only model instances which implement ChangeEventSource may be monitored.

Parameters:
monitorChanges - true to monitor changes

setStoreSorter

public void setStoreSorter(StoreSorter<M> storeSorter)
Sets the store's sorter.

Parameters:
storeSorter - the sorter

update

public void update(M model)
Notifies the store that the model has been updated and fires the Update event.

Parameters:
model - the updated model