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.3.1
11 * Copyright(c) 2006-2010 Sencha Inc.
12 * licensing@sencha.com
13 * http://www.sencha.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 = Ext.extend(Ext.util.Observable, {
22 constructor : function(config){
26 <div id="event-Ext.tree.DefaultSelectionModel-selectionchange"></div>/**
27 * @event selectionchange
28 * Fires when the selected node changes
29 * @param {DefaultSelectionModel} this
30 * @param {TreeNode} node the new selection
34 <div id="event-Ext.tree.DefaultSelectionModel-beforeselect"></div>/**
36 * Fires before the selected node changes, return false to cancel the change
37 * @param {DefaultSelectionModel} this
38 * @param {TreeNode} node the new selection
39 * @param {TreeNode} node the old selection
44 Ext.apply(this, config);
45 Ext.tree.DefaultSelectionModel.superclass.constructor.call(this);
48 init : function(tree){
50 tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
51 tree.on('click', this.onNodeClick, this);
54 onNodeClick : function(node, e){
58 <div id="method-Ext.tree.DefaultSelectionModel-select"></div>/**
60 * @param {TreeNode} node The node to select
61 * @return {TreeNode} The selected node
63 select : function(node, /* private*/ selectNextNode){
64 // If node is hidden, select the next node in whatever direction was being moved in.
65 if (!Ext.fly(node.ui.wrap).isVisible() && selectNextNode) {
66 return selectNextNode.call(this, node);
68 var last = this.selNode;
70 node.ui.onSelectedChange(true);
71 }else if(this.fireEvent('beforeselect', this, node, last) !== false){
73 last.ui.onSelectedChange(false);
76 node.ui.onSelectedChange(true);
77 this.fireEvent('selectionchange', this, node, last);
82 <div id="method-Ext.tree.DefaultSelectionModel-unselect"></div>/**
84 * @param {TreeNode} node The node to unselect
85 * @param {Boolean} silent True to stop the selectionchange event from firing.
87 unselect : function(node, silent){
88 if(this.selNode == node){
89 this.clearSelections(silent);
93 <div id="method-Ext.tree.DefaultSelectionModel-clearSelections"></div>/**
94 * Clear all selections
95 * @param {Boolean} silent True to stop the selectionchange event from firing.
97 clearSelections : function(silent){
100 n.ui.onSelectedChange(false);
103 this.fireEvent('selectionchange', this, null);
109 <div id="method-Ext.tree.DefaultSelectionModel-getSelectedNode"></div>/**
110 * Get the selected node
111 * @return {TreeNode} The selected node
113 getSelectedNode : function(){
117 <div id="method-Ext.tree.DefaultSelectionModel-isSelected"></div>/**
118 * Returns true if the node is selected
119 * @param {TreeNode} node The node to check
122 isSelected : function(node){
123 return this.selNode == node;
126 <div id="method-Ext.tree.DefaultSelectionModel-selectPrevious"></div>/**
127 * Selects the node above the selected node in the tree, intelligently walking the nodes
128 * @return TreeNode The new selection
130 selectPrevious : function(/* private */ s){
131 if(!(s = s || this.selNode || this.lastSelNode)){
134 // Here we pass in the current function to select to indicate the direction we're moving
135 var ps = s.previousSibling;
137 if(!ps.isExpanded() || ps.childNodes.length < 1){
138 return this.select(ps, this.selectPrevious);
140 var lc = ps.lastChild;
141 while(lc && lc.isExpanded() && Ext.fly(lc.ui.wrap).isVisible() && lc.childNodes.length > 0){
144 return this.select(lc, this.selectPrevious);
146 } else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
147 return this.select(s.parentNode, this.selectPrevious);
152 <div id="method-Ext.tree.DefaultSelectionModel-selectNext"></div>/**
153 * Selects the node above the selected node in the tree, intelligently walking the nodes
154 * @return TreeNode The new selection
156 selectNext : function(/* private */ s){
157 if(!(s = s || this.selNode || this.lastSelNode)){
160 // Here we pass in the current function to select to indicate the direction we're moving
161 if(s.firstChild && s.isExpanded() && Ext.fly(s.ui.wrap).isVisible()){
162 return this.select(s.firstChild, this.selectNext);
163 }else if(s.nextSibling){
164 return this.select(s.nextSibling, this.selectNext);
165 }else if(s.parentNode){
167 s.parentNode.bubble(function(){
168 if(this.nextSibling){
169 newS = this.getOwnerTree().selModel.select(this.nextSibling, this.selectNext);
178 onKeyDown : function(e){
179 var s = this.selNode || this.lastSelNode;
180 // undesirable, but required
193 this.selectPrevious();
197 if(s.hasChildNodes()){
200 }else if(s.firstChild){
201 this.select(s.firstChild, e);
207 if(s.hasChildNodes() && s.isExpanded()){
209 }else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
210 this.select(s.parentNode, e);
217 <div id="cls-Ext.tree.MultiSelectionModel"></div>/**
218 * @class Ext.tree.MultiSelectionModel
219 * @extends Ext.util.Observable
220 * Multi selection for a TreePanel.
222 Ext.tree.MultiSelectionModel = Ext.extend(Ext.util.Observable, {
224 constructor : function(config){
228 <div id="event-Ext.tree.MultiSelectionModel-selectionchange"></div>/**
229 * @event selectionchange
230 * Fires when the selected nodes change
231 * @param {MultiSelectionModel} this
232 * @param {Array} nodes Array of the selected nodes
236 Ext.apply(this, config);
237 Ext.tree.MultiSelectionModel.superclass.constructor.call(this);
240 init : function(tree){
242 tree.mon(tree.getTreeEl(), 'keydown', this.onKeyDown, this);
243 tree.on('click', this.onNodeClick, this);
246 onNodeClick : function(node, e){
247 if(e.ctrlKey && this.isSelected(node)){
250 this.select(node, e, e.ctrlKey);
254 <div id="method-Ext.tree.MultiSelectionModel-select"></div>/**
256 * @param {TreeNode} node The node to select
257 * @param {EventObject} e (optional) An event associated with the selection
258 * @param {Boolean} keepExisting True to retain existing selections
259 * @return {TreeNode} The selected node
261 select : function(node, e, keepExisting){
262 if(keepExisting !== true){
263 this.clearSelections(true);
265 if(this.isSelected(node)){
266 this.lastSelNode = node;
269 this.selNodes.push(node);
270 this.selMap[node.id] = node;
271 this.lastSelNode = node;
272 node.ui.onSelectedChange(true);
273 this.fireEvent('selectionchange', this, this.selNodes);
277 <div id="method-Ext.tree.MultiSelectionModel-unselect"></div>/**
279 * @param {TreeNode} node The node to unselect
281 unselect : function(node){
282 if(this.selMap[node.id]){
283 node.ui.onSelectedChange(false);
284 var sn = this.selNodes;
285 var index = sn.indexOf(node);
287 this.selNodes.splice(index, 1);
289 delete this.selMap[node.id];
290 this.fireEvent('selectionchange', this, this.selNodes);
294 <div id="method-Ext.tree.MultiSelectionModel-clearSelections"></div>/**
295 * Clear all selections
297 clearSelections : function(suppressEvent){
298 var sn = this.selNodes;
300 for(var i = 0, len = sn.length; i < len; i++){
301 sn[i].ui.onSelectedChange(false);
305 if(suppressEvent !== true){
306 this.fireEvent('selectionchange', this, this.selNodes);
311 <div id="method-Ext.tree.MultiSelectionModel-isSelected"></div>/**
312 * Returns true if the node is selected
313 * @param {TreeNode} node The node to check
316 isSelected : function(node){
317 return this.selMap[node.id] ? true : false;
320 <div id="method-Ext.tree.MultiSelectionModel-getSelectedNodes"></div>/**
321 * Returns an array of the selected nodes
324 getSelectedNodes : function(){
325 return this.selNodes.concat([]);
328 onKeyDown : Ext.tree.DefaultSelectionModel.prototype.onKeyDown,
330 selectNext : Ext.tree.DefaultSelectionModel.prototype.selectNext,
332 selectPrevious : Ext.tree.DefaultSelectionModel.prototype.selectPrevious