/*
	Copyright (c) 2004-2011, The Dojo Foundation All Rights Reserved.
	Available via Academic Free License >= 2.1 OR the modified BSD license.
	see: http://dojotoolkit.org/license for details
*/


window[esri._dojoScopeName||"dojo"]._xdResourceLoaded(function(_1,_2,_3){return {depends:[["provide","dijit.tree._dndSelector"],["require","dojo.dnd.common"],["require","dijit.tree._dndContainer"]],defineResource:function(_4,_5,_6){if(!_4._hasResource["dijit.tree._dndSelector"]){_4._hasResource["dijit.tree._dndSelector"]=true;_4.provide("dijit.tree._dndSelector");_4.require("dojo.dnd.common");_4.require("dijit.tree._dndContainer");_4.declare("dijit.tree._dndSelector",_5.tree._dndContainer,{constructor:function(_7,_8){this.selection={};this.anchor=null;_5.setWaiState(this.tree.domNode,"multiselect",!this.singular);this.events.push(_4.connect(this.tree.domNode,"onmousedown",this,"onMouseDown"),_4.connect(this.tree.domNode,"onmouseup",this,"onMouseUp"),_4.connect(this.tree.domNode,"onmousemove",this,"onMouseMove"));},singular:false,getSelectedTreeNodes:function(){var _9=[],_a=this.selection;for(var i in _a){_9.push(_a[i]);}return _9;},selectNone:function(){this.setSelection([]);return this;},destroy:function(){this.inherited(arguments);this.selection=this.anchor=null;},addTreeNode:function(_b,_c){this.setSelection(this.getSelectedTreeNodes().concat([_b]));if(_c){this.anchor=_b;}return _b;},removeTreeNode:function(_d){this.setSelection(this._setDifference(this.getSelectedTreeNodes(),[_d]));return _d;},isTreeNodeSelected:function(_e){return _e.id&&!!this.selection[_e.id];},setSelection:function(_f){var _10=this.getSelectedTreeNodes();_4.forEach(this._setDifference(_10,_f),_4.hitch(this,function(_11){_11.setSelected(false);if(this.anchor==_11){delete this.anchor;}delete this.selection[_11.id];}));_4.forEach(this._setDifference(_f,_10),_4.hitch(this,function(_12){_12.setSelected(true);this.selection[_12.id]=_12;}));this._updateSelectionProperties();},_setDifference:function(xs,ys){_4.forEach(ys,function(y){y.__exclude__=true;});var ret=_4.filter(xs,function(x){return !x.__exclude__;});_4.forEach(ys,function(y){delete y["__exclude__"];});return ret;},_updateSelectionProperties:function(){var _13=this.getSelectedTreeNodes();var _14=[],_15=[];_4.forEach(_13,function(_16){_15.push(_16);_14.push(_16.getTreePath());});var _17=_4.map(_15,function(_18){return _18.item;});this.tree._set("paths",_14);this.tree._set("path",_14[0]||[]);this.tree._set("selectedNodes",_15);this.tree._set("selectedNode",_15[0]||null);this.tree._set("selectedItems",_17);this.tree._set("selectedItem",_17[0]||null);},onMouseDown:function(e){if(!this.current||this.tree.isExpandoNode(e.target,this.current)){return;}if(e.button==_4.mouseButtons.RIGHT){return;}_4.stopEvent(e);var _19=this.current,_1a=_4.isCopyKey(e),id=_19.id;if(!this.singular&&!e.shiftKey&&this.selection[id]){this._doDeselect=true;return;}else{this._doDeselect=false;}this.userSelect(_19,_1a,e.shiftKey);},onMouseUp:function(e){if(!this._doDeselect){return;}this._doDeselect=false;this.userSelect(this.current,_4.isCopyKey(e),e.shiftKey);},onMouseMove:function(e){this._doDeselect=false;},userSelect:function(_1b,_1c,_1d){if(this.singular){if(this.anchor==_1b&&_1c){this.selectNone();}else{this.setSelection([_1b]);this.anchor=_1b;}}else{if(_1d&&this.anchor){var cr=_5.tree._compareNodes(this.anchor.rowNode,_1b.rowNode),_1e,end,_1f=this.anchor;if(cr<0){_1e=_1f;end=_1b;}else{_1e=_1b;end=_1f;}nodes=[];while(_1e!=end){nodes.push(_1e);_1e=this.tree._getNextNode(_1e);}nodes.push(end);this.setSelection(nodes);}else{if(this.selection[_1b.id]&&_1c){this.removeTreeNode(_1b);}else{if(_1c){this.addTreeNode(_1b,true);}else{this.setSelection([_1b]);this.anchor=_1b;}}}}},forInSelectedItems:function(f,o){o=o||_4.global;for(var id in this.selection){f.call(o,this.getItem(id),id,this);}}});}}};});