3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
4 <title>The source code</title>
5 <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
6 <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
8 <body onload="prettyPrint();">
9 <pre class="prettyprint lang-js">/*!
10 * Ext JS Library 3.2.0
11 * Copyright(c) 2006-2010 Ext JS, Inc.
13 * http://www.extjs.com/license
15 <div id="cls-Ext.tree.DefaultSelectionModel"></div>/**
16 * @class Ext.tree.DefaultSelectionModel
17 * @extends Ext.util.Observable
18 * The default single selection for a TreePanel.
20 Ext.tree.DefaultSelectionModel = function(config){
24 <div id="event-Ext.tree.DefaultSelectionModel-selectionchange"></div>/**
25 * @event selectionchange
26 * Fires when the selected node changes
27 * @param {DefaultSelectionModel} this
28 * @param {TreeNode} node the new selection
32 <div id="event-Ext.tree.DefaultSelectionModel-beforeselect"></div>/**
34 * Fires before the selected node changes, return false to cancel the change
35 * @param {DefaultSelectionModel} this
36 * @param {TreeNode} node the new selection
37 * @param {TreeNode} node the old selection
42 Ext.apply(this, config);
43 Ext.tree.DefaultSelectionModel.superclass.constructor.call(this);
46 Ext.extend(Ext.tree.DefaultSelectionModel, Ext.util.Observable, {
47 init : function(tree){
49 tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
50 tree.on('click', this.onNodeClick, this);
53 onNodeClick : function(node, e){
57 <div id="method-Ext.tree.DefaultSelectionModel-select"></div>/**
59 * @param {TreeNode} node The node to select
60 * @return {TreeNode} The selected node
62 select : function(node, /* private*/ selectNextNode){
63 // If node is hidden, select the next node in whatever direction was being moved in.
64 if (!Ext.fly(node.ui.wrap).isVisible() && selectNextNode) {
65 return selectNextNode.call(this, node);
67 var last = this.selNode;
69 node.ui.onSelectedChange(true);
70 }else if(this.fireEvent('beforeselect', this, node, last) !== false){
72 last.ui.onSelectedChange(false);
75 node.ui.onSelectedChange(true);
76 this.fireEvent('selectionchange', this, node, last);
81 <div id="method-Ext.tree.DefaultSelectionModel-unselect"></div>/**
83 * @param {TreeNode} node The node to unselect
84 * @param {Boolean} silent True to stop the selectionchange event from firing.
86 unselect : function(node, silent){
87 if(this.selNode == node){
88 this.clearSelections(silent);
92 <div id="method-Ext.tree.DefaultSelectionModel-clearSelections"></div>/**
93 * Clear all selections
94 * @param {Boolean} silent True to stop the selectionchange event from firing.
96 clearSelections : function(silent){
99 n.ui.onSelectedChange(false);
102 this.fireEvent('selectionchange', this, null);
108 <div id="method-Ext.tree.DefaultSelectionModel-getSelectedNode"></div>/**
109 * Get the selected node
110 * @return {TreeNode} The selected node
112 getSelectedNode : function(){
116 <div id="method-Ext.tree.DefaultSelectionModel-isSelected"></div>/**
117 * Returns true if the node is selected
118 * @param {TreeNode} node The node to check
121 isSelected : function(node){
122 return this.selNode == node;
125 <div id="method-Ext.tree.DefaultSelectionModel-selectPrevious"></div>/**
126 * Selects the node above the selected node in the tree, intelligently walking the nodes
127 * @return TreeNode The new selection
129 selectPrevious : function(/* private */ s){
130 if(!(s = s || this.selNode || this.lastSelNode)){
133 // Here we pass in the current function to select to indicate the direction we're moving
134 var ps = s.previousSibling;
136 if(!ps.isExpanded() || ps.childNodes.length < 1){
137 return this.select(ps, this.selectPrevious);
139 var lc = ps.lastChild;
140 while(lc && lc.isExpanded() && Ext.fly(lc.ui.wrap).isVisible() && lc.childNodes.length > 0){
143 return this.select(lc, this.selectPrevious);
145 } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
146 return this.select(s.parentNode, this.selectPrevious);
151 <div id="method-Ext.tree.DefaultSelectionModel-selectNext"></div>/**
152 * Selects the node above the selected node in the tree, intelligently walking the nodes
153 * @return TreeNode The new selection
155 selectNext : function(/* private */ s){
156 if(!(s = s || this.selNode || this.lastSelNode)){
159 // Here we pass in the current function to select to indicate the direction we're moving
160 if(s.firstChild && s.isExpanded() && Ext.fly(s.ui.wrap).isVisible()){
161 return this.select(s.firstChild, this.selectNext);
162 }else if(s.nextSibling){
163 return this.select(s.nextSibling, this.selectNext);
164 }else if(s.parentNode){
166 s.parentNode.bubble(function(){
167 if(this.nextSibling){
168 newS = this.getOwnerTree().selModel.select(this.nextSibling, this.selectNext);
177 onKeyDown : function(e){
178 var s = this.selNode || this.lastSelNode;
179 // undesirable, but required
192 this.selectPrevious();
196 if(s.hasChildNodes()){
199 }else if(s.firstChild){
200 this.select(s.firstChild, e);
206 if(s.hasChildNodes() && s.isExpanded()){
208 }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
209 this.select(s.parentNode, e);
216 <div id="cls-Ext.tree.MultiSelectionModel"></div>/**
217 * @class Ext.tree.MultiSelectionModel
218 * @extends Ext.util.Observable
219 * Multi selection for a TreePanel.
221 Ext.tree.MultiSelectionModel = function(config){
225 <div id="event-Ext.tree.MultiSelectionModel-selectionchange"></div>/**
226 * @event selectionchange
227 * Fires when the selected nodes change
228 * @param {MultiSelectionModel} this
229 * @param {Array} nodes Array of the selected nodes
233 Ext.apply(this, config);
234 Ext.tree.MultiSelectionModel.superclass.constructor.call(this);
237 Ext.extend(Ext.tree.MultiSelectionModel, Ext.util.Observable, {
238 init : function(tree){
240 tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
241 tree.on('click', this.onNodeClick, this);
244 onNodeClick : function(node, e){
245 if(e.ctrlKey && this.isSelected(node)){
248 this.select(node, e, e.ctrlKey);
252 <div id="method-Ext.tree.MultiSelectionModel-select"></div>/**
254 * @param {TreeNode} node The node to select
255 * @param {EventObject} e (optional) An event associated with the selection
256 * @param {Boolean} keepExisting True to retain existing selections
257 * @return {TreeNode} The selected node
259 select : function(node, e, keepExisting){
260 if(keepExisting !== true){
261 this.clearSelections(true);
263 if(this.isSelected(node)){
264 this.lastSelNode = node;
267 this.selNodes.push(node);
268 this.selMap[node.id] = node;
269 this.lastSelNode = node;
270 node.ui.onSelectedChange(true);
271 this.fireEvent('selectionchange', this, this.selNodes);
275 <div id="method-Ext.tree.MultiSelectionModel-unselect"></div>/**
277 * @param {TreeNode} node The node to unselect
279 unselect : function(node){
280 if(this.selMap[node.id]){
281 node.ui.onSelectedChange(false);
282 var sn = this.selNodes;
283 var index = sn.indexOf(node);
285 this.selNodes.splice(index, 1);
287 delete this.selMap[node.id];
288 this.fireEvent('selectionchange', this, this.selNodes);
292 <div id="method-Ext.tree.MultiSelectionModel-clearSelections"></div>/**
293 * Clear all selections
295 clearSelections : function(suppressEvent){
296 var sn = this.selNodes;
298 for(var i = 0, len = sn.length; i < len; i++){
299 sn[i].ui.onSelectedChange(false);
303 if(suppressEvent !== true){
304 this.fireEvent('selectionchange', this, this.selNodes);
309 <div id="method-Ext.tree.MultiSelectionModel-isSelected"></div>/**
310 * Returns true if the node is selected
311 * @param {TreeNode} node The node to check
314 isSelected : function(node){
315 return this.selMap[node.id] ? true : false;
318 <div id="method-Ext.tree.MultiSelectionModel-getSelectedNodes"></div>/**
319 * Returns an array of the selected nodes
322 getSelectedNodes : function(){
323 return this.selNodes;
326 onKeyDown : Ext.tree.DefaultSelectionModel.prototype.onKeyDown,
328 selectNext : Ext.tree.DefaultSelectionModel.prototype.selectNext,
330 selectPrevious : Ext.tree.DefaultSelectionModel.prototype.selectPrevious