3
* Copyright(c) 2006-2009, Ext JS, LLC.
6
* http://extjs.com/license
10
* @class Ext.tree.DefaultSelectionModel
11
* @extends Ext.util.Observable
12
* The default single selection for a TreePanel.
14
Ext.tree.DefaultSelectionModel = function(config){
19
* @event selectionchange
20
* Fires when the selected node changes
21
* @param {DefaultSelectionModel} this
22
* @param {TreeNode} node the new selection
28
* Fires before the selected node changes, return false to cancel the change
29
* @param {DefaultSelectionModel} this
30
* @param {TreeNode} node the new selection
31
* @param {TreeNode} node the old selection
36
Ext.apply(this, config);
37
Ext.tree.DefaultSelectionModel.superclass.constructor.call(this);
40
Ext.extend(Ext.tree.DefaultSelectionModel, Ext.util.Observable, {
41
init : function(tree){
43
tree.getTreeEl().on("keydown", this.onKeyDown, this);
44
tree.on("click", this.onNodeClick, this);
47
onNodeClick : function(node, e){
53
* @param {TreeNode} node The node to select
54
* @return {TreeNode} The selected node
56
select : function(node){
57
var last = this.selNode;
58
if(last != node && this.fireEvent('beforeselect', this, node, last) !== false){
60
last.ui.onSelectedChange(false);
63
node.ui.onSelectedChange(true);
64
this.fireEvent("selectionchange", this, node, last);
71
* @param {TreeNode} node The node to unselect
73
unselect : function(node){
74
if(this.selNode == node){
75
this.clearSelections();
80
* Clear all selections
82
clearSelections : function(){
85
n.ui.onSelectedChange(false);
87
this.fireEvent("selectionchange", this, null);
93
* Get the selected node
94
* @return {TreeNode} The selected node
96
getSelectedNode : function(){
101
* Returns true if the node is selected
102
* @param {TreeNode} node The node to check
105
isSelected : function(node){
106
return this.selNode == node;
110
* Selects the node above the selected node in the tree, intelligently walking the nodes
111
* @return TreeNode The new selection
113
selectPrevious : function(){
114
var s = this.selNode || this.lastSelNode;
118
var ps = s.previousSibling;
120
if(!ps.isExpanded() || ps.childNodes.length < 1){
121
return this.select(ps);
123
var lc = ps.lastChild;
124
while(lc && lc.isExpanded() && lc.childNodes.length > 0){
127
return this.select(lc);
129
} else if(s.parentNode && (this.tree.rootVisible || !s.parentNode.isRoot)){
130
return this.select(s.parentNode);
136
* Selects the node above the selected node in the tree, intelligently walking the nodes
137
* @return TreeNode The new selection
139
selectNext : function(){
140
var s = this.selNode || this.lastSelNode;
144
if(s.firstChild && s.isExpanded()){
145
return this.select(s.firstChild);
146
}else if(s.nextSibling){
147
return this.select(s.nextSibling);
148
}else if(s.parentNode){
150
s.parentNode.bubble(function(){
151
if(this.nextSibling){
152
newS = this.getOwnerTree().selModel.select(this.nextSibling);
161
onKeyDown : function(e){
162
var s = this.selNode || this.lastSelNode;
163
// undesirable, but required
176
this.selectPrevious();
180
if(s.hasChildNodes()){
183
}else if(s.firstChild){
184
this.select(s.firstChild, e);
190
if(s.hasChildNodes() && s.isExpanded()){
192
}else if(s.parentNode && (this.tree.rootVisible || s.parentNode != this.tree.getRootNode())){
193
this.select(s.parentNode, e);
201
* @class Ext.tree.MultiSelectionModel
202
* @extends Ext.util.Observable
203
* Multi selection for a TreePanel.
205
Ext.tree.MultiSelectionModel = function(config){
210
* @event selectionchange
211
* Fires when the selected nodes change
212
* @param {MultiSelectionModel} this
213
* @param {Array} nodes Array of the selected nodes
217
Ext.apply(this, config);
218
Ext.tree.MultiSelectionModel.superclass.constructor.call(this);
221
Ext.extend(Ext.tree.MultiSelectionModel, Ext.util.Observable, {
222
init : function(tree){
224
tree.getTreeEl().on("keydown", this.onKeyDown, this);
225
tree.on("click", this.onNodeClick, this);
228
onNodeClick : function(node, e){
229
this.select(node, e, e.ctrlKey);
234
* @param {TreeNode} node The node to select
235
* @param {EventObject} e (optional) An event associated with the selection
236
* @param {Boolean} keepExisting True to retain existing selections
237
* @return {TreeNode} The selected node
239
select : function(node, e, keepExisting){
240
if(keepExisting !== true){
241
this.clearSelections(true);
243
if(this.isSelected(node)){
244
this.lastSelNode = node;
247
this.selNodes.push(node);
248
this.selMap[node.id] = node;
249
this.lastSelNode = node;
250
node.ui.onSelectedChange(true);
251
this.fireEvent("selectionchange", this, this.selNodes);
257
* @param {TreeNode} node The node to unselect
259
unselect : function(node){
260
if(this.selMap[node.id]){
261
node.ui.onSelectedChange(false);
262
var sn = this.selNodes;
263
var index = sn.indexOf(node);
265
this.selNodes.splice(index, 1);
267
delete this.selMap[node.id];
268
this.fireEvent("selectionchange", this, this.selNodes);
273
* Clear all selections
275
clearSelections : function(suppressEvent){
276
var sn = this.selNodes;
278
for(var i = 0, len = sn.length; i < len; i++){
279
sn[i].ui.onSelectedChange(false);
283
if(suppressEvent !== true){
284
this.fireEvent("selectionchange", this, this.selNodes);
290
* Returns true if the node is selected
291
* @param {TreeNode} node The node to check
294
isSelected : function(node){
295
return this.selMap[node.id] ? true : false;
299
* Returns an array of the selected nodes
302
getSelectedNodes : function(){
303
return this.selNodes;
306
onKeyDown : Ext.tree.DefaultSelectionModel.prototype.onKeyDown,
308
selectNext : Ext.tree.DefaultSelectionModel.prototype.selectNext,
310
selectPrevious : Ext.tree.DefaultSelectionModel.prototype.selectPrevious
b'\\ No newline at end of file'