public void syncModel(int offset, int limit) {
int min = offset;
int max = offset + limit - 1;
final ListModel model = _grid.getModel();
Rows rows = _grid.getRows();
final int newsz = model.getSize();
final int oldsz = rows != null ? rows.getChildren().size(): 0;
final Paginal pgi = _grid.getPaginal();
final boolean inPaging = inPagingMold();
int newcnt = newsz - oldsz;
int atg = pgi != null ? _grid.getActivePage(): 0;
RowRenderer renderer = null;
Component next = null;
if (oldsz > 0) {
if (min < 0) min = 0;
else if (min > oldsz - 1) min = oldsz - 1;
if (max < 0) max = oldsz - 1;
else if (max > oldsz - 1) max = oldsz - 1;
if (min > max) {
int t = min; min = max; max = t;
}
int cnt = max - min + 1; //# of affected
if (model instanceof GroupsListModel) {
//detach all from end to front since groupfoot
//must be detached before group
newcnt += cnt; //add affected later
if (newcnt > INVALIDATE_THRESHOLD && !inPaging)
_grid.invalidate(); //performance is better
Component comp = (Component)rows.getChildren().get(max);
next = comp.getNextSibling();
while (--cnt >= 0) {
Component p = comp.getPreviousSibling();
comp.detach();
comp = p;
}
} else { //ListModel
int addcnt = 0;
Component row = (Component)rows.getChildren().get(min);
while (--cnt >= 0) {
next = row.getNextSibling();
if (cnt < -newcnt) { //if shrink, -newcnt > 0
row.detach(); //remove extra
} else if (((LoadStatus)((AbstractComponent)row).getExtraCtrl()).isLoaded()) {
if (renderer == null)
renderer = (RowRenderer)getRealRenderer();
row.detach(); //always detach
rows.insertBefore((Row) newUnloadedItem(renderer, min), next);
++addcnt;
}
++min;
row = next;
}
if ((addcnt > INVALIDATE_THRESHOLD || addcnt + newcnt > INVALIDATE_THRESHOLD) && !inPaging)
_grid.invalidate(); //performance is better
}
} else {
min = 0;
//auto create but it means <grid model="xx"><rows/>... will fail
if (rows == null) {
rows = new Rows();
rows.setParent(_grid);
}
}
for (; --newcnt >= 0; ++min) {
if (renderer == null)
renderer = (RowRenderer) getRealRenderer();
rows.insertBefore((Row)newUnloadedItem(renderer, min), next);
}
if (pgi != null) {
if (atg >= pgi.getPageCount())
atg = pgi.getPageCount() - 1;