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.BeforeClear : StoreEvent(store)
Fires before the store is cleared. Listeners can cancel the action by calling BaseEvent.setCancelled(boolean).
Store.Clear : StoreEvent(store)
Fires when the data cache has been cleared.


Field Summary
static EventType Add
          Add event type.
protected  java.util.List<M> all
           
static EventType BeforeAdd
          BeforeAdd event type.
static EventType BeforeClear
          BeforeClear event type.
static EventType BeforeDataChanged
          BeforeDataChanged event type.
static EventType BeforeRemove
          BeforeRemove 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.
protected  java.lang.String filterBeginsWith
           
protected  java.util.List<M> filtered
           
protected  java.lang.String filterProperty
           
protected  java.util.List<StoreFilter<M>> filters
           
protected  boolean filtersEnabled
           
protected  java.util.List<Record> modified
           
protected  java.util.Map<M,Record> recordMap
           
static EventType Remove
          Remove event type.
protected  java.util.List<M> snapshot
           
static EventType Sort
          Filter event type.
protected  SortInfo sortInfo
           
protected  StoreSorter<M> storeSorter
           
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.
protected  void afterCommit(Record record)
           
protected  void afterEdit(Record record)
           
protected  void afterReject(Record record)
           
 void applyFilters(java.lang.String property)
          Applies the current filters to the store.
protected  void applySort(boolean supressEvent)
           
 void clearFilters()
          Revert to a view of this store with no filtering applied.
 void commitChanges()
          Commit all items with outstanding changes.
 boolean contains(M item)
          Returns true if the item is in this store.
protected  StoreEvent<M> createStoreEvent()
           
 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.
protected  void fireStoreEvent(EventType type, Record.RecordUpdate operation, Record record)
           
 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.
protected  boolean isFiltered(ModelData record, java.lang.String property)
           
 boolean isMonitorChanges()
          Returns true if the store is monitoring changes.
protected  void onModelChange(ChangeEvent ce)
           
protected  void registerModel(M model)
          Subclasses must register any model instance being inserted into the store.
 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.
protected  void swapModelInstance(M oldModel, M newModel)
           
protected  void unregisterModel(M model)
          Subclasses must unregister any model instance being removed from the store.
 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, callListener, fireEvent, fireEvent, getFiresEvents, getListeners, hasActiveEvent, hasListeners, hasListeners, removeAllListeners, removeListener, setFiresEvents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

BeforeAdd

public static final EventType BeforeAdd
BeforeAdd event type.


BeforeClear

public static final EventType BeforeClear
BeforeClear event type.


BeforeDataChanged

public static final EventType BeforeDataChanged
BeforeDataChanged event type.


BeforeRemove

public static final EventType BeforeRemove
BeforeRemove 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.


all

protected java.util.List<M extends ModelData> all

recordMap

protected java.util.Map<M extends ModelData,Record> recordMap

filtered

protected java.util.List<M extends ModelData> filtered

modified

protected java.util.List<Record> modified

sortInfo

protected SortInfo sortInfo

storeSorter

protected StoreSorter<M extends ModelData> storeSorter

filterProperty

protected java.lang.String filterProperty

filterBeginsWith

protected java.lang.String filterBeginsWith

filtersEnabled

protected boolean filtersEnabled

snapshot

protected java.util.List<M extends ModelData> snapshot

filters

protected java.util.List<StoreFilter<M extends ModelData>> filters
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(M 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 not 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

afterCommit

protected void afterCommit(Record record)

afterEdit

protected void afterEdit(Record record)

afterReject

protected void afterReject(Record record)

applySort

protected void applySort(boolean supressEvent)

createStoreEvent

protected StoreEvent<M> createStoreEvent()

fireStoreEvent

protected void fireStoreEvent(EventType type,
                              Record.RecordUpdate operation,
                              Record record)

isFiltered

protected boolean isFiltered(ModelData record,
                             java.lang.String property)

onModelChange

protected void onModelChange(ChangeEvent ce)

registerModel

protected void registerModel(M model)
Subclasses must register any model instance being inserted into the store.

Parameters:
model - the model

swapModelInstance

protected void swapModelInstance(M oldModel,
                                 M newModel)

unregisterModel

protected void unregisterModel(M model)
Subclasses must unregister any model instance being removed from the store.

Parameters:
model - the model