2
* Ext JS Library 3.0 RC2
3
* Copyright(c) 2006-2009, Ext JS, LLC.
6
* http://extjs.com/license
10
* @class Ext.tree.TreePanel
12
* <p>The TreePanel provides tree-structured UI representation of tree-structured data.</p>
13
* <p>{@link Ext.tree.TreeNode TreeNode}s added to the TreePanel may each contain metadata
14
* used by your application in their {@link Ext.tree.TreeNode#attributes attributes} property.</p>
15
* <p><b>A TreePanel must have a {@link #root} node before it is rendered.</b> This may either be
16
* specified using the {@link #root} config option, or using the {@link #setRootNode} method.
17
* <p>An example of tree rendered to an existing div:</p><pre><code>
18
var tree = new Ext.tree.TreePanel({
24
containerScroll: true,
26
// auto create TreeLoader
27
dataUrl: 'get-nodes.php',
39
tree.getRootNode().expand();
41
* <p>The example above would work with a data packet similar to this:</p><pre><code>
45
"id":"source\/adapter",
55
"id":"source\/debug.js",
61
* <p>An example of tree within a Viewport:</p><pre><code>
72
loader: new Ext.tree.TreeLoader(),
73
root: new Ext.tree.AsyncTreeNode({
76
text: 'Menu Option 1',
79
text: 'Menu Option 2',
82
text: 'Menu Option 3',
89
Ext.Msg.alert('Navigation Tree Click', 'You clicked: "' + n.attributes.text + '"');
95
// remaining code not shown ...
99
* @cfg {Ext.tree.TreeNode} root The root node for the tree.
100
* @cfg {Boolean} rootVisible <tt>false</tt> to hide the root node (defaults to <tt>true</tt>)
101
* @cfg {Boolean} lines <tt>false</tt> to disable tree lines (defaults to <tt>true</tt>)
102
* @cfg {Boolean} enableDD <tt>true</tt> to enable drag and drop
103
* @cfg {Boolean} enableDrag <tt>true</tt> to enable just drag
104
* @cfg {Boolean} enableDrop <tt>true</tt> to enable just drop
105
* @cfg {Object} dragConfig Custom config to pass to the {@link Ext.tree.TreeDragZone} instance
106
* @cfg {Object} dropConfig Custom config to pass to the {@link Ext.tree.TreeDropZone} instance
107
* @cfg {String} ddGroup The DD group this TreePanel belongs to
108
* @cfg {Boolean} ddAppendOnly <tt>true</tt> if the tree should only allow append drops (use for trees which are sorted)
109
* @cfg {Boolean} ddScroll <tt>true</tt> to enable body scrolling
110
* @cfg {Boolean} containerScroll <tt>true</tt> to register this container with ScrollManager
111
* @cfg {Boolean} hlDrop <tt>false</tt> to disable node highlight on drop (defaults to the value of {@link Ext#enableFx})
112
* @cfg {String} hlColor The color of the node highlight (defaults to <tt>'C3DAF9'</tt>)
113
* @cfg {Boolean} animate <tt>true</tt> to enable animated expand/collapse (defaults to the value of {@link Ext#enableFx})
114
* @cfg {Boolean} singleExpand <tt>true</tt> if only 1 node per branch may be expanded
115
* @cfg {Object} selModel A tree selection model to use with this TreePanel (defaults to an {@link Ext.tree.DefaultSelectionModel})
116
* @cfg {Boolean} trackMouseOver <tt>false</tt> to disable mouse over highlighting
117
* @cfg {Ext.tree.TreeLoader} loader A {@link Ext.tree.TreeLoader} for use with this TreePanel
118
* @cfg {String} pathSeparator The token used to separate sub-paths in path strings (defaults to <tt>'/'</tt>)
119
* @cfg {Boolean} useArrows <tt>true</tt> to use Vista-style arrows in the tree (defaults to <tt>false</tt>)
120
* @cfg {String} requestMethod The HTTP request method for loading data (defaults to the value of {@link Ext.Ajax#method}).
123
* @param {Object} config
125
Ext.tree.TreePanel = Ext.extend(Ext.Panel, {
127
animate: Ext.enableFx,
130
hlDrop : Ext.enableFx,
133
initComponent : function(){
134
Ext.tree.TreePanel.superclass.initComponent.call(this);
136
if(!this.eventModel){
137
this.eventModel = new Ext.tree.TreeEventModel(this);
140
// initialize the loader
143
l = new Ext.tree.TreeLoader({
144
dataUrl: this.dataUrl,
145
requestMethod: this.requestMethod
147
}else if(typeof l == 'object' && !l.load){
148
l = new Ext.tree.TreeLoader(l);
155
* The root node of this tree.
156
* @type Ext.tree.TreeNode
170
* Fires when a new child node is appended to a node in this tree.
171
* @param {Tree} tree The owner tree
172
* @param {Node} parent The parent node
173
* @param {Node} node The newly appended node
174
* @param {Number} index The index of the newly appended node
179
* Fires when a child node is removed from a node in this tree.
180
* @param {Tree} tree The owner tree
181
* @param {Node} parent The parent node
182
* @param {Node} node The child node removed
187
* Fires when a node is moved to a new location in the tree
188
* @param {Tree} tree The owner tree
189
* @param {Node} node The node moved
190
* @param {Node} oldParent The old parent of this node
191
* @param {Node} newParent The new parent of this node
192
* @param {Number} index The index it was moved to
197
* Fires when a new child node is inserted in a node in this tree.
198
* @param {Tree} tree The owner tree
199
* @param {Node} parent The parent node
200
* @param {Node} node The child node inserted
201
* @param {Node} refNode The child node the node was inserted before
205
* @event beforeappend
206
* Fires before a new child is appended to a node in this tree, return false to cancel the append.
207
* @param {Tree} tree The owner tree
208
* @param {Node} parent The parent node
209
* @param {Node} node The child node to be appended
213
* @event beforeremove
214
* Fires before a child is removed from a node in this tree, return false to cancel the remove.
215
* @param {Tree} tree The owner tree
216
* @param {Node} parent The parent node
217
* @param {Node} node The child node to be removed
221
* @event beforemovenode
222
* Fires before a node is moved to a new location in the tree. Return false to cancel the move.
223
* @param {Tree} tree The owner tree
224
* @param {Node} node The node being moved
225
* @param {Node} oldParent The parent of the node
226
* @param {Node} newParent The new parent the node is moving to
227
* @param {Number} index The index it is being moved to
231
* @event beforeinsert
232
* Fires before a new child is inserted in a node in this tree, return false to cancel the insert.
233
* @param {Tree} tree The owner tree
234
* @param {Node} parent The parent node
235
* @param {Node} node The child node to be inserted
236
* @param {Node} refNode The child node the node is being inserted before
242
* Fires before a node is loaded, return false to cancel
243
* @param {Node} node The node being loaded
248
* Fires when a node is loaded
249
* @param {Node} node The node that was loaded
254
* Fires when the text for a node is changed
255
* @param {Node} node The node
256
* @param {String} text The new text
257
* @param {String} oldText The old text
261
* @event beforeexpandnode
262
* Fires before a node is expanded, return false to cancel.
263
* @param {Node} node The node
264
* @param {Boolean} deep
265
* @param {Boolean} anim
269
* @event beforecollapsenode
270
* Fires before a node is collapsed, return false to cancel.
271
* @param {Node} node The node
272
* @param {Boolean} deep
273
* @param {Boolean} anim
275
"beforecollapsenode",
278
* Fires when a node is expanded
279
* @param {Node} node The node
283
* @event disabledchange
284
* Fires when the disabled status of a node changes
285
* @param {Node} node The node
286
* @param {Boolean} disabled
290
* @event collapsenode
291
* Fires when a node is collapsed
292
* @param {Node} node The node
297
* Fires before click processing on a node. Return false to cancel the default action.
298
* @param {Node} node The node
299
* @param {Ext.EventObject} e The event object
304
* Fires when a node is clicked
305
* @param {Node} node The node
306
* @param {Ext.EventObject} e The event object
311
* Fires when a node with a checkbox's checked property changes
312
* @param {Node} this This node
313
* @param {Boolean} checked
318
* Fires when a node is double clicked
319
* @param {Node} node The node
320
* @param {Ext.EventObject} e The event object
325
* Fires when a node is right clicked. To display a context menu in response to this
326
* event, first create a Menu object (see {@link Ext.menu.Menu} for details), then add
327
* a handler for this event:<code><pre>
328
new Ext.tree.TreePanel({
329
title: 'My TreePanel',
330
root: new Ext.tree.AsyncTreeNode({
333
{ text: 'Child node 1', leaf: true },
334
{ text: 'Child node 2', leaf: true }
337
contextMenu: new Ext.menu.Menu({
343
itemclick: function(item) {
346
var n = item.parentMenu.contextNode;
356
contextmenu: function(node, e) {
357
// Register the context node with the menu so that a Menu Item's handler function can access
358
// it via its {@link Ext.menu.BaseItem#parentMenu parentMenu} property.
360
var c = node.getOwnerTree().contextMenu;
361
c.contextNode = node;
367
* @param {Node} node The node
368
* @param {Ext.EventObject} e The event object
372
* @event beforechildrenrendered
373
* Fires right before the child nodes for a node are rendered
374
* @param {Node} node The node
376
"beforechildrenrendered",
379
* Fires when a node starts being dragged
380
* @param {Ext.tree.TreePanel} this
381
* @param {Ext.tree.TreeNode} node
382
* @param {event} e The raw browser event
387
* Fires when a drag operation is complete
388
* @param {Ext.tree.TreePanel} this
389
* @param {Ext.tree.TreeNode} node
390
* @param {event} e The raw browser event
395
* Fires when a dragged node is dropped on a valid DD target
396
* @param {Ext.tree.TreePanel} this
397
* @param {Ext.tree.TreeNode} node
398
* @param {DD} dd The dd it was dropped on
399
* @param {event} e The raw browser event
403
* @event beforenodedrop
404
* Fires when a DD object is dropped on a node in this tree for preprocessing. Return false to cancel the drop. The dropEvent
405
* passed to handlers has the following properties:<br />
406
* <ul style="padding:5px;padding-left:16px;">
407
* <li>tree - The TreePanel</li>
408
* <li>target - The node being targeted for the drop</li>
409
* <li>data - The drag data from the drag source</li>
410
* <li>point - The point of the drop - append, above or below</li>
411
* <li>source - The drag source</li>
412
* <li>rawEvent - Raw mouse event</li>
413
* <li>dropNode - Drop node(s) provided by the source <b>OR</b> you can supply node(s)
414
* to be inserted by setting them on this object.</li>
415
* <li>cancel - Set this to true to cancel the drop.</li>
416
* <li>dropStatus - If the default drop action is cancelled but the drop is valid, setting this to true
417
* will prevent the animated "repair" from appearing.</li>
419
* @param {Object} dropEvent
424
* Fires after a DD object is dropped on a node in this tree. The dropEvent
425
* passed to handlers has the following properties:<br />
426
* <ul style="padding:5px;padding-left:16px;">
427
* <li>tree - The TreePanel</li>
428
* <li>target - The node being targeted for the drop</li>
429
* <li>data - The drag data from the drag source</li>
430
* <li>point - The point of the drop - append, above or below</li>
431
* <li>source - The drag source</li>
432
* <li>rawEvent - Raw mouse event</li>
433
* <li>dropNode - Dropped node(s).</li>
435
* @param {Object} dropEvent
439
* @event nodedragover
440
* Fires when a tree node is being targeted for a drag drop, return false to signal drop not allowed. The dragOverEvent
441
* passed to handlers has the following properties:<br />
442
* <ul style="padding:5px;padding-left:16px;">
443
* <li>tree - The TreePanel</li>
444
* <li>target - The node being targeted for the drop</li>
445
* <li>data - The drag data from the drag source</li>
446
* <li>point - The point of the drop - append, above or below</li>
447
* <li>source - The drag source</li>
448
* <li>rawEvent - Raw mouse event</li>
449
* <li>dropNode - Drop node(s) provided by the source.</li>
450
* <li>cancel - Set this to true to signal drop not allowed.</li>
452
* @param {Object} dragOverEvent
456
if(this.singleExpand){
457
this.on("beforeexpandnode", this.restrictExpand, this);
462
proxyNodeEvent : function(ename, a1, a2, a3, a4, a5, a6){
463
if(ename == 'collapse' || ename == 'expand' || ename == 'beforecollapse' || ename == 'beforeexpand' || ename == 'move' || ename == 'beforemove'){
464
ename = ename+'node';
466
// args inline for performance while bubbling events
467
return this.fireEvent(ename, a1, a2, a3, a4, a5, a6);
472
* Returns this root node for this tree
475
getRootNode : function(){
480
* Sets the root node for this tree. If the TreePanel has already rendered a root node, the
481
* previous root node (and all of its descendants) are destroyed before the new root node is rendered.
485
setRootNode : function(node){
486
Ext.destroy(this.root);
487
if(!node.render){ // attributes passed
488
node = this.loader.createNode(node);
491
node.ownerTree = this;
493
this.registerNode(node);
494
if(!this.rootVisible){
495
var uiP = node.attributes.uiProvider;
496
node.ui = uiP ? new uiP(node) : new Ext.tree.RootTreeNodeUI(node);
499
this.innerCt.update('');
506
* Gets a node in this tree by its id
510
getNodeById : function(id){
511
return this.nodeHash[id];
515
registerNode : function(node){
516
this.nodeHash[node.id] = node;
520
unregisterNode : function(node){
521
delete this.nodeHash[node.id];
525
toString : function(){
526
return "[Tree"+(this.id?" "+this.id:"")+"]";
530
restrictExpand : function(node){
531
var p = node.parentNode;
533
if(p.expandedChild && p.expandedChild.parentNode == p){
534
p.expandedChild.collapse();
536
p.expandedChild = node;
541
* Retrieve an array of checked nodes, or an array of a specific attribute of checked nodes (e.g. "id")
542
* @param {String} attribute (optional) Defaults to null (return the actual nodes)
543
* @param {TreeNode} startNode (optional) The node to start from, defaults to the root
546
getChecked : function(a, startNode){
547
startNode = startNode || this.root;
550
if(this.attributes.checked){
551
r.push(!a ? this : (a == 'id' ? this.id : this.attributes[a]));
554
startNode.cascade(f);
559
* Returns the container element for this TreePanel.
560
* @return {Element} The container element for this TreePanel.
567
* Returns the default {@link Ext.tree.TreeLoader} for this TreePanel.
568
* @return {Ext.tree.TreeLoader} The TreeLoader for this TreePanel.
570
getLoader : function(){
577
expandAll : function(){
578
this.root.expand(true);
584
collapseAll : function(){
585
this.root.collapse(true);
589
* Returns the selection model used by this TreePanel.
590
* @return {TreeSelectionModel} The selection model used by this TreePanel
592
getSelectionModel : function(){
594
this.selModel = new Ext.tree.DefaultSelectionModel();
596
return this.selModel;
600
* Expands a specified path in this TreePanel. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
601
* @param {String} path
602
* @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
603
* @param {Function} callback (optional) The callback to call when the expand is complete. The callback will be called with
604
* (bSuccess, oLastNode) where bSuccess is if the expand was successful and oLastNode is the last node that was expanded.
606
expandPath : function(path, attr, callback){
608
var keys = path.split(this.pathSeparator);
609
var curNode = this.root;
610
if(curNode.attributes[attr] != keys[1]){ // invalid root
612
callback(false, null);
618
if(++index == keys.length){
620
callback(true, curNode);
624
var c = curNode.findChild(attr, keys[index]);
627
callback(false, curNode);
632
c.expand(false, false, f);
634
curNode.expand(false, false, f);
638
* Selects the node in this tree at the specified path. A path can be retrieved from a node with {@link Ext.data.Node#getPath}
639
* @param {String} path
640
* @param {String} attr (optional) The attribute used in the path (see {@link Ext.data.Node#getPath} for more info)
641
* @param {Function} callback (optional) The callback to call when the selection is complete. The callback will be called with
642
* (bSuccess, oSelNode) where bSuccess is if the selection was successful and oSelNode is the selected node.
644
selectPath : function(path, attr, callback){
646
var keys = path.split(this.pathSeparator);
649
var f = function(success, node){
651
var n = node.findChild(attr, v);
666
this.expandPath(keys.join(this.pathSeparator), attr, f);
670
callback(true, this.root);
676
* Returns the underlying Element for this tree
677
* @return {Ext.Element} The Element
679
getTreeEl : function(){
684
onRender : function(ct, position){
685
Ext.tree.TreePanel.superclass.onRender.call(this, ct, position);
686
this.el.addClass('x-tree');
687
this.innerCt = this.body.createChild({tag:"ul",
688
cls:"x-tree-root-ct " +
689
(this.useArrows ? 'x-tree-arrows' : this.lines ? "x-tree-lines" : "x-tree-no-lines")});
693
initEvents : function(){
694
Ext.tree.TreePanel.superclass.initEvents.call(this);
696
if(this.containerScroll){
697
Ext.dd.ScrollManager.register(this.body);
699
if((this.enableDD || this.enableDrop) && !this.dropZone){
701
* The dropZone used by this tree if drop is enabled (see {@link #enableDD} or {@link #enableDrop})
703
* @type Ext.tree.TreeDropZone
705
this.dropZone = new Ext.tree.TreeDropZone(this, this.dropConfig || {
706
ddGroup: this.ddGroup || "TreeDD", appendOnly: this.ddAppendOnly === true
709
if((this.enableDD || this.enableDrag) && !this.dragZone){
711
* The dragZone used by this tree if drag is enabled (see {@link #enableDD} or {@link #enableDrag})
713
* @type Ext.tree.TreeDragZone
715
this.dragZone = new Ext.tree.TreeDragZone(this, this.dragConfig || {
716
ddGroup: this.ddGroup || "TreeDD",
717
scroll: this.ddScroll
720
this.getSelectionModel().init(this);
724
afterRender : function(){
725
Ext.tree.TreePanel.superclass.afterRender.call(this);
727
if(!this.rootVisible){
728
this.root.renderChildren();
732
onDestroy : function(){
734
this.body.removeAllListeners();
735
Ext.dd.ScrollManager.unregister(this.body);
737
this.dropZone.unreg();
740
this.dragZone.unreg();
744
this.nodeHash = null;
745
Ext.tree.TreePanel.superclass.onDestroy.call(this);
749
* @cfg {String/Number} activeItem
753
* @cfg {Boolean} autoDestroy
757
* @cfg {Object/String/Function} autoLoad
761
* @cfg {Boolean} autoWidth
765
* @cfg {Boolean/Number} bufferResize
769
* @cfg {String} defaultType
773
* @cfg {Object} defaults
777
* @cfg {Boolean} hideBorders
785
* @cfg {String} layout
789
* @cfg {Object} layoutConfig
793
* @cfg {Boolean} monitorResize
825
* @method getComponent
865
* @event beforeremove
876
* @cfg {String} allowDomMove @hide
879
* @cfg {String} autoEl @hide
882
* @cfg {String} applyTo @hide
885
* @cfg {String} contentEl @hide
888
* @cfg {String} disabledClass @hide
891
* @cfg {String} elements @hide
894
* @cfg {String} html @hide
901
* @method applyToMarkup
913
* @method setDisabled
918
Ext.tree.TreePanel.nodeTypes = {};
920
Ext.reg('treepanel', Ext.tree.TreePanel);
b'\\ No newline at end of file'