//>>built
define("dojox/grid/enhanced/plugins/_SelectionPreserver",["dojo/_base/declare","dojo/_base/lang","dojo/_base/connect","../../_SelectionPreserver"],function(q,h,k,r){return q("dojox.grid.enhanced.plugins._SelectionPreserver",r,{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(k.connect(d,"selectRange",
h.hitch(this,"_updateMapping",!0,!0,!1)),k.connect(d,"deselectRange",h.hitch(this,"_updateMapping",!0,!1,!1)),k.connect(d,"deselectAll",h.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,g=this.grid;if(d&&g._hasIdentity){var e=g.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);g.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,g,e){var m=this.selection,f=this.grid,n=0,p=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]=!!m.selected[c]):(++p,n+=
m.selected[c]?1:-1);p&&(this._defaultSelected=0<n);b||void 0===g||void 0===e||(b=!f.usingPagination&&Math.abs(e-g+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}})});