|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.smartgwt.client.core.BaseClass
com.smartgwt.client.widgets.tree.Tree
public class Tree
A Tree is a data model representing a set of objects linked into a hierarchy.
A Tree has no visual presentation, it
is displayed by a TreeGrid
or ColumnTree
when supplied as data
or data
.
A Tree can be constructed out of a List
of objects interlinked by IDs or via explicitly specified Arrays of child objects. See modelType
for an explanation of how to pass data to a Tree.
Typical usage is to call TreeGrid.fetchData()
to cause automatic creation of a
com.smartgwt.client..ResultTree
, which is a type of Tree that automatically handles loading data on demand.
For information on DataBinding Trees, see TreeDataBinding
.
Field Summary |
---|
Fields inherited from class com.smartgwt.client.core.BaseClass |
---|
config, id, scClassName |
Constructor Summary | |
---|---|
Tree()
|
|
Tree(JavaScriptObject jsObj)
|
Method Summary | |
---|---|
TreeNode |
add(TreeNode node,
String parentPath)
Add a single node under the specified parent |
TreeNode |
add(TreeNode node,
String parentPath,
int position)
|
TreeNode |
add(TreeNode node,
TreeNode parent)
Add a single node under the specified parent |
TreeNode |
add(TreeNode node,
TreeNode parent,
int position)
Add a single node under the specified parent |
HandlerRegistration |
addDataChangedHandler(DataChangedHandler handler)
Add a dataChanged handler. |
TreeNode[] |
addList(TreeNode[] nodeList,
String parentPath)
Add a list of nodes to some parent. |
TreeNode[] |
addList(TreeNode[] nodeList,
String parentPath,
int position)
Add a list of nodes to some parent. |
TreeNode[] |
addList(TreeNode[] nodeList,
TreeNode parent)
Add a list of nodes to some parent. |
TreeNode[] |
addList(TreeNode[] nodeList,
TreeNode parent,
int position)
Add a list of nodes to some parent. |
void |
closeAll()
Close all nodes under a particular node |
void |
closeAll(TreeNode node)
Close all nodes under a particular node |
void |
closeFolder(TreeNode node)
Closes a folder |
void |
closeFolders(TreeNode[] nodeList)
Close a set of folders, specified by path or as pointers to nodes. |
JavaScriptObject |
create()
|
TreeNode |
find(String fieldNameOrPath)
Find a node within this tree using a string path or by attribute value(s). |
TreeNode |
find(String fieldNameOrPath,
Object value)
Find a node within this tree using a string path or by attribute value(s). |
TreeNode |
findById(String id)
Find the node with the specified ID. |
TreeNode[] |
getAllNodes()
Get all the nodes that exist in the tree under a particular node, as a flat list, in depth-first traversal order. |
TreeNode |
getAllNodes(TreeNode node)
Get all the nodes that exist in the tree under a particular node, as a flat list, in depth-first traversal order. |
Boolean |
getAutoOpenRoot()
If true, the root node is automatically opened when the tree is created or setRoot(com.smartgwt.client.widgets.tree.TreeNode) is called. |
TreeNode[] |
getChildren(TreeNode node)
Returns all children of a node. |
String |
getChildrenProperty()
For trees with the modelType "children", this property specifies the name of the property that contains the list of children for a node. |
ListGridRecord[] |
getData()
|
Boolean |
getDefaultIsFolder()
Controls whether nodes are assumed to be folders or leaves by default. |
String |
getDefaultNodeTitle()
Title assigned to nodes without a titleProperty value or
a nameProperty value. |
TreeNode[] |
getDescendantFolders()
Ruturns the list of all descendants of a node that are folders. |
TreeNode[] |
getDescendantFolders(TreeNode node)
Ruturns the list of all descendants of a node that are folders. |
TreeNode[] |
getDescendantLeaves()
Returns the list of all descendants of a node that are leaves. |
TreeNode[] |
getDescendantLeaves(TreeNode node)
Returns the list of all descendants of a node that are leaves. |
TreeNode[] |
getDescendants()
Returns the list of all descendants of a node. |
TreeNode[] |
getDescendants(TreeNode node)
Returns the list of all descendants of a node. |
Boolean |
getDiscardParentlessNodes()
If this tree has 'modelType:"parent"' , should nodes in the
data array for the tree be dropped if they have an explicitly specified value for the parentIdField which doesn't match any other nodes in the tree. |
TreeNode[] |
getFolders(TreeNode node)
Returns all the first-level folders of a node. |
String |
getIdField()
Name of the property on a TreeNode that holds an id for the node which is
unique across the entire Tree. |
String |
getIsFolderProperty()
Name of property that defines whether a node is a folder. |
TreeNode[] |
getLeaves(TreeNode node)
Return all the first-level leaves of a node. |
int |
getLength()
Returns the number of items in the current open list. |
int |
getLevel(TreeNode node)
Return the number of levels deep this node is in the tree. |
TreeModelType |
getModelType()
Selects the model used to construct the tree representation. |
String |
getName(TreeNode node)
Get the 'name' of a node. |
String |
getNameProperty()
Name of the property on a TreeNode that holds a name for the node that is
unique among it's immediate siblings, thus allowing a unique path to be used to identify the node, similar to a file
system. |
TreeNode[] |
getOpenList(TreeNode node)
Return a flattened list of nodes that are open under some parent, including the parent itself. |
String |
getOpenProperty()
The property consulted by the default implementation of isOpen(com.smartgwt.client.widgets.tree.TreeNode) to
determine if the node is open or not. |
static Tree |
getOrCreateRef(JavaScriptObject jsObj)
|
TreeNode |
getParent(TreeNode node)
Returns the parent of this node. |
String |
getParentIdField()
For trees with modelType "parent", this property specifies the name of the property that contains the unique parent ID of a node. |
String |
getParentPath(TreeNode node)
Given a node, return the path to it's parent. |
TreeNode[] |
getParents(TreeNode node)
Given a node, return an array of the node's parents with the immediate parent first. |
String |
getPath(TreeNode node)
Returns the path of a node - a path has the following format: ([name][pathDelim]?)*
For example, in this tree: |
String |
getPathDelim()
Specifies the delimiter between node names. |
Boolean |
getReportCollisions()
If new nodes are added to a tree with modelType:"parent" which have the same 'id field value' as existing nodes, the existing nodess are removed
when the new nodes are added. |
TreeNode |
getRoot()
If you're using the "parent" modelType, you can provide the root node configuration via this property. |
String |
getRootValue()
|
Boolean |
getShowRoot()
Controls whether a call to getOpenList(com.smartgwt.client.widgets.tree.TreeNode) includes the root node. |
String |
getTitle(TreeNode node)
Return the title of a node -- the name as it should be presented to the user. |
String |
getTitleProperty()
Name of the property on a TreeNode that holds the title of the node as it
should be shown to the user. |
Boolean |
hasChildren(TreeNode node)
Returns true if this node has any children. |
Boolean |
hasFolders(TreeNode node)
Return true if this this node has any children that are folders. |
Boolean |
hasLeaves(TreeNode node)
Return whether this node has any children that are leaves. |
Boolean |
isDescendantOf(TreeNode child,
TreeNode parent)
Is one node a descendant of the other? |
Boolean |
isFolder(TreeNode node)
Determines whether a particular node is a folder. |
Boolean |
isLeaf(TreeNode node)
Returns true if the passed in node is a leaf. |
Boolean |
isOpen(TreeNode node)
Whether a particular node is open or closed (works for leaves and folders). |
Boolean |
isRoot(TreeNode node)
Return true if the passed node is the root node. |
void |
linkNodes(TreeNode[] nodes)
This method is provided as a mechanism to link new nodes into the tree of modelType "parent". |
void |
loadChildren(TreeNode node)
Load the children of a given node. This implementation does nothing other than mark the node as loaded |
void |
move(TreeNode node,
TreeNode newParent)
Moves the specified node to a new parent. |
void |
move(TreeNode node,
TreeNode newParent,
int position)
Moves the specified node to a new parent. |
static TreeNode |
nodeForRecord(ListGridRecord record)
A TreeNode and ListGridRecord represent similar datastructures and it is possible that certain TreeGrid operations return a ListGridRecord since TreeGrid extends ListGrid. |
void |
openAll()
Open all nodes under a particular node. |
void |
openAll(TreeNode node)
Open all nodes under a particular node. |
void |
openFolder(TreeNode node)
Open a particular node |
void |
openFolders(TreeNode[] nodeList)
Open a set of folders, specified by path or as pointers to nodes. |
void |
reloadChildren(TreeNode node)
Reload the children of a node |
Boolean |
remove(TreeNode node)
Removes a node, along with all its children. |
Boolean |
removeList(TreeNode[] nodeList)
Remove a list of nodes (not necessarily from the same parent), and all children of those nodes. |
void |
setAutoOpenRoot(Boolean autoOpenRoot)
If true, the root node is automatically opened when the tree is created or setRoot(com.smartgwt.client.widgets.tree.TreeNode) is called. |
void |
setChildrenProperty(String childrenProperty)
For trees with the modelType "children", this property specifies the name of the property that contains the list of children for a node. |
void |
setData(TreeNode[] nodes)
Optional initial data for the tree. |
void |
setDefaultIsFolder(Boolean defaultIsFolder)
Controls whether nodes are assumed to be folders or leaves by default. |
void |
setDefaultNodeTitle(String defaultNodeTitle)
Title assigned to nodes without a titleProperty value or
a nameProperty value. |
void |
setDiscardParentlessNodes(Boolean discardParentlessNodes)
If this tree has 'modelType:"parent"' , should nodes in the
data array for the tree be dropped if they have an explicitly specified value for the parentIdField which doesn't match any other nodes in the tree. |
void |
setIdField(String idField)
Name of the property on a TreeNode that holds an id for the node which is
unique across the entire Tree. |
void |
setIsFolderProperty(String isFolderProperty)
Name of property that defines whether a node is a folder. |
void |
setModelType(TreeModelType modelType)
Selects the model used to construct the tree representation. |
void |
setNameProperty(String nameProperty)
Name of the property on a TreeNode that holds a name for the node that is
unique among it's immediate siblings, thus allowing a unique path to be used to identify the node, similar to a file
system. |
void |
setOpenProperty(String openProperty)
The property consulted by the default implementation of isOpen(com.smartgwt.client.widgets.tree.TreeNode) to
determine if the node is open or not. |
void |
setParentIdField(String parentIdField)
For trees with modelType "parent", this property specifies the name of the property that contains the unique parent ID of a node. |
void |
setPathDelim(String pathDelim)
Specifies the delimiter between node names. |
void |
setReportCollisions(Boolean reportCollisions)
If new nodes are added to a tree with modelType:"parent" which have the same 'id field value' as existing nodes, the existing nodess are removed
when the new nodes are added. |
void |
setRoot(TreeNode root)
If you're using the "parent" modelType, you can provide the root node configuration via this property. |
void |
setRootValue(int rootValue)
If you are using the "parent" modelType and did not specify a root node via root with an id (idField ), then you can provide the root node's id via this property. |
void |
setRootValue(String rootValue)
If you are using the "parent" modelType and did not specify a root node via root with an id (idField ), then you can provide the root node's id via this property. |
void |
setShowRoot(Boolean showRoot)
Controls whether a call to getOpenList(com.smartgwt.client.widgets.tree.TreeNode) includes the root node. |
void |
setTitleProperty(String titleProperty)
Name of the property on a TreeNode that holds the title of the node as it
should be shown to the user. |
void |
unloadChildren(TreeNode node)
Unload the children of a node |
Methods inherited from class com.smartgwt.client.core.BaseClass |
---|
destroy, doAddHandler, error, error, errorIfNotCreated, fireEvent, getAttribute, getAttributeAsBoolean, getAttributeAsDate, getAttributeAsDouble, getAttributeAsElement, getAttributeAsFloat, getAttributeAsInt, getAttributeAsJavaScriptObject, getAttributeAsString, getConfig, getHandlerCount, getID, getJsObj, getOrCreateJsObj, getRef, isCreated, onInit, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setAttribute, setID, setProperty, setProperty, setProperty, setProperty |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.google.gwt.event.shared.HasHandlers |
---|
fireEvent |
Constructor Detail |
---|
public Tree()
public Tree(JavaScriptObject jsObj)
Method Detail |
---|
public static Tree getOrCreateRef(JavaScriptObject jsObj)
public JavaScriptObject create()
create
in class BaseClass
public void setModelType(TreeModelType modelType)
TreeModelType
for
the available options and their implications. If the "parent" modelType is used, you can provide the initial
parent-linked data set to the tree via the data
attribute. If the
"children" modelType is used, you can provide the initial tree structure to the Tree via the root
attribute.
Note : This is an advanced setting
modelType
- modelType Default value is "children"public TreeModelType getModelType()
TreeModelType
for
the available options and their implications. If the "parent" modelType is used, you can provide the initial
parent-linked data set to the tree via the data
attribute. If the
"children" modelType is used, you can provide the initial tree structure to the Tree via the root
attribute.
public void setIsFolderProperty(String isFolderProperty)
isFolder
.
isFolderProperty
- isFolderProperty Default value is "isFolder"public String getIsFolderProperty()
isFolder
.
public void setDefaultIsFolder(Boolean defaultIsFolder) throws IllegalStateException
Nodes that have children or have the isFolderProperty
set to true will be considered folders by
default. Other nodes will be considered folders or leaves by default according to this setting.
defaultIsFolder
- defaultIsFolder Default value is null
IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic Boolean getDefaultIsFolder()
Nodes that have children or have the isFolderProperty
set to true will be considered folders by
default. Other nodes will be considered folders or leaves by default according to this setting.
public void setReportCollisions(Boolean reportCollisions) throws IllegalStateException
'id field value'
as existing nodes, the existing nodess are removed
when the new nodes are added. If reportCollisions is true, the Tree will log a warning in the developer console about this.
Note that if an id collision occurs between a new node and its ancestor, the ancestor will be removed and the new node will not be added to the tree.
reportCollisions
- reportCollisions Default value is true
IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic Boolean getReportCollisions()
'id field value'
as existing nodes, the existing nodess are removed
when the new nodes are added. If reportCollisions is true, the Tree will log a warning in the developer console about this.
Note that if an id collision occurs between a new node and its ancestor, the ancestor will be removed and the new node will not be added to the tree.
public void setPathDelim(String pathDelim)
getPath(com.smartgwt.client.widgets.tree.TreeNode)
and can be used to
find any node in the tree by calling
find(java.lang.String)
. Note that you can also
hand-construct a path - in other words
you are not required to call getPath(com.smartgwt.client.widgets.tree.TreeNode)
in order to later use
find(java.lang.String)
to retrieve it.
nameProperty
that's used
for naming the nodes. So for
example, if you have the following tree:
one two three/fourThen you will be unable to find the
three/four
node using
find(java.lang.String)
if
your tree is using the default pathDelim of /.
In such a case, you can use a different pathDelim for the tree. For
example if you used |
for the path delim, then you can find the three/four
node in the tree above
by
calling tree.find("one|two|three/four")
.
getPath(com.smartgwt.client.widgets.tree.TreeNode)
and find(java.lang.String)
and
does not
affect any aspect of the tree structure or other forms of tree navigation (such as
via getChildren(com.smartgwt.client.widgets.tree.TreeNode)
).
Note : This is an advanced setting
pathDelim
- pathDelim Default value is "/"public String getPathDelim()
getPath(com.smartgwt.client.widgets.tree.TreeNode)
and can be used to
find any node in the tree by calling
find(java.lang.String)
. Note that you can also
hand-construct a path - in other words
you are not required to call getPath(com.smartgwt.client.widgets.tree.TreeNode)
in order to later use
find(java.lang.String)
to retrieve it.
nameProperty
that's used
for naming the nodes. So for
example, if you have the following tree:
one two three/fourThen you will be unable to find the
three/four
node using
find(java.lang.String)
if
your tree is using the default pathDelim of /.
In such a case, you can use a different pathDelim for the tree. For
example if you used |
for the path delim, then you can find the three/four
node in the tree above
by
calling tree.find("one|two|three/four")
.
getPath(com.smartgwt.client.widgets.tree.TreeNode)
and find(java.lang.String)
and
does not
affect any aspect of the tree structure or other forms of tree navigation (such as
via getChildren(com.smartgwt.client.widgets.tree.TreeNode)
).
public void setNameProperty(String nameProperty)
TreeNode
that holds a name for the node that is
unique among it's immediate siblings, thus allowing a unique path to be used to identify the node, similar to a file
system. Default value is "name". See name
for usage.
nameProperty
- nameProperty Default value is "name"public String getNameProperty()
TreeNode
that holds a name for the node that is
unique among it's immediate siblings, thus allowing a unique path to be used to identify the node, similar to a file
system. Default value is "name". See name
for usage.
public void setTitleProperty(String titleProperty)
TreeNode
that holds the title of the node as it
should be shown to the user. Default value is "title". See title
for usage.
titleProperty
- titleProperty Default value is "title"public String getTitleProperty()
TreeNode
that holds the title of the node as it
should be shown to the user. Default value is "title". See title
for usage.
public void setIdField(String idField) throws IllegalStateException
TreeNode
that holds an id for the node which is
unique across the entire Tree. Required for all nodes for trees with modelType "parent". Default value is "id". See
id
for usage.
Note : This is an advanced setting
idField
- idField Default value is "id"
IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic String getIdField()
TreeNode
that holds an id for the node which is
unique across the entire Tree. Required for all nodes for trees with modelType "parent". Default value is "id". See
id
for usage.
public void setParentIdField(String parentIdField) throws IllegalStateException
parentId
for
usage.
Note : This is an advanced setting
parentIdField
- parentIdField Default value is "parentId"
IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic String getParentIdField()
parentId
for
usage.
public void setChildrenProperty(String childrenProperty)
childrenProperty
- childrenProperty Default value is "children"public String getChildrenProperty()
public void setOpenProperty(String openProperty)
isOpen(com.smartgwt.client.widgets.tree.TreeNode)
to
determine if the node is open or not. By default, this property is auto-generated for you, but you can set it to a
custom value if you want to declaratively specify this state, but be careful - if you display this Tree in multiple
TreeGrids at the same time, the open state will not be tracked independently - see SharingNodes
for more info on this.
Note : This is an advanced setting
openProperty
- openProperty Default value is nullpublic String getOpenProperty()
isOpen(com.smartgwt.client.widgets.tree.TreeNode)
to
determine if the node is open or not. By default, this property is auto-generated for you, but you can set it to a
custom value if you want to declaratively specify this state, but be careful - if you display this Tree in multiple
TreeGrids at the same time, the open state will not be tracked independently - see SharingNodes
for more info on this.
public void setRoot(TreeNode root)
If you're using the "children" modelType, you can provide the initial tree data via this property. So, for example, to construct the following tree:
foo bar zooYou would initialize the tree as follows:
Tree.create({ root: { name:"root", children: [ { name:"foo", children: [ { name: "bar" } ]}, { name: "zoo" } ]} });Note that if you provide a
name
property for the root node, then the path to
any node underneath it will start with
that name. So in the example above, the path to the
bar
node would be root/foo/bar
(assuming you're using the default
pathDelim
. If you
omit the name attribute on the root node, then it's name
is automatically set to the pathDelim
value. So in the example above, if
you omitted
name:"root"
, then the path to the bar
node would be
/foo/bar
.
root
value, a root node will be
auto-created for
you. You can then call add(com.smartgwt.client.widgets.tree.TreeNode, com.smartgwt.client.widgets.tree.TreeNode)
to construct the tree.
Set the root node of the tree.
root
- new root node. Default value is nullpublic TreeNode getRoot()
If you're using the "children" modelType, you can provide the initial tree data via this property. So, for example, to construct the following tree:
foo bar zooYou would initialize the tree as follows:
Tree.create({ root: { name:"root", children: [ { name:"foo", children: [ { name: "bar" } ]}, { name: "zoo" } ]} });Note that if you provide a
name
property for the root node, then the path to
any node underneath it will start with
that name. So in the example above, the path to the
bar
node would be root/foo/bar
(assuming you're using the default
pathDelim
. If you
omit the name attribute on the root node, then it's name
is automatically set to the pathDelim
value. So in the example above, if
you omitted
name:"root"
, then the path to the bar
node would be
/foo/bar
.
root
value, a root node will be
auto-created for
you. You can then call add(com.smartgwt.client.widgets.tree.TreeNode, com.smartgwt.client.widgets.tree.TreeNode)
to construct the tree.
public void setDiscardParentlessNodes(Boolean discardParentlessNodes) throws IllegalStateException
'modelType:"parent"'
, should nodes in the
data array for the tree be dropped if they have an explicitly specified value for the parentIdField
which doesn't match any other nodes in the tree.
If set to false these nodes will be added as children of the root node.
Note : This is an advanced setting
discardParentlessNodes
- discardParentlessNodes Default value is false
IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic Boolean getDiscardParentlessNodes()
'modelType:"parent"'
, should nodes in the
data array for the tree be dropped if they have an explicitly specified value for the parentIdField
which doesn't match any other nodes in the tree.
If set to false these nodes will be added as children of the root node.
public void setShowRoot(Boolean showRoot)
getOpenList(com.smartgwt.client.widgets.tree.TreeNode)
includes the root node. Since view
components such as TreeGrid
use getOpenList()
to display the
currently visible tree, showRoot
controls whether the root node is shown to the user. All Trees must
have a single, logical root, however, most applications want to show multiple nodes at the top level.
showRoot:false
, the default setting, prevents the logical root from being shown, so that the displayed tree
begins with the children of root.
You can set showRoot:true
to show the single, logical root node as
the only top-level node. This property is only meaningful for Trees where you supplied a value for root
, otherwise, you will see an automatically generated root node that
is meaningless to the user.
showRoot
- showRoot Default value is falsepublic Boolean getShowRoot()
getOpenList(com.smartgwt.client.widgets.tree.TreeNode)
includes the root node. Since view
components such as TreeGrid
use getOpenList()
to display the
currently visible tree, showRoot
controls whether the root node is shown to the user. All Trees must
have a single, logical root, however, most applications want to show multiple nodes at the top level.
showRoot:false
, the default setting, prevents the logical root from being shown, so that the displayed tree
begins with the children of root.
You can set showRoot:true
to show the single, logical root node as
the only top-level node. This property is only meaningful for Trees where you supplied a value for root
, otherwise, you will see an automatically generated root node that
is meaningless to the user.
public void setAutoOpenRoot(Boolean autoOpenRoot)
setRoot(com.smartgwt.client.widgets.tree.TreeNode)
is called.
autoOpenRoot
- autoOpenRoot Default value is truepublic Boolean getAutoOpenRoot()
setRoot(com.smartgwt.client.widgets.tree.TreeNode)
is called.
public void setDefaultNodeTitle(String defaultNodeTitle)
titleProperty
value or
a nameProperty
value.
defaultNodeTitle
- defaultNodeTitle Default value is "Untitled"public String getDefaultNodeTitle()
titleProperty
value or
a nameProperty
value.
public Boolean isRoot(TreeNode node)
node
- node to test
public String getName(TreeNode node)
nameProperty
]. If
that value has not been set on the node, a unique value (within this parent) will be auto-generated and returned.
node
- node in question
public String getTitle(TreeNode node)
titleProperty
is set on the node, the value of that
property is returned. nameProperty
is set on the node, that value is returned, minus any trailing pathDelim
. defaultNodeTitle
is returned. TreeGrid.getNodeTitle(com.smartgwt.client.data.Record, int, com.smartgwt.client.widgets.grid.ListGridField)
instead.
node
- node for which the title is being requested
public String getPath(TreeNode node)
([name][pathDelim]?)*
root foo barAssuming that
pathDelim
is the default /
, the
bar
node would have the path root/foo/bar
and the path for the foo
node
would be root/foo
.
node
- node in question
public String getParentPath(TreeNode node)
getPath(com.smartgwt.client.widgets.tree.TreeNode)
except the node itself is not reported as part of the path.
node
- node in question
public int getLevel(TreeNode node)
root foo barCalling
tree.getLevel(bar)
will return 2
.
node
- node in question
public Boolean isFolder(TreeNode node)
TreeNode
has a value for the isFolderProperty
(isFolder
by default) that value is returned. childrenProperty
(by default children
) is checked on the TreeNode
. If the node has the children property defined (regardless of whether it
actually has any children), then isFolder() returns true for that node. You can override this method to provide your own intepretation of what constitutes a folder.
node
- node in question
public Boolean isLeaf(TreeNode node)
node
- node in question
public Boolean hasChildren(TreeNode node)
node
- node in question
public Boolean hasFolders(TreeNode node)
node
- node in question
public Boolean hasLeaves(TreeNode node)
node
- node in question
public Boolean isDescendantOf(TreeNode child, TreeNode parent)
child
- child nodeparent
- parent node
public HandlerRegistration addDataChangedHandler(DataChangedHandler handler)
Called when the structure of this tree is changed in any way. Intended to be observed.
Note that on a big
change (many items being added or deleted) this may be called multiple times
addDataChangedHandler
in interface HasDataChangedHandlers
handler
- the dataChanged handler
HandlerRegistration
used to remove this handlerpublic void move(TreeNode node, TreeNode newParent)
node
- node to movenewParent
- new parent to move the node topublic void move(TreeNode node, TreeNode newParent, int position)
node
- node to movenewParent
- new parent to move the node toposition
- Position of the new node in the children list. If not specified, the node will be added
at the end of the list.public Boolean remove(TreeNode node)
node
- node to remove
public void unloadChildren(TreeNode node)
node
- node in questionpublic void reloadChildren(TreeNode node)
node
- node in questionpublic Boolean isOpen(TreeNode node)
node
- node in question
public void closeFolder(TreeNode node)
node
- folder to closepublic void openAll()
public void openAll(TreeNode node)
node
- node from which to open folders (if not specified, the root node is used)public void closeAll()
public void closeAll(TreeNode node)
node
- node from which to close folders (if not specified, the root node is used)public int getLength()
public void setData(TreeNode[] nodes)
modelType
. If modelType
is
"parent"
, the list that you provide will be passed to linkNodes(com.smartgwt.client.widgets.tree.TreeNode[])
,
integrating the nodes into the tree.
In this case the root node must be supplied separately via root
, or you may instead provide the id
of the root
node via rootValue
. So for example, to create this
tree:
foo bar zoowith modelType:"parent", you can do this:
Tree.create({ root: {id: "root"}, data: [ {name: "foo", id: "foo", parentId: "root"}, {name: "bar", id: "bar", parentId: "foo"}, {name: "zoo", id: "zoo", parentId: "root"} });Or this:
Tree.create({ rootValue: "root", data: [ {name: "foo", id: "foo", parentId: "root"}, {name: "bar", id: "bar", parentId: "foo"}, {name: "zoo", id: "zoo", parentId: "root"} });Specifying the root node explicitly allows you to give it a name, changing the way path derivation works (see
root
for more
on naming the root node). For modelType:"children"
trees, the data passed in will be assumed to
be an array of children the tree's root node.
data
- data Default value is null
IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic ListGridRecord[] getData()
public void setRootValue(String rootValue)
root
with an id (idField
), then you can provide the root node's id via this property. See the example in data
for more info.
rootValue
- rootValue Default value is null
IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic void setRootValue(int rootValue)
root
with an id (idField
), then you can provide the root node's id via this property. See the example in data
for more info.
rootValue
- rootValue Default value is null
IllegalStateException
- this property cannot be changed after the underlying component has been createdpublic String getRootValue()
public TreeNode getParent(TreeNode node)
node
- node in question
public void linkNodes(TreeNode[] nodes)
idField
) and a parent ID (keyed by parentIdField
). Based on this information, the list
of nodes is integrated into the tree structure.
nodes
- list of nodes to link into the tree.public TreeNode[] getParents(TreeNode node)
root foo barCalling
tree.getParents(bar)
would return: [foo, root]
. Note that the returned array will
contain references to the nodes, not the names.
node
- node in question
public TreeNode findById(String id)
id
- ID of the node to return.
public TreeNode find(String fieldNameOrPath)
com.smartgwt.client..List#find
). node[fieldName]
matches the second argument. So for example, given this tree: foo zoo bar moo barAssuming your
pathDelim
is the default /
and foo
is the name of the root node, then
tree.find("foo/moo/bar")
would return the bar
node under the moo
node.
tree.find("name", "bar")
would return the first bar
node because it is the
first one in the list whose name
(default value of nameProperty
) property matches the value bar
. The two argument usage is generally more
interesting when your tree nodes have some custom unique property that you wish to search on. For example if
your tree nodes had a unique field called "UID", their serialized form would look something like this: { name: "foo", children: [...], UID:"someUniqueId"}You could then call
tree.find("UID",
"someUniqueId")
to find that node. Note that the value doesn't have to be a string - it can be any
valid JS value, but since this data generally comes from the server, the typical types are string, number,
and boolean. tree.find({color: "green", shape: "circle"}) would return the first node in
the tree where both properties matched.
When searching by path, trailing path delimiters are
ignored. So for example tree.find("foo/zoo/bar")
is equivalent to
tree.find("foo/zoo/bar/")
- Parameters:
fieldNameOrPath
- Either the path to the node to be found, or the name of
a field which should match the value passed as a second
parameter
- Returns:
- the node matching the supplied criteria or null if not found
public TreeNode find(String fieldNameOrPath, Object value)
com.smartgwt.client..List#find
). node[fieldName]
matches the second argument. So for example, given this tree: foo zoo bar moo barAssuming your
pathDelim
is the default /
and foo
is the name of the root node, then
tree.find("foo/moo/bar")
would return the bar
node under the moo
node.
tree.find("name", "bar")
would return the first bar
node because it is the
first one in the list whose name
(default value of nameProperty
) property matches the value bar
. The two argument usage is generally more
interesting when your tree nodes have some custom unique property that you wish to search on. For example if
your tree nodes had a unique field called "UID", their serialized form would look something like this: { name: "foo", children: [...], UID:"someUniqueId"}You could then call
tree.find("UID",
"someUniqueId")
to find that node. Note that the value doesn't have to be a string - it can be any
valid JS value, but since this data generally comes from the server, the typical types are string, number,
and boolean. tree.find({color: "green", shape: "circle"}) would return the first node in
the tree where both properties matched.
When searching by path, trailing path delimiters are
ignored. So for example tree.find("foo/zoo/bar")
is equivalent to
tree.find("foo/zoo/bar/")
- Parameters:
fieldNameOrPath
- Either the path to the node to be found, or the name of
a field which should match the value passed as a second
parametervalue
- If specified, this is the desired value for the
appropriate field
- Returns:
- the node matching the supplied criteria or null if not found
public TreeNode[] getChildren(TreeNode node)
ResultSet
, so it's
${isc.DocUtils.linkForRef('interface:List')} interface instead of as a native Javascript Array.
node
- The node whose children you want to fetch.
public TreeNode[] getFolders(TreeNode node)
ResultSet
, so it's
${isc.DocUtils.linkForRef('interface:List')} interface instead of as a native Javascript Array.
node
- node in question
public TreeNode[] getLeaves(TreeNode node)
ResultSet
, so it's
${isc.DocUtils.linkForRef('interface:List')} interface instead of as a native Javascript Array.
node
- node in question
public TreeNode[] getDescendants()
find(java.lang.String)
in combination with getChildren(com.smartgwt.client.widgets.tree.TreeNode)
will be much faster. ResultSet
, so it's
to access the return value using the ${isc.DocUtils.linkForRef('interface:List')} interface instead of as a
native Javascript Array.
public TreeNode[] getDescendants(TreeNode node)
find(java.lang.String)
in combination with getChildren(com.smartgwt.client.widgets.tree.TreeNode)
will be much faster. ResultSet
, so it's
to access the return value using the ${isc.DocUtils.linkForRef('interface:List')} interface instead of as a
native Javascript Array.
node
- node in question (the root node is asumed if none specified)
public TreeNode[] getDescendantFolders()
getDescendants()
, except leaf nodes are not part of the returned list.
Like getDescendants()
, this method can be very slow for large
trees. Generally, find(java.lang.String)
in combination with getFolders(com.smartgwt.client.widgets.tree.TreeNode)
be much faster. ResultSet
, so it's
${isc.DocUtils.linkForRef('interface:List')} interface instead of as a native Javascript Array.
public TreeNode[] getDescendantFolders(TreeNode node)
getDescendants()
, except leaf nodes are not part of the returned list.
Like getDescendants()
, this method can be very slow for large
trees. Generally, find(java.lang.String)
in combination with getFolders(com.smartgwt.client.widgets.tree.TreeNode)
be much faster. ResultSet
, so it's
${isc.DocUtils.linkForRef('interface:List')} interface instead of as a native Javascript Array.
node
- node in question (the root node is assumed if none specified)
public TreeNode[] getDescendantLeaves()
getDescendants()
, except folders are not part of the returned list.
Folders are still recursed into, just not returned. Like getDescendants()
,
this method can be very slow for large trees. Generally, find(java.lang.String)
in combination with getLeaves(com.smartgwt.client.widgets.tree.TreeNode)
be much faster. ResultSet
, so it's
${isc.DocUtils.linkForRef('interface:List')} interface instead of as a native Javascript Array.
public TreeNode[] getDescendantLeaves(TreeNode node)
getDescendants()
, except folders are not part of the returned list.
Folders are still recursed into, just not returned. Like getDescendants()
,
this method can be very slow for large trees. Generally, find(java.lang.String)
in combination with getLeaves(com.smartgwt.client.widgets.tree.TreeNode)
be much faster. ResultSet
, so it's
${isc.DocUtils.linkForRef('interface:List')} interface instead of as a native Javascript Array.
node
- node in question (the root node is assumed if none specified)
public TreeNode add(TreeNode node, TreeNode parent)
node
- node to addparent
- Parent of the node being added. You can pass in
either the TreeNode
itself, or a path to
the node (as a String), in which case a
find(java.lang.String)
is performed to find
the node.
public TreeNode add(TreeNode node, String parentPath)
node
- node to addparentPath
- Parent of the node being added. You can pass in either the TreeNode
itself, or a path to the node (as a String), in which case a
find(java.lang.String)
is performed to find the node.
public TreeNode add(TreeNode node, TreeNode parent, int position)
node
- node to addparent
- Parent of the node being added. You can pass in
either the TreeNode
itself, or a path to
the node (as a String), in which case a
find(java.lang.String)
is performed to find
the node.position
- Position of the new node in the children list. If not
specified, the node will be added at the end of the list.
public TreeNode add(TreeNode node, String parentPath, int position)
public TreeNode[] addList(TreeNode[] nodeList, TreeNode parent)
nodeList
- The list of nodes to addparent
- Parent of the node being added. You can pass in
either the TreeNode
itself, or a path to
the node (as a String), in which case a
find(java.lang.String)
is performed to find
the node.
public TreeNode[] addList(TreeNode[] nodeList, String parentPath)
nodeList
- The list of nodes to addparentPath
- Parent of the node being added. You can pass in
either the TreeNode
itself, or a path to
the node (as a String), in which case a
find(java.lang.String)
is performed to find
the node.
public TreeNode[] addList(TreeNode[] nodeList, TreeNode parent, int position)
nodeList
- The list of nodes to addparent
- Parent of the node being added. You can pass in
either the TreeNode
itself, or a path to
the node (as a String), in which case a
find(java.lang.String)
is performed to find
the node.position
- Position of the new node in the children list. If not
specified, the node will be added at the end of the list.
public TreeNode[] addList(TreeNode[] nodeList, String parentPath, int position)
nodeList
- The list of nodes to addparentPath
- Parent of the node being added. You can pass in
either the TreeNode
itself, or a path to
the node (as a String), in which case a
find(java.lang.String)
is performed to find
the node.position
- Position of the new node in the children list. If not
specified, the node will be added at the end of the list.
public Boolean removeList(TreeNode[] nodeList)
nodeList
- list of nodes to remove
public void openFolders(TreeNode[] nodeList)
nodeList
- List of nodes or node paths.public void closeFolders(TreeNode[] nodeList)
nodeList
- List of nodes or node paths.public TreeNode[] getOpenList(TreeNode node)
node
- node in question
public static TreeNode nodeForRecord(ListGridRecord record)
record
- the record
public void loadChildren(TreeNode node)
node
- node in questionpublic void openFolder(TreeNode node)
node
- node to openpublic TreeNode[] getAllNodes()
public TreeNode getAllNodes(TreeNode node)
node
- optional node to start from. Default is root.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |