private void initialize() {
if (queryResult == null) {
queryResult = new QueryResult();
Query query = new Query(queryResult);
IDataSource dataSource = getDataSource();
int oldItemCount = realItemCount;
// query for items
dataSource.query(wrapQuery(query), queryResult);
// process the QueryResult
queryResult.process(dataSource);
// check for situation when we didn't get any items, but we know the real count
// this is not a case when there are no items at all, just the case when there are no items on current page
// but possible items on previous pages
if (queryResult.itemCache.size() == 0 && realItemCount != UNKOWN_COUNT &&
realItemCount != oldItemCount && realItemCount > 0) {
// the data must have changed, the number of items has been reduced. try move to
// last page
int page = getPageCount() - 1;
if (page < 0) {
page = 0;
}
setCurrentPage(page);
// try reloading the items
queryResult = new QueryResult();
query = new Query(queryResult);
// query for items
dataSource.query(query, queryResult);
// process the QueryResult
queryResult.process(dataSource);
}
else if (realItemCount == 0)