com.sencha.gxt.data.shared
Class Store<M>

java.lang.Object
  extended by com.sencha.gxt.data.shared.Store<M>
Type Parameters:
M - the model type
All Implemented Interfaces:
EventHandler, HasHandlers, StoreAddEvent.HasStoreAddHandlers<M>, StoreClearEvent.HasStoreClearHandler<M>, StoreDataChangeEvent.HasStoreDataChangeHandlers<M>, StoreFilterEvent.HasStoreFilterHandlers<M>, StoreHandlers.HasStoreHandlers<M>, StoreRecordChangeEvent.HasStoreRecordChangeHandlers<M>, StoreRemoveEvent.HasStoreRemoveHandler<M>, StoreSortEvent.HasStoreSortHandler<M>, StoreUpdateEvent.HasStoreUpdateHandlers<M>
Direct Known Subclasses:
ListStore, TreeStore

public abstract class Store<M>
extends Object
implements StoreHandlers.HasStoreHandlers<M>

Store is a client-side cache for collections of data. Modifications made to the Store via Records are not passed right away to the data, allowing for the changes to be committed or rolled back.


Nested Class Summary
static interface Store.Change<M,V>
          Represents a change that can occur to a given model.
static class Store.PropertyChange<M,V>
          ValueProvider-based change impl - takes a ValueProvider and the new value to be changed.
 class Store.Record
          Records wrap model instances and provide specialized editing features, including modification tracking and editing capabilities.
static interface Store.StoreFilter<M>
          Defines the interface for store filters.
static class Store.StoreSortInfo<M>
          Sort information for a Store to use.
 
Constructor Summary
Store(ModelKeyProvider<? super M> keyProvider)
          Creates a store with the given key provider.
 
Method Summary
 void addFilter(Store.StoreFilter<M> filter)
          Adds the filter to the end of the store's set of filters.
 void addSortInfo(int index, Store.StoreSortInfo<M> info)
          Adds the sort info at the specified index.
 void addSortInfo(Store.StoreSortInfo<M> info)
          Adds the specified sort info to the store.
 HandlerRegistration addStoreAddHandler(StoreAddEvent.StoreAddHandler<M> handler)
          Adds a StoreAddEvent handler.
 HandlerRegistration addStoreClearHandler(StoreClearEvent.StoreClearHandler<M> handler)
          Adds a StoreClearEvent handler.
 HandlerRegistration addStoreDataChangeHandler(StoreDataChangeEvent.StoreDataChangeHandler<M> handler)
          Adds a StoreDataChangeEvent handler.
 HandlerRegistration addStoreFilterHandler(StoreFilterEvent.StoreFilterHandler<M> handler)
          Adds a StoreFilterEvent handler.
 HandlerRegistration addStoreHandlers(StoreHandlers<M> handlers)
          Adds a common store event handler.
 HandlerRegistration addStoreRecordChangeHandler(StoreRecordChangeEvent.StoreRecordChangeHandler<M> handler)
          Adds a StoreRecordChangeEvent handler.
 HandlerRegistration addStoreRemoveHandler(StoreRemoveEvent.StoreRemoveHandler<M> handler)
          Adds a StoreRemoveEvent handler.
 HandlerRegistration addStoreSortHandler(StoreSortEvent.StoreSortHandler<M> handler)
          Adds a StoreSortEvent handler.
 HandlerRegistration addStoreUpdateHandler(StoreUpdateEvent.StoreUpdateHandler<M> handler)
          Adds a StoreUpdateEvent handler.
abstract  void applySort(boolean suppressEvent)
          Tells the store to re-apply sort settings and to fire an event when complete.
 void clearSortInfo()
          Removes all of the sort info from the store, so subsequent calls to applySort will not change the order.
 void commitChanges()
          Commits the outstanding changes.
 M findModel(M model)
          Finds the matching model using the store's key provider.
abstract  M findModelWithKey(String key)
          Finds the model with the given key, using ModelKeyProvider as necessary.
 void fireEvent(GwtEvent<?> event)
           
abstract  List<M> getAll()
          Returns a list of all items contained in the store.
 LinkedHashSet<Store.StoreFilter<M>> getFilters()
          Returns the stores filters.
 ModelKeyProvider<? super M> getKeyProvider()
          Returns the stores model key provider.
 Collection<Store.Record> getModifiedRecords()
          Returns a list of records that have been changed and not committed.
 Store.Record getRecord(M data)
          Gets the current Record instance for the given item.
 List<Store.StoreSortInfo<M>> getSortInfo()
          Gets the list of sort info objects.
 boolean hasMatchingKey(M model1, M model2)
          Returns true if the two models have the same key.
 boolean hasRecord(M data)
          Returns true if a record exists for the given model.
 boolean isAutoCommit()
          Returns true if auto commit is enabled.
 boolean isEnableFilters()
          Returns true if filtering is enabled, whether or not filters are present.
 boolean isFiltered()
          Returns true if filtering is enabled AND the store has filters.
 void rejectChanges()
          Cancel outstanding changes on all changed records.
 void removeFilter(Store.StoreFilter<M> filter)
          Removes the filter from the store's set of filters.
 void removeFilters()
          Removes all filters.
 void setAutoCommit(boolean isAutoCommit)
          Enables or disables auto commit.
 void setEnableFilters(boolean enableFilters)
          Enables or disables the filters.
abstract  void update(M item)
          Replaces the item that matches the key of the given item, and fires a StoreUpdateEvent to indicate that this change has occurred.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Store

public Store(ModelKeyProvider<? super M> keyProvider)
Creates a store with the given key provider. The key provider is responsible for returning a unique key for a given model

Parameters:
keyProvider - the key provider, responsible for returning a unique key for a given model
Method Detail

addFilter

public void addFilter(Store.StoreFilter<M> filter)
Adds the filter to the end of the store's set of filters. Runs the filters again if they are enabled.

Parameters:
filter - the filter to add

addSortInfo

public void addSortInfo(int index,
                        Store.StoreSortInfo<M> info)
Adds the sort info at the specified index. The store will be sorted after this change.

Parameters:
index - the sort index
info - the sort info

addSortInfo

public void addSortInfo(Store.StoreSortInfo<M> info)
Adds the specified sort info to the store. The store will then be sorted based on this new sort info.

Parameters:
info - the sort info

addStoreAddHandler

public HandlerRegistration addStoreAddHandler(StoreAddEvent.StoreAddHandler<M> handler)
Description copied from interface: StoreAddEvent.HasStoreAddHandlers
Adds a StoreAddEvent handler.

Specified by:
addStoreAddHandler in interface StoreAddEvent.HasStoreAddHandlers<M>
Parameters:
handler - the handler
Returns:
the registration for the event

addStoreClearHandler

public HandlerRegistration addStoreClearHandler(StoreClearEvent.StoreClearHandler<M> handler)
Description copied from interface: StoreClearEvent.HasStoreClearHandler
Adds a StoreClearEvent handler.

Specified by:
addStoreClearHandler in interface StoreClearEvent.HasStoreClearHandler<M>
Parameters:
handler - the handler
Returns:
the registration for the event

addStoreDataChangeHandler

public HandlerRegistration addStoreDataChangeHandler(StoreDataChangeEvent.StoreDataChangeHandler<M> handler)
Description copied from interface: StoreDataChangeEvent.HasStoreDataChangeHandlers
Adds a StoreDataChangeEvent handler.

Specified by:
addStoreDataChangeHandler in interface StoreDataChangeEvent.HasStoreDataChangeHandlers<M>
Parameters:
handler - the handler
Returns:
the registration for the event

addStoreFilterHandler

public HandlerRegistration addStoreFilterHandler(StoreFilterEvent.StoreFilterHandler<M> handler)
Description copied from interface: StoreFilterEvent.HasStoreFilterHandlers
Adds a StoreFilterEvent handler.

Specified by:
addStoreFilterHandler in interface StoreFilterEvent.HasStoreFilterHandlers<M>
Parameters:
handler - the handler
Returns:
the registration for the event

addStoreHandlers

public HandlerRegistration addStoreHandlers(StoreHandlers<M> handlers)
Description copied from interface: StoreHandlers.HasStoreHandlers
Adds a common store event handler.

Specified by:
addStoreHandlers in interface StoreHandlers.HasStoreHandlers<M>
Parameters:
handlers - the handlers
Returns:
the registration for the event

addStoreRecordChangeHandler

public HandlerRegistration addStoreRecordChangeHandler(StoreRecordChangeEvent.StoreRecordChangeHandler<M> handler)
Description copied from interface: StoreRecordChangeEvent.HasStoreRecordChangeHandlers
Adds a StoreRecordChangeEvent handler.

Specified by:
addStoreRecordChangeHandler in interface StoreRecordChangeEvent.HasStoreRecordChangeHandlers<M>
Parameters:
handler - the handler
Returns:
the registration for the event

addStoreRemoveHandler

public HandlerRegistration addStoreRemoveHandler(StoreRemoveEvent.StoreRemoveHandler<M> handler)
Description copied from interface: StoreRemoveEvent.HasStoreRemoveHandler
Adds a StoreRemoveEvent handler.

Specified by:
addStoreRemoveHandler in interface StoreRemoveEvent.HasStoreRemoveHandler<M>
Parameters:
handler - the handler
Returns:
the registration for the event

addStoreSortHandler

public HandlerRegistration addStoreSortHandler(StoreSortEvent.StoreSortHandler<M> handler)
Description copied from interface: StoreSortEvent.HasStoreSortHandler
Adds a StoreSortEvent handler.

Specified by:
addStoreSortHandler in interface StoreSortEvent.HasStoreSortHandler<M>
Parameters:
handler - the handler
Returns:
the registration for the event

addStoreUpdateHandler

public HandlerRegistration addStoreUpdateHandler(StoreUpdateEvent.StoreUpdateHandler<M> handler)
Description copied from interface: StoreUpdateEvent.HasStoreUpdateHandlers
Adds a StoreUpdateEvent handler.

Specified by:
addStoreUpdateHandler in interface StoreUpdateEvent.HasStoreUpdateHandlers<M>
Parameters:
handler - the handler
Returns:
the registration for the event

applySort

public abstract void applySort(boolean suppressEvent)
Tells the store to re-apply sort settings and to fire an event when complete. Must be called when manipulating the sort settings directly instead of through the store, or the sort order will not change. Automatically called after addSortInfo(StoreSortInfo), addSortInfo(int, StoreSortInfo), and clearSortInfo().

Parameters:
suppressEvent - true to suppress event from firing

clearSortInfo

public void clearSortInfo()
Removes all of the sort info from the store, so subsequent calls to applySort will not change the order.


commitChanges

public void commitChanges()
Commits the outstanding changes.


findModel

public M findModel(M model)
Finds the matching model using the store's key provider.

Parameters:
model - target model
Returns:
the matching model or null

findModelWithKey

public abstract M findModelWithKey(String key)
Finds the model with the given key, using ModelKeyProvider as necessary.

Parameters:
key - the key of the model to find
Returns:
the model with the given key, or null if the model cannot be found in the store

fireEvent

public void fireEvent(GwtEvent<?> event)
Specified by:
fireEvent in interface HasHandlers

getAll

public abstract List<M> getAll()
Returns a list of all items contained in the store. Modifying this list will not change the store, as this is a copy of the contents of the store. Note also that because this is a copy, this can be a expensive call to make.

Returns:
the list of items

getFilters

public LinkedHashSet<Store.StoreFilter<M>> getFilters()
Returns the stores filters.

Returns:
the filters

getKeyProvider

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

Returns:
the model key provider

getModifiedRecords

public Collection<Store.Record> getModifiedRecords()
Returns a list of records that have been changed and not committed.

Returns:
the list of modified records

getRecord

public Store.Record getRecord(M data)
Gets the current Record instance for the given item.

Parameters:
data - the data key
Returns:
the record

getSortInfo

public List<Store.StoreSortInfo<M>> getSortInfo()
Gets the list of sort info objects. This list may be modified directly, but before it takes effect, applySort(boolean) must be called. Note that addSortInfo(StoreSortInfo) and addSortInfo(int, StoreSortInfo) will add the new sort info the this list, and then call applySort directly.

Returns:
the current mutable list of StoreSortInfo instances

hasMatchingKey

public boolean hasMatchingKey(M model1,
                              M model2)
Returns true if the two models have the same key.

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

hasRecord

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

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

isAutoCommit

public boolean isAutoCommit()
Returns true if auto commit is enabled.

Returns:
true if auto commit is enabled

isEnableFilters

public boolean isEnableFilters()
Returns true if filtering is enabled, whether or not filters are present.

Returns:
true if filtering is enabled

isFiltered

public boolean isFiltered()
Returns true if filtering is enabled AND the store has filters.

Returns:
true if the store is filtered

rejectChanges

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


removeFilter

public void removeFilter(Store.StoreFilter<M> filter)
Removes the filter from the store's set of filters. Runs the filters again if they are enabled, and the filter was actually in the list.

Parameters:
filter - the filter to be removed

removeFilters

public void removeFilters()
Removes all filters.


setAutoCommit

public void setAutoCommit(boolean isAutoCommit)
Enables or disables auto commit. If auto commit is enabled, the change will be made directly to the model, else the change will be queued up until commit() is called.

Parameters:
isAutoCommit - true to enable auto commit
See Also:
Store.Record.addChange(ValueProvider, Object)

setEnableFilters

public void setEnableFilters(boolean enableFilters)
Enables or disables the filters.

Parameters:
enableFilters - true to enable filters

update

public abstract void update(M item)
Replaces the item that matches the key of the given item, and fires a StoreUpdateEvent to indicate that this change has occurred. This will not cause the sort or filter to be re-applied to the object.

Parameters:
item - the new item to take its place in the Store.


Copyright © 2012. All Rights Reserved.