4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../prettify/prettify.js"></script>
8 <style type="text/css">
9 .highlight { display: block; background-color: #ddd; }
11 <script type="text/javascript">
12 function highlight() {
13 document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
17 <body onload="prettyPrint(); highlight();">
18 <pre class="prettyprint lang-js"><span id='Ext-data-Tree-method-constructor'><span id='Ext-data-Tree'>/**
19 </span></span> * @class Ext.data.Tree
21 * This class is used as a container for a series of nodes. The nodes themselves maintain
22 * the relationship between parent/child. The tree itself acts as a manager. It gives functionality
23 * to retrieve a node by its identifier: {@link #getNodeById}.
25 * The tree also relays events from any of it's child nodes, allowing them to be handled in a
26 * centralized fashion. In general this class is not used directly, rather used internally
27 * by other parts of the framework.
30 * @param {Node} root (optional) The root node
32 Ext.define('Ext.data.Tree', {
36 observable: "Ext.util.Observable"
39 <span id='Ext-data-Tree-property-root'> /**
40 </span> * The root node for this tree
45 constructor: function(root) {
50 me.mixins.observable.constructor.call(me);
57 <span id='Ext-data-Tree-method-getRootNode'> /**
58 </span> * Returns the root node for this tree.
59 * @return {Ext.data.NodeInterface}
61 getRootNode : function() {
65 <span id='Ext-data-Tree-method-setRootNode'> /**
66 </span> * Sets the root node for this tree.
67 * @param {Ext.data.NodeInterface} node
68 * @return {Ext.data.NodeInterface} The root node
70 setRootNode : function(node) {
74 Ext.data.NodeInterface.decorate(node);
76 if (me.fireEvent('beforeappend', null, node) !== false) {
77 node.set('root', true);
80 me.relayEvents(node, [
81 <span id='Ext-data-Tree-event-append'> /**
82 </span> * @event append
83 * Fires when a new child node is appended to a node in this tree.
84 * @param {Tree} tree The owner tree
85 * @param {Node} parent The parent node
86 * @param {Node} node The newly appended node
87 * @param {Number} index The index of the newly appended node
91 <span id='Ext-data-Tree-event-remove'> /**
92 </span> * @event remove
93 * Fires when a child node is removed from a node in this tree.
94 * @param {Tree} tree The owner tree
95 * @param {Node} parent The parent node
96 * @param {Node} node The child node removed
100 <span id='Ext-data-Tree-event-move'> /**
101 </span> * @event move
102 * Fires when a node is moved to a new location in the tree
103 * @param {Tree} tree The owner tree
104 * @param {Node} node The node moved
105 * @param {Node} oldParent The old parent of this node
106 * @param {Node} newParent The new parent of this node
107 * @param {Number} index The index it was moved to
111 <span id='Ext-data-Tree-event-insert'> /**
112 </span> * @event insert
113 * Fires when a new child node is inserted in a node in this tree.
114 * @param {Tree} tree The owner tree
115 * @param {Node} parent The parent node
116 * @param {Node} node The child node inserted
117 * @param {Node} refNode The child node the node was inserted before
121 <span id='Ext-data-Tree-event-beforeappend'> /**
122 </span> * @event beforeappend
123 * Fires before a new child is appended to a node in this tree, return false to cancel the append.
124 * @param {Tree} tree The owner tree
125 * @param {Node} parent The parent node
126 * @param {Node} node The child node to be appended
128 "beforeappend",
130 <span id='Ext-data-Tree-event-beforeremove'> /**
131 </span> * @event beforeremove
132 * Fires before a child is removed from a node in this tree, return false to cancel the remove.
133 * @param {Tree} tree The owner tree
134 * @param {Node} parent The parent node
135 * @param {Node} node The child node to be removed
137 "beforeremove",
139 <span id='Ext-data-Tree-event-beforemove'> /**
140 </span> * @event beforemove
141 * Fires before a node is moved to a new location in the tree. Return false to cancel the move.
142 * @param {Tree} tree The owner tree
143 * @param {Node} node The node being moved
144 * @param {Node} oldParent The parent of the node
145 * @param {Node} newParent The new parent the node is moving to
146 * @param {Number} index The index it is being moved to
148 "beforemove",
150 <span id='Ext-data-Tree-event-beforeinsert'> /**
151 </span> * @event beforeinsert
152 * Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
153 * @param {Tree} tree The owner tree
154 * @param {Node} parent The parent node
155 * @param {Node} node The child node to be inserted
156 * @param {Node} refNode The child node the node is being inserted before
158 "beforeinsert",
160 <span id='Ext-data-Tree-event-expand'> /**
161 </span> * @event expand
162 * Fires when this node is expanded.
163 * @param {Node} this The expanding node
167 <span id='Ext-data-Tree-event-collapse'> /**
168 </span> * @event collapse
169 * Fires when this node is collapsed.
170 * @param {Node} this The collapsing node
172 "collapse",
174 <span id='Ext-data-Tree-event-beforeexpand'> /**
175 </span> * @event beforeexpand
176 * Fires before this node is expanded.
177 * @param {Node} this The expanding node
179 "beforeexpand",
181 <span id='Ext-data-Tree-event-beforecollapse'> /**
182 </span> * @event beforecollapse
183 * Fires before this node is collapsed.
184 * @param {Node} this The collapsing node
186 "beforecollapse" ,
188 <span id='Ext-data-Tree-event-rootchange'> /**
189 </span> * @event rootchange
190 * Fires whenever the root node is changed in the tree.
191 * @param {Ext.data.Model} root The new root
193 "rootchange"
198 insert: me.onNodeInsert,
199 append: me.onNodeAppend,
200 remove: me.onNodeRemove
203 me.registerNode(node);
204 me.fireEvent('append', null, node);
205 me.fireEvent('rootchange', node);
211 <span id='Ext-data-Tree-method-flatten'> /**
212 </span> * Flattens all the nodes in the tree into an array.
214 * @return {Array} The flattened nodes.
218 hash = this.nodeHash,
222 if (hash.hasOwnProperty(key)) {
223 nodes.push(hash[key]);
229 <span id='Ext-data-Tree-method-onNodeInsert'> /**
230 </span> * Fired when a node is inserted into the root or one of it's children
232 * @param {Ext.data.NodeInterface} parent The parent node
233 * @param {Ext.data.NodeInterface} node The inserted node
235 onNodeInsert: function(parent, node) {
236 this.registerNode(node);
239 <span id='Ext-data-Tree-method-onNodeAppend'> /**
240 </span> * Fired when a node is appended into the root or one of it's children
242 * @param {Ext.data.NodeInterface} parent The parent node
243 * @param {Ext.data.NodeInterface} node The appended node
245 onNodeAppend: function(parent, node) {
246 this.registerNode(node);
249 <span id='Ext-data-Tree-method-onNodeRemove'> /**
250 </span> * Fired when a node is removed from the root or one of it's children
252 * @param {Ext.data.NodeInterface} parent The parent node
253 * @param {Ext.data.NodeInterface} node The removed node
255 onNodeRemove: function(parent, node) {
256 this.unregisterNode(node);
259 <span id='Ext-data-Tree-method-getNodeById'> /**
260 </span> * Gets a node in this tree by its id.
262 * @return {Ext.data.NodeInterface} The match node.
264 getNodeById : function(id) {
265 return this.nodeHash[id];
268 <span id='Ext-data-Tree-method-registerNode'> /**
269 </span> * Registers a node with the tree
271 * @param {Ext.data.NodeInterface} The node to register
273 registerNode : function(node) {
274 this.nodeHash[node.getId() || node.internalId] = node;
277 <span id='Ext-data-Tree-method-unregisterNode'> /**
278 </span> * Unregisters a node with the tree
280 * @param {Ext.data.NodeInterface} The node to unregister
282 unregisterNode : function(node) {
283 delete this.nodeHash[node.getId() || node.internalId];
286 <span id='Ext-data-Tree-method-sort'> /**
287 </span> * Sorts this tree
289 * @param {Function} sorterFn The function to use for sorting
290 * @param {Boolean} recursive True to perform recursive sorting
292 sort: function(sorterFn, recursive) {
293 this.getRootNode().sort(sorterFn, recursive);
296 <span id='Ext-data-Tree-method-filter'> /**
297 </span> * Filters this tree
299 * @param {Function} sorterFn The function to use for filtering
300 * @param {Boolean} recursive True to perform recursive filtering
302 filter: function(filters, recursive) {
303 this.getRootNode().filter(filters, recursive);