//>>built
define("dojox/grid/enhanced/plugins/_SelectionPreserver",["dojo/_base/declare","dojo/_base/lang","dojo/_base/connect","../../_SelectionPreserver"],function(n,g,h,p){return n("dojox.grid.enhanced.plugins._SelectionPreserver",p,{constructor:function(d){var a=this.grid;a.onSelectedById=this.onSelectedById;this._oldClearData=a._clearData;var b=this;a._clearData=function(){b._updateMapping(!a._noInternalMapping);b._trustSelection=[];b._oldClearData.apply(a,arguments)};this._connects.push(h.connect(d,"selectRange",
g.hitch(this,"_updateMapping",!0,!0,!1)),h.connect(d,"deselectRange",g.hitch(this,"_updateMapping",!0,!1,!1)),h.connect(d,"deselectAll",g.hitch(this,"_updateMapping",!0,!1,!0)))},destroy:function(){this.inherited(arguments);this.grid._clearData=this._oldClearData},reset:function(){this.inherited(arguments);this._idMap=[];this._trustSelection=[];this._defaultSelected=!1},_reSelectById:function(d,a){var b=this.selection,k=this.grid;if(d&&k._hasIdentity){var e=k.store.getIdentity(d);void 0===this._selectedById[e]?
this._trustSelection[a]||(b.selected[a]=this._defaultSelected):b.selected[a]=this._selectedById[e];this._idMap.push(e);k.onSelectedById(e,a,b.selected[a])}},_selectById:function(d,a){this.inherited(arguments)||(this._trustSelection[a]=!0)},onSelectedById:function(d,a,b){},_updateMapping:function(d,a,b,k,e){var g=this.selection,f=this.grid,h=0,m=0,c,l;for(c=f.rowCount-1;0<=c;--c)f._by_idx[c]?(l=f._by_idx[c].idty)&&(d||void 0===this._selectedById[l])&&(this._selectedById[l]=!!g.selected[c]):(++m,h+=
g.selected[c]?1:-1);m&&(this._defaultSelected=0<h);b||void 0===k||void 0===e||(b=!f.usingPagination&&Math.abs(e-k+1)===f.rowCount);if(b&&(!f.usingPagination||"single"===f.selectionMode))for(c=this._idMap.length-1;0<=c;--c)this._selectedById[this._idMap[c]]=a}})});