com.extjs.gxt.ui.client.store
Class TreeStore<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>
          extended by com.extjs.gxt.ui.client.store.TreeStore<M>
All Implemented Interfaces:
Observable

public class TreeStore<M extends ModelData>
extends Store<M>

A store for hierarchical data.

The parent child relationships are handled internally by the store. It is important to note that the store does not use the the parent and children of any TreeModel instances added to the store.

It is important to note the sorting behavior when working with TreeStore. When a sorter is set, it is applied to all existing models in the cache and the Sort event is fired. At this point, the sorter is enabled and active.

Remote sorting is not supported with TreeStore.

Events:
Store.BeforeDataChanged : TreeStoreEvent(store)
Fires before the store's data is changed. Apply applies when a store is bound to a loader.
Store.DataChange : TreeStoreEvent(store)
Fires when the data cache has changed, and a widget which is using this Store as a Model cache should refresh its view.
Store.Filter : TreeStoreEvent(store)
Fires when filters are applied and removed from the store.
Store.Add : TreeStoreEvent(store, parent, child)
Fires when models have been added to the store.
Store.Remove : TreeStoreEvent(store, parent, child)
Fires when a model has been removed from the store.
Store.Update : TreeStoreEvent(store, model, record)
Fires when a model has been updated via its record.
Store.Clear : TreeStoreEvent(store)
Fires when the data cache has been cleared.
Store.Sort : TreeStoreEvent(store)
Fires after a sorter is applied to the store.


Field Summary
protected  TreeLoader<M> loader
           
protected  java.util.Map<java.lang.String,TreeModel> modelFastMap
           
protected  java.util.Map<M,TreeModel> modelMap
           
protected  BaseTreeModel rootWrapper
           
protected  java.util.Map<java.lang.String,M> wrapperMap
           
 
Fields inherited from class com.extjs.gxt.ui.client.store.Store
Add, all, BeforeAdd, BeforeClear, BeforeDataChanged, BeforeRemove, BeforeSort, Clear, DataChanged, Filter, filterBeginsWith, filtered, filterProperty, filters, filtersEnabled, modified, recordMap, Remove, snapshot, Sort, sortInfo, storeSorter, Update
 
Constructor Summary
TreeStore()
          Creates a new tree store.
TreeStore(TreeLoader<M> loader)
          Creates a new tree store.
 
Method Summary
 void add(java.util.List<M> models, boolean addChildren)
          Adds the models to the root of the store and fires the Add event.
 void add(M item, boolean addChildren)
          Adds the items to the store and fires the Add event.
 void add(M parent, java.util.List<M> children, boolean addChildren)
          Adds the models to the given parent and fires the Add event.
 void add(M parent, M item, boolean addChildren)
          Adds the child to the parent and fires the Add event.
 void applyFilters(java.lang.String property)
          Applies the current filters to the store.
protected  void applySort(boolean supressEvent)
           
protected  void applySort(java.util.List<TreeModel> list)
           
 void clearFilters()
          Revert to a view of this store with no filtering applied.
protected  TreeStoreEvent<M> createStoreEvent()
           
protected  TreeModel findWrapper(M item)
           
 java.util.List<M> getAllItems()
          Returns all the stores items.
 M getChild(int index)
          Returns the root level child.
 M getChild(M parent, int index)
          Returns the child at the given index.
 int getChildCount()
          Returns the root level child count.
 int getChildCount(M parent)
          Returns the child count for the parent.
 java.util.List<M> getChildren(M parent)
          Returns the children of the parent.
 java.util.List<M> getChildren(M parent, boolean deep)
          Returns the children of the parent.
 int getDepth(M item)
          Returns the depth of the item.
 M getFirstChild(M parent)
          Returns the fist child of the parent.
 M getLastChild(M parent)
          Returns the last child of the parent.
 TreeLoader<M> getLoader()
          Returns the store's loader.
 TreeStoreModel getModelState(M model)
          Returns the parent-child relationships for the given model.
 M getNextSibling(M item)
          Returns the next sibling of the model.
 M getParent(M item)
          Returns the parent of the item.
 M getPreviousSibling(M item)
          Returns the item's previous sibling.
 java.util.List<M> getRootItems()
          Returns the root level items.
 SortInfo getSortState()
          Returns the current sort state of this store.
 boolean hasChildren(M parent)
          Returns true if the given parent model has any children.
 int indexOf(M item)
          Returns the item's index in it's parent including root level items.
 void insert(java.util.List<M> models, int index, boolean addChildren)
          Inserts the models into the store and fires the Add event.
 void insert(M item, int index, boolean addChildren)
          Adds the item to the store and fires the Add event.
 void insert(M parent, java.util.List<M> children, int index, boolean addChildren)
          Inserts the children to the parent and fires the Add event.
 void insert(M parent, M model, int index, boolean addChildren)
          Adds the child to the parent and fires the Add event.
protected  void onBeforeLoad(LoadEvent le)
           
protected  void onLoad(TreeLoadEvent le)
           
protected  void onLoadException(LoadEvent le)
           
protected  void onModelChange(ChangeEvent ce)
           
 void remove(M model)
          Removes the model from the store and fires the Remove event.
 void remove(M parent, M child)
          Removes the child from the parent and fires the Remove event.
 void removeAll()
          Remove all items from the store and fires the Clear event.
 void removeAll(M parent)
          Removes all the parent's children.
 void setSortInfo(SortInfo info)
          Sets the current sort info used when sorting items in the store.
 void setStoreSorter(StoreSorter<M> storeSorter)
          Sets the store's sorter.
 void sort(java.lang.String field, Style.SortDir sortDir)
          Sorts the store.
protected  void swapModelInstance(M oldModel, M newModel)
           
protected  java.util.List<M> unwrap(java.util.List<TreeModel> models)
           
protected  M unwrap(TreeModel wrapper)
           
protected  java.util.List<M> unwrapChildren(TreeModel parent)
           
protected  TreeModel wrap(M model)
           
 
Methods inherited from class com.extjs.gxt.ui.client.store.Store
addFilter, addStoreListener, afterCommit, afterEdit, afterReject, commitChanges, contains, equals, filter, filter, findModel, findModel, findModel, findModels, fireStoreEvent, getFilters, getKeyProvider, getModelComparer, getModels, getModifiedRecords, getRecord, getStoreSorter, hasRecord, isFiltered, isFiltered, isMonitorChanges, registerModel, rejectChanges, removeFilter, removeStoreListener, setKeyProvider, setModelComparer, setMonitorChanges, unregisterModel, update
 
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

loader

protected TreeLoader<M extends ModelData> loader

modelFastMap

protected java.util.Map<java.lang.String,TreeModel> modelFastMap

modelMap

protected java.util.Map<M extends ModelData,TreeModel> modelMap

rootWrapper

protected BaseTreeModel rootWrapper

wrapperMap

protected java.util.Map<java.lang.String,M extends ModelData> wrapperMap
Constructor Detail

TreeStore

public TreeStore()
Creates a new tree store.


TreeStore

public TreeStore(TreeLoader<M> loader)
Creates a new tree store.

Parameters:
loader - the tree loader
Method Detail

add

public void add(java.util.List<M> models,
                boolean addChildren)
Adds the models to the root of the store and fires the Add event.

Parameters:
models - the models to be added
addChildren - true to recursively add all children

add

public void add(M item,
                boolean addChildren)
Adds the items to the store and fires the Add event.

Parameters:
item - the item to add
addChildren - true to recursively add all children

add

public void add(M parent,
                java.util.List<M> children,
                boolean addChildren)
Adds the models to the given parent and fires the Add event.

Parameters:
parent - the parent
children - the children
addChildren - true to recursively add all children

add

public void add(M parent,
                M item,
                boolean addChildren)
Adds the child to the parent and fires the Add event.

Parameters:
parent - the parent item
item - the child item
addChildren - true to recursively add all children

applyFilters

public void applyFilters(java.lang.String property)
Description copied from class: Store
Applies the current filters to the store.

Overrides:
applyFilters in class Store<M extends ModelData>
Parameters:
property - the optional active property

clearFilters

public void clearFilters()
Description copied from class: Store
Revert to a view of this store with no filtering applied.

Overrides:
clearFilters in class Store<M extends ModelData>

getAllItems

public java.util.List<M> getAllItems()
Returns all the stores items. The items are not returned in any order.

Returns:
the items

getChild

public M getChild(int index)
Returns the root level child.

Parameters:
index - the index
Returns:
the child

getChild

public M getChild(M parent,
                  int index)
Returns the child at the given index.

Parameters:
parent - the parent model or null if parent is root
index - the index
Returns:
the child of the parent at the given index

getChildCount

public int getChildCount()
Returns the root level child count.

Returns:
the child count

getChildCount

public int getChildCount(M parent)
Returns the child count for the parent.

Parameters:
parent - the parent
Returns:
the child count or -1 if parent not found in the store

getChildren

public java.util.List<M> getChildren(M parent)
Returns the children of the parent.

Parameters:
parent - the parent
Returns:
the children or null if parent not found in the store

getChildren

public java.util.List<M> getChildren(M parent,
                                     boolean deep)
Returns the children of the parent.

Parameters:
parent - the parent
deep - true to return all children recursively
Returns:
the children or null if parent not found in the store

getDepth

public int getDepth(M item)
Returns the depth of the item.

Parameters:
item - the item
Returns:
the item's depth

getFirstChild

public M getFirstChild(M parent)
Returns the fist child of the parent.

Parameters:
parent - the parent
Returns:
the first child or null if no children

getLastChild

public M getLastChild(M parent)
Returns the last child of the parent.

Parameters:
parent - the parent
Returns:
the last child of null if no children

getLoader

public TreeLoader<M> getLoader()
Returns the store's loader.

Returns:
the loader

getModelState

public TreeStoreModel getModelState(M model)
Returns the parent-child relationships for the given model. The actual model can be retrieved in each TreeModel's "model" property using the TreeStoreModel.getModel() method. The children of each tree model contains tree model instances which wrap the actual child model.

Parameters:
model - the model
Returns:
the model and it's children

getNextSibling

public M getNextSibling(M item)
Returns the next sibling of the model.

Parameters:
item - the model
Returns:
the next sibling or null

getParent

public M getParent(M item)
Returns the parent of the item.

Parameters:
item - the item
Returns:
the item's parent

getPreviousSibling

public M getPreviousSibling(M item)
Returns the item's previous sibling.

Parameters:
item - the item
Returns:
the previous sibling

getRootItems

public java.util.List<M> getRootItems()
Returns the root level items.

Returns:
the items

getSortState

public SortInfo getSortState()
Returns the current sort state of this store.

Returns:
the sort state

hasChildren

public boolean hasChildren(M parent)
Returns true if the given parent model has any children.

Parameters:
parent - the parent model
Returns:
true if the given parent model has any children

indexOf

public int indexOf(M item)
Returns the item's index in it's parent including root level items.

Parameters:
item - the item
Returns:
the index

insert

public void insert(java.util.List<M> models,
                   int index,
                   boolean addChildren)
Inserts the models into the store and fires the Add event.

Parameters:
models - the models to insert
index - the insert index
addChildren - true to recursively add all children

insert

public void insert(M item,
                   int index,
                   boolean addChildren)
Adds the item to the store and fires the Add event.

Parameters:
item - the item to insert
index - the insert index
addChildren - true to recursively add all children

insert

public void insert(M parent,
                   java.util.List<M> children,
                   int index,
                   boolean addChildren)
Inserts the children to the parent and fires the Add event.

Parameters:
parent - the parent
children - the children
index - the insert index
addChildren - true to recursively add all children

insert

public void insert(M parent,
                   M model,
                   int index,
                   boolean addChildren)
Adds the child to the parent and fires the Add event.

Parameters:
parent - the parent model
model - the child model
index - the insert index
addChildren - true to recursively add all children

remove

public void remove(M model)
Removes the model from the store and fires the Remove event. Works with both regular and root nodes.

Parameters:
model - the item to be removed

remove

public void remove(M parent,
                   M child)
Removes the child from the parent and fires the Remove event.

Parameters:
parent - the parent model
child - the child model

removeAll

public void removeAll()
Description copied from class: Store
Remove all items from the store and fires the Clear event.

Overrides:
removeAll in class Store<M extends ModelData>

removeAll

public void removeAll(M parent)
Removes all the parent's children.

Parameters:
parent - the parent

setSortInfo

public void setSortInfo(SortInfo info)
Sets the current sort info used when sorting items in the store.

Parameters:
info - the sort info

setStoreSorter

public void setStoreSorter(StoreSorter<M> storeSorter)
Description copied from class: Store
Sets the store's sorter.

Overrides:
setStoreSorter in class Store<M extends ModelData>
Parameters:
storeSorter - the sorter

sort

public void sort(java.lang.String field,
                 Style.SortDir sortDir)
Sorts the store.

Parameters:
field - the field to sort by
sortDir - the sort dir

applySort

protected void applySort(boolean supressEvent)
Overrides:
applySort in class Store<M extends ModelData>

applySort

protected void applySort(java.util.List<TreeModel> list)

createStoreEvent

protected TreeStoreEvent<M> createStoreEvent()
Overrides:
createStoreEvent in class Store<M extends ModelData>

findWrapper

protected TreeModel findWrapper(M item)

onBeforeLoad

protected void onBeforeLoad(LoadEvent le)

onLoad

protected void onLoad(TreeLoadEvent le)

onLoadException

protected void onLoadException(LoadEvent le)

onModelChange

protected void onModelChange(ChangeEvent ce)
Overrides:
onModelChange in class Store<M extends ModelData>

swapModelInstance

protected void swapModelInstance(M oldModel,
                                 M newModel)
Overrides:
swapModelInstance in class Store<M extends ModelData>

unwrap

protected java.util.List<M> unwrap(java.util.List<TreeModel> models)

unwrap

protected M unwrap(TreeModel wrapper)

unwrapChildren

protected java.util.List<M> unwrapChildren(TreeModel parent)

wrap

protected TreeModel wrap(M model)