4 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5 <title>The source code</title>
6 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
7 <script type="text/javascript" src="../resources/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'>/**
19 </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 Ext.define('Ext.data.Tree', {
34 observable: "Ext.util.Observable"
37 <span id='Ext-data-Tree-property-root'> /**
38 </span> * @property {Ext.data.NodeInterface}
39 * The root node for this tree
43 <span id='Ext-data-Tree-method-constructor'> /**
44 </span> * Creates new Tree object.
45 * @param {Ext.data.NodeInterface} root (optional) The root node
47 constructor: function(root) {
52 me.mixins.observable.constructor.call(me);
59 <span id='Ext-data-Tree-method-getRootNode'> /**
60 </span> * Returns the root node for this tree.
61 * @return {Ext.data.NodeInterface}
63 getRootNode : function() {
67 <span id='Ext-data-Tree-method-setRootNode'> /**
68 </span> * Sets the root node for this tree.
69 * @param {Ext.data.NodeInterface} node
70 * @return {Ext.data.NodeInterface} The root node
72 setRootNode : function(node) {
76 Ext.data.NodeInterface.decorate(node);
78 if (me.fireEvent('beforeappend', null, node) !== false) {
79 node.set('root', true);
82 me.relayEvents(node, [
83 <span id='Ext-data-Tree-event-append'> /**
84 </span> * @event append
85 * @alias Ext.data.NodeInterface#append
89 <span id='Ext-data-Tree-event-remove'> /**
90 </span> * @event remove
91 * @alias Ext.data.NodeInterface#remove
95 <span id='Ext-data-Tree-event-move'> /**
97 * @alias Ext.data.NodeInterface#move
101 <span id='Ext-data-Tree-event-insert'> /**
102 </span> * @event insert
103 * @alias Ext.data.NodeInterface#insert
107 <span id='Ext-data-Tree-event-beforeappend'> /**
108 </span> * @event beforeappend
109 * @alias Ext.data.NodeInterface#beforeappend
111 "beforeappend",
113 <span id='Ext-data-Tree-event-beforeremove'> /**
114 </span> * @event beforeremove
115 * @alias Ext.data.NodeInterface#beforeremove
117 "beforeremove",
119 <span id='Ext-data-Tree-event-beforemove'> /**
120 </span> * @event beforemove
121 * @alias Ext.data.NodeInterface#beforemove
123 "beforemove",
125 <span id='Ext-data-Tree-event-beforeinsert'> /**
126 </span> * @event beforeinsert
127 * @alias Ext.data.NodeInterface#beforeinsert
129 "beforeinsert",
131 <span id='Ext-data-Tree-event-expand'> /**
132 </span> * @event expand
133 * @alias Ext.data.NodeInterface#expand
137 <span id='Ext-data-Tree-event-collapse'> /**
138 </span> * @event collapse
139 * @alias Ext.data.NodeInterface#collapse
141 "collapse",
143 <span id='Ext-data-Tree-event-beforeexpand'> /**
144 </span> * @event beforeexpand
145 * @alias Ext.data.NodeInterface#beforeexpand
147 "beforeexpand",
149 <span id='Ext-data-Tree-event-beforecollapse'> /**
150 </span> * @event beforecollapse
151 * @alias Ext.data.NodeInterface#beforecollapse
153 "beforecollapse" ,
155 <span id='Ext-data-Tree-event-rootchange'> /**
156 </span> * @event rootchange
157 * Fires whenever the root node is changed in the tree.
158 * @param {Ext.data.Model} root The new root
160 "rootchange"
165 insert: me.onNodeInsert,
166 append: me.onNodeAppend,
167 remove: me.onNodeRemove
171 me.registerNode(node);
172 me.fireEvent('append', null, node);
173 me.fireEvent('rootchange', node);
179 <span id='Ext-data-Tree-method-flatten'> /**
180 </span> * Flattens all the nodes in the tree into an array.
182 * @return {Ext.data.NodeInterface[]} The flattened nodes.
186 hash = this.nodeHash,
190 if (hash.hasOwnProperty(key)) {
191 nodes.push(hash[key]);
197 <span id='Ext-data-Tree-method-onNodeInsert'> /**
198 </span> * Fired when a node is inserted into the root or one of it's children
200 * @param {Ext.data.NodeInterface} parent The parent node
201 * @param {Ext.data.NodeInterface} node The inserted node
203 onNodeInsert: function(parent, node) {
204 this.registerNode(node, true);
207 <span id='Ext-data-Tree-method-onNodeAppend'> /**
208 </span> * Fired when a node is appended into the root or one of it's children
210 * @param {Ext.data.NodeInterface} parent The parent node
211 * @param {Ext.data.NodeInterface} node The appended node
213 onNodeAppend: function(parent, node) {
214 this.registerNode(node, true);
217 <span id='Ext-data-Tree-method-onNodeRemove'> /**
218 </span> * Fired when a node is removed from the root or one of it's children
220 * @param {Ext.data.NodeInterface} parent The parent node
221 * @param {Ext.data.NodeInterface} node The removed node
223 onNodeRemove: function(parent, node) {
224 this.unregisterNode(node, true);
227 <span id='Ext-data-Tree-method-getNodeById'> /**
228 </span> * Gets a node in this tree by its id.
230 * @return {Ext.data.NodeInterface} The match node.
232 getNodeById : function(id) {
233 return this.nodeHash[id];
236 <span id='Ext-data-Tree-method-registerNode'> /**
237 </span> * Registers a node with the tree
239 * @param {Ext.data.NodeInterface} The node to register
240 * @param {Boolean} [includeChildren] True to unregister any child nodes
242 registerNode : function(node, includeChildren) {
243 this.nodeHash[node.getId() || node.internalId] = node;
244 if (includeChildren === true) {
245 node.eachChild(function(child){
246 this.registerNode(child, true);
251 <span id='Ext-data-Tree-method-unregisterNode'> /**
252 </span> * Unregisters a node with the tree
254 * @param {Ext.data.NodeInterface} The node to unregister
255 * @param {Boolean} [includeChildren] True to unregister any child nodes
257 unregisterNode : function(node, includeChildren) {
258 delete this.nodeHash[node.getId() || node.internalId];
259 if (includeChildren === true) {
260 node.eachChild(function(child){
261 this.unregisterNode(child, true);
266 <span id='Ext-data-Tree-method-sort'> /**
267 </span> * Sorts this tree
269 * @param {Function} sorterFn The function to use for sorting
270 * @param {Boolean} recursive True to perform recursive sorting
272 sort: function(sorterFn, recursive) {
273 this.getRootNode().sort(sorterFn, recursive);
276 <span id='Ext-data-Tree-method-filter'> /**
277 </span> * Filters this tree
279 * @param {Function} sorterFn The function to use for filtering
280 * @param {Boolean} recursive True to perform recursive filtering
282 filter: function(filters, recursive) {
283 this.getRootNode().filter(filters, recursive);