M
- the model typepublic class TreeStore<M> extends Store<M>
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.StoreFilter
s. 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.Modifier and Type | Class and Description |
---|---|
static interface |
TreeStore.TreeNode<T>
Simple interface to allow data to be imported/exported from a TreeStore,
complete with the structure of the tree.
|
Store.Change<M,V>, Store.PropertyChange<M,V>, Store.Record, Store.StoreFilter<M>, Store.StoreSortInfo<M>
Constructor and Description |
---|
TreeStore(ModelKeyProvider<? super M> keyProvider)
Creates a tree store with the given key provider.
|
Modifier and Type | Method and Description |
---|---|
void |
add(List<? extends 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,
List<? extends 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,
List<? extends TreeStore.TreeNode<? extends M>> children)
Imports a list of subtrees at the given position in the root of the tree.
|
void |
addSubTree(M parent,
int index,
List<? extends TreeStore.TreeNode<? extends M>> children)
Imports a list of subtrees to append to the given parent object already
present in the tree.
|
protected void |
applyFilters()
Sets the filters to run again, whether they need it or not.
|
void |
applySort(boolean suppressEvent)
Tells the store to re-apply sort settings and to fire an event when
complete.
|
protected Comparator<com.sencha.gxt.data.shared.TreeStore.TreeModel> |
buildWrappedFullComparator() |
void |
clear()
Removes all items from the store.
|
protected List<com.sencha.gxt.data.shared.TreeStore.TreeModel> |
convertTreeNodes(List<? extends TreeStore.TreeNode<? extends M>> children)
Helper function to prepare a foreign set of nodes to be imported into this
TreeStore instance.
|
M |
findModelWithKey(String key)
Finds the model with the given key, using
ModelKeyProvider as
necessary. |
List<M> |
getAll()
Gets all visible items in the tree
|
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
|
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.
|
protected Map<String,com.sencha.gxt.data.shared.TreeStore.TreeModel> |
getModelMap() |
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.
|
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.
|
protected com.sencha.gxt.data.shared.TreeStore.TreeModel |
getWrapper(M data)
Gets the existing wrapper for the given data model.
|
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,
List<? extends 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,
List<? extends 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,
List<? extends M> children)
Replaces the children of the given parent with a list of new child models.
|
void |
replaceSubTree(M parent,
List<? extends TreeStore.TreeNode<? extends M>> children)
Replaces the children of the given parent with a list of subtrees.
|
protected List<M> |
unwrap(List<com.sencha.gxt.data.shared.TreeStore.TreeModel> models)
Gets the data models represented by the given TreeModels
|
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. |
protected List<com.sencha.gxt.data.shared.TreeStore.TreeModel> |
wrap(List<? extends M> data)
Creates a List of wrappers for the given models.
|
protected com.sencha.gxt.data.shared.TreeStore.TreeModel |
wrap(M data)
Creates a new wrapper for the given data model.
|
addFilter, addSortInfo, addSortInfo, addStoreAddHandler, addStoreClearHandler, addStoreDataChangeHandler, addStoreFilterHandler, addStoreHandlers, addStoreRecordChangeHandler, addStoreRemoveHandler, addStoreSortHandler, addStoreUpdateHandler, buildFullComparator, clearSortInfo, commitChanges, ensureHandlers, findModel, fireEvent, getFilters, getKeyProvider, getModifiedRecords, getRecord, getSortInfo, hasMatchingKey, hasRecord, isAutoCommit, isEnableFilters, isFiltered, isSorted, rejectChanges, removeFilter, removeFilters, setAutoCommit, setEnableFilters, wrapRecordValueProvider
public TreeStore(ModelKeyProvider<? super M> keyProvider)
keyProvider
- the key providerpublic void add(List<? extends M> rootNodes)
rootNodes
- the items to addpublic void add(M root)
root
- the data model to add as a rootpublic void add(M parent, List<? extends M> children)
parent
- the parent itemchildren
- the items to insertpublic void add(M parent, M child)
parent
- the parent data modelchild
- the child data modelpublic void addSubTree(int index, List<? extends TreeStore.TreeNode<? extends M>> children)
index
- the insert location of the new subtreechildren
- the list of subtreespublic void addSubTree(M parent, int index, List<? extends TreeStore.TreeNode<? extends M>> children)
parent
- the parent data modelindex
- the child indexchildren
- the list of subtreespublic void applySort(boolean suppressEvent)
Store
Store.addSortInfo(StoreSortInfo)
,
Store.addSortInfo(int, StoreSortInfo)
, and Store.clearSortInfo()
.public void clear()
Store
public M findModelWithKey(String key)
Store
ModelKeyProvider
as
necessary.findModelWithKey
in class Store<M>
key
- the key of the model to findpublic List<M> getAllChildren(M parent)
parent
- the parent data modelpublic int getAllItemsCount()
public M getChild(int index)
index
- the indexpublic int getChildCount(M parent)
parent
- the parent of the childrenpublic List<M> getChildren(M parent)
parent
- given elementpublic int getDepth(M child)
child
- given elementpublic M getFirstChild(M parent)
parent
- the parentpublic M getLastChild(M parent)
parent
- the parentpublic M getNextSibling(M item)
item
- the modelpublic M getParent(M child)
child
- the given childpublic M getPreviousSibling(M item)
item
- the itempublic int getRootCount()
public List<M> getRootItems()
public TreeStore.TreeNode<M> getSubTree(M parent)
parent
- the model data representing the parent of the subtreepublic boolean hasChildren(M item)
item
- given nodepublic int indexOf(M item)
item
- the itempublic void insert(int index, List<? extends M> rootNodes)
index
- the insert indexrootNodes
- the items to insertpublic void insert(int index, M root)
index
- the insert indexroot
- the root itempublic void insert(M parent, int index, List<? extends M> children)
parent
- the parent itemindex
- the insert indexchildren
- the items to insertpublic void insert(M parent, int index, M child)
parent
- the parent itemindex
- the insert indexchild
- the child itempublic boolean remove(M model)
StoreRemoveEvent
if the element was visible.public void removeChildren(M parent)
StoreRemoveEvent
for the models which were visibleparent
- the parent of the children to removepublic void replaceChildren(M parent, List<? extends M> children)
parent
- the parent data modelchildren
- the list of child modelspublic void replaceSubTree(M parent, List<? extends TreeStore.TreeNode<? extends M>> children)
parent
- the parent data modelchildren
- the list of subtreespublic void update(M item)
Store
StoreUpdateEvent
to indicate that
this change has occurred. Any changes to the previous model via it's record instance will be lost and the record
will be removed.
This will not cause the sort or filter to be re-applied to the object.protected void applyFilters()
Store
applyFilters
in class Store<M>
protected Comparator<com.sencha.gxt.data.shared.TreeStore.TreeModel> buildWrappedFullComparator()
protected List<com.sencha.gxt.data.shared.TreeStore.TreeModel> convertTreeNodes(List<? extends TreeStore.TreeNode<? extends M>> children)
children
- the foreign nodes to prepareprotected com.sencha.gxt.data.shared.TreeStore.TreeModel getWrapper(M data)
ModelKeyProvider.getKey(Object)
.data
- the existing data model to look upprotected List<M> unwrap(List<com.sencha.gxt.data.shared.TreeStore.TreeModel> models)
models
- the modelprotected List<com.sencha.gxt.data.shared.TreeStore.TreeModel> wrap(List<? extends M> data)
wrap(Object)
, these must not already be part of the tree.data
- the dataprotected com.sencha.gxt.data.shared.TreeStore.TreeModel wrap(M data)
getWrapper(Object)
in that case.data
- the data model to wrapCopyright © 2018. All rights reserved.