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

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

A Store for hierarchical data. Parent-Child relationships are tracked internally, and can be accessed through the getParent(Object) and getChildren(Object) calls, and modified through the many add() overrides or the remove(Object) method. As with ListStore, all changes and data are relative to what is currently visible, due to the Store.StoreFilters. As such, if filters are active and structural changes are required, it might be necessary to disable filters to make the change, re-enabling them when finished.


Nested Class Summary
static interface TreeStore.TreeNode<T>
          Simple interface to allow data to be imported/exported from a TreeStore, complete with the structure of the tree.
 
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
TreeStore(ModelKeyProvider<? super M> keyProvider)
          Creates a tree store with the given key provider.
 
Method Summary
 void add(java.util.List<M> rootNodes)
          Adds the data models as roots of the tree.
 void add(M root)
          Adds the given data model as a root of the tree.
 void add(M parent, java.util.List<M> children)
          Adds the list of children to the end of the visible children of the given parent model
 void add(M parent, M child)
          Adds the child to the end of the visible children of the parent model
 void addSubTree(int index, java.util.List<? extends TreeStore.TreeNode<M>> children)
          Imports a list of subtrees at the given position in the root of the tree.
 void addSubTree(M parent, int index, java.util.List<? extends TreeStore.TreeNode<M>> children)
          Imports a list of subtrees to append to the given parent object already present in the tree.
 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(java.lang.String key)
          Finds the model with the given key, using ModelKeyProvider as necessary.
 java.util.List<M> getAll()
          Gets all visible items in the tree
 java.util.List<M> getAllChildren(M parent)
          Recursively builds a list of all of the visible elements below the given one in the tree
 int getAllItemsCount()
          Gets the total count of all visible items in the tree
 M getChild(int index)
          Returns the root level child.
 int getChildCount(M parent)
          Gets the number of visible children in the given node
 java.util.List<M> getChildren(M parent)
          Gets the list of visible children attached to the given element
 int getDepth(M child)
          Gets the depth of the given element in the tree, where 1 indicates that it is a root element of the tree.
 M getFirstChild(M parent)
          Returns the fist child of the parent.
 M getLastChild(M parent)
          Returns the last child of the parent.
 M getNextSibling(M item)
          Returns the next sibling of the model.
 M getParent(M child)
          Returns the parent of the given child.
 M getPreviousSibling(M item)
          Returns the item's previous sibling.
 int getRootCount()
          Gets the number of items at the root of the tree, that is, the number of visible items that have been added without specifying a parent.
 java.util.List<M> getRootItems()
          Gets the visible items at the root of the tree.
 TreeStore.TreeNode<M> getSubTree(M parent)
          Gets the full subtree model from the given parent node.
 boolean hasChildren(M item)
          Returns true if the given node has visible children
 int indexOf(M item)
          Returns the item's index in it's parent including root level items.
 void insert(int index, java.util.List<M> rootNodes)
          Inserts the given models at the given index in the list of root nodes
 void insert(int index, M root)
          Inserts the given model at the given index in the list of root nodes
 void insert(M parent, int index, java.util.List<M> children)
          Inserts the child models at the given position in the parent's list of visible children.
 void insert(M parent, int index, M child)
          Inserts the child model at the given position in the parent's list of visible children
 boolean remove(M model)
          Removes the given model from the store.
 void removeChildren(M parent)
          Removed the children of the given model from the store.
 void replaceChildren(M parent, java.util.List<M> children)
          Replaces the children of the given parent with a list of new child models.
 void replaceSubTree(M parent, java.util.List<? extends TreeStore.TreeNode<M>> children)
          Replaces the children of the given parent with a list of subtrees.
 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

TreeStore

public TreeStore(ModelKeyProvider<? super M> keyProvider)
Creates a tree 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
Method Detail

add

public void add(java.util.List<M> rootNodes)
Adds the data models as roots of the tree.

Parameters:
rootNodes - the items to add

add

public void add(M root)
Adds the given data model as a root of the tree.

Parameters:
root - the data model to add as a root

add

public void add(M parent,
                java.util.List<M> children)
Adds the list of children to the end of the visible children of the given parent model

Parameters:
parent - the parent item
children - the items to insert

add

public void add(M parent,
                M child)
Adds the child to the end of the visible children of the parent model

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

addSubTree

public void addSubTree(int index,
                       java.util.List<? extends TreeStore.TreeNode<M>> children)
Imports a list of subtrees at the given position in the root of the tree.

Parameters:
index - the insert location of the new subtree
children - the list of subtrees

addSubTree

public void addSubTree(M parent,
                       int index,
                       java.util.List<? extends TreeStore.TreeNode<M>> children)
Imports a list of subtrees to append to the given parent object already present in the tree.

Parameters:
parent - the parent data model
index - the child index
children - the list of subtrees

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(java.lang.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

getAll

public java.util.List<M> getAll()
Gets all visible items in the tree

Specified by:
getAll in class Store<M>
Returns:
all visible items in the tree

getAllChildren

public java.util.List<M> getAllChildren(M parent)
Recursively builds a list of all of the visible elements below the given one in the tree

Parameters:
parent - the parent data model
Returns:
list of all of the visible elements

getAllItemsCount

public int getAllItemsCount()
Gets the total count of all visible items in the tree

Returns:
count of all visible items

getChild

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

Parameters:
index - the index
Returns:
the child

getChildCount

public int getChildCount(M parent)
Gets the number of visible children in the given node

Parameters:
parent - the parent of the children
Returns:
number of visible children

getChildren

public java.util.List<M> getChildren(M parent)
Gets the list of visible children attached to the given element

Parameters:
parent - given element
Returns:
list of visible children

getDepth

public int getDepth(M child)
Gets the depth of the given element in the tree, where 1 indicates that it is a root element of the tree.

Parameters:
child - given element
Returns:
depth of the given element

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

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 child)
Returns the parent of the given child.

Parameters:
child - the given child
Returns:
parent of the given child

getPreviousSibling

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

Parameters:
item - the item
Returns:
the previous sibling

getRootCount

public int getRootCount()
Gets the number of items at the root of the tree, that is, the number of visible items that have been added without specifying a parent.

Returns:
number of items at the root of the tree

getRootItems

public java.util.List<M> getRootItems()
Gets the visible items at the root of the tree.

Returns:
visible items at the root of the tree

getSubTree

public TreeStore.TreeNode<M> getSubTree(M parent)
Gets the full subtree model from the given parent node. Note that this model will be modified if the store changes, and the children lists are immutable except by going through the TreeStore.

Parameters:
parent - the model data representing the parent of the subtree
Returns:
the tree node representing the parent of the subtree

hasChildren

public boolean hasChildren(M item)
Returns true if the given node has visible children

Parameters:
item - given node
Returns:
true if the given node has visible 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(int index,
                   java.util.List<M> rootNodes)
Inserts the given models at the given index in the list of root nodes

Parameters:
index - the insert index
rootNodes - the items to insert

insert

public void insert(int index,
                   M root)
Inserts the given model at the given index in the list of root nodes

Parameters:
index - the insert index
root - the root item

insert

public void insert(M parent,
                   int index,
                   java.util.List<M> children)
Inserts the child models at the given position in the parent's list of visible children.

Parameters:
parent - the parent item
index - the insert index
children - the items to insert

insert

public void insert(M parent,
                   int index,
                   M child)
Inserts the child model at the given position in the parent's list of visible children

Parameters:
parent - the parent item
index - the insert index
child - the child item

remove

public boolean remove(M model)
Removes the given model from the store. Only fires the StoreRemoveEvent if the element was visible.

Parameters:
model - the data model to remove
Returns:
boolean, indicating if it was removed from the Store. Subclasses should modify this to return false if necessary

removeChildren

public void removeChildren(M parent)
Removed the children of the given model from the store. Only fires StoreRemoveEvent for the models which were visible

Parameters:
parent - the parent of the children to remove

replaceChildren

public void replaceChildren(M parent,
                            java.util.List<M> children)
Replaces the children of the given parent with a list of new child models.

Parameters:
parent - the parent data model
children - the list of child models

replaceSubTree

public void replaceSubTree(M parent,
                           java.util.List<? extends TreeStore.TreeNode<M>> children)
Replaces the children of the given parent with a list of subtrees.

Parameters:
parent - the parent data model
children - the list of subtrees

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.