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

java.lang.Object
  extended by com.sencha.gxt.data.shared.Store<M>
      extended by com.sencha.gxt.data.shared.ListStore<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>

public class ListStore<M>
extends Store<M>

List-like client side cache for elements. All operations are performed on the currently visible set of elements.


Nested Class Summary
 
Nested classes/interfaces inherited from class com.sencha.gxt.data.shared.Store
Store.Change<M,V>, Store.PropertyChange<M,V>, Store.Record, Store.StoreFilter<M>, Store.StoreSortInfo<M>
 
Constructor Summary
ListStore(ModelKeyProvider<? super M> keyProvider)
          Creates a new store.
 
Method Summary
 void add(int index, M item)
          Like add(M), except the item will be inserted at the given index in the visible items.
 void add(M item)
          Adds the given item to the end of the list.
 boolean addAll(Collection<? extends M> items)
          Adds all items to the end of the list.
 boolean addAll(int index, Collection<? extends M> items)
          Adds all items at the given position.
 void applySort(boolean suppressEvent)
          Tells the store to re-apply sort settings and to fire an event when complete.
 void clear()
          Removes all items from the store.
 M findModelWithKey(String key)
          Finds the model with the given key, using ModelKeyProvider as necessary.
 M get(int index)
          Gets the given item from the list.
 List<M> getAll()
          Returns a list of all items contained in the store.
 int indexOf(M item)
          Gets the position of the item in the set of visible items.
 M remove(int index)
          A ListStore acts like a Java List, and stuff is arranged in a linear fashion, so it may be advantageous to remove based on index.
 boolean remove(M model)
          Removes the given item, visible or not, from the store.
 void replaceAll(List<M> newItems)
          Replaces all the items in the store with given list of new items.
 int size()
          Returns the number of visible items.
 List<M> subList(int start, int end)
          Creates a new list containing references to the items in the specified range.
 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 com.sencha.gxt.data.shared.Store
addFilter, addSortInfo, addSortInfo, addStoreAddHandler, addStoreClearHandler, addStoreDataChangeHandler, addStoreFilterHandler, addStoreHandlers, addStoreRecordChangeHandler, addStoreRemoveHandler, addStoreSortHandler, addStoreUpdateHandler, clearSortInfo, commitChanges, findModel, fireEvent, getFilters, getKeyProvider, getModifiedRecords, getRecord, getSortInfo, hasMatchingKey, hasRecord, isAutoCommit, isEnableFilters, isFiltered, rejectChanges, removeFilter, removeFilters, setAutoCommit, setEnableFilters
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListStore

public ListStore(ModelKeyProvider<? super M> keyProvider)
Creates a new store.

Parameters:
keyProvider - the key provider
Method Detail

add

public void add(int index,
                M item)
Like add(M), except the item will be inserted at the given index in the visible items. If filters are enabled, it will be added to the un-filtered list after its previous sibling in the filtered list. Note that the item may not be visible, depending on the filters configured. In this case its position in the un-filtered list will still be after where it would have been in the filtered list.

Parameters:
index - - the index in the visible items. Must be a valid index, in the range [0,size()). If the store is sorted, the index will be ignored
item - the item to be added

add

public void add(M item)
Adds the given item to the end of the list.

Parameters:
item - the item to be added

addAll

public boolean addAll(Collection<? extends M> items)
Adds all items to the end of the list.

Parameters:
items - the items to be added
Returns:
true if all items added

addAll

public boolean addAll(int index,
                      Collection<? extends M> items)
Adds all items at the given position.

Parameters:
index - the insert index
items - the items to be added
Returns:
true if all items added

applySort

public void applySort(boolean suppressEvent)
Description copied from class: Store
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 Store.addSortInfo(StoreSortInfo), Store.addSortInfo(int, StoreSortInfo), and Store.clearSortInfo().

Specified by:
applySort in class Store<M>
Parameters:
suppressEvent - true to suppress event from firing

clear

public void clear()
Description copied from class: Store
Removes all items from the store.


findModelWithKey

public M findModelWithKey(String key)
Description copied from class: Store
Finds the model with the given key, using ModelKeyProvider as necessary.

Specified by:
findModelWithKey in class Store<M>
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

get

public M get(int index)
Gets the given item from the list. In keeping with the 2.x api, does not throw exceptions if you request obviously unavailable items. Index is relative to the ordered set of visible items.

Parameters:
index - the specified index.
Returns:
the visible item.

getAll

public List<M> getAll()
Description copied from class: Store
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.

Specified by:
getAll in class Store<M>
Returns:
an ordered list of all items in the ListStore

indexOf

public int indexOf(M item)
Gets the position of the item in the set of visible items.

Parameters:
item - the visible item
Returns:
the index of the item

remove

public M remove(int index)
A ListStore acts like a Java List, and stuff is arranged in a linear fashion, so it may be advantageous to remove based on index. Note that this index is relative to the visible items, so items not visible cannot be removed in this way.

Parameters:
index - the index of the item to remove

remove

public boolean remove(M model)
Removes the given item, visible or not, from the store.

Parameters:
model - model to remove
Returns:
true if item was removed

replaceAll

public void replaceAll(List<M> newItems)
Replaces all the items in the store with given list of new items.

Parameters:
newItems - the new contents of the store

size

public int size()
Returns the number of visible items.

Returns:
the number of visible items

subList

public List<M> subList(int start,
                       int end)
Creates a new list containing references to the items in the specified range.

Parameters:
start - the starting index
end - the ending index
Returns:
a list of references to the store items in given range

update

public void update(M item)
Description copied from class: Store
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.

Specified by:
update in class Store<M>
Parameters:
item - the new item to take its place in the Store.


Copyright © 2012. All Rights Reserved.