protected void didUpdate() {
}
protected void setupPhase() {
WODisplayGroup dg = displayGroup();
if (dg != null) {
NSArray sortOrderings = dg.sortOrderings();
EODataSource ds = dataSource();
if (!_hasBeenInitialized) {
log.debug("Initializing display group");
String fetchspecName = (String) d2wContext().valueForKey("restrictingFetchSpecification");
if (fetchspecName != null) {
if (ds instanceof EODatabaseDataSource) {
EOFetchSpecification fs = ((EODatabaseDataSource) ds).entity().fetchSpecificationNamed(fetchspecName);
if (fs != null) {
fs = (EOFetchSpecification) fs.clone();
}
((EODatabaseDataSource) ds).setFetchSpecification(fs);
}
}
if (sortOrderings == null) {
sortOrderings = sortOrderings();
setSortOrderingsOnDisplayGroup(sortOrderings, dg);
}
dg.setNumberOfObjectsPerBatch(numberOfObjectsPerBatch());
_fetchDisplayGroup(dg);
dg.updateDisplayedObjects();
_hasBeenInitialized = true;
_hasToUpdate = false;
}
// AK: if we have a DB datasource, then we might want to refetch if
// the sort ordering changed
// because if we have a fetch limit then the displayed matches on
// the first page come from the
// results, not from the real order in the DB. Set
// "alwaysRefetchList" to false in your
// rules to prevent that.
// In addition, we need to refetch if we use a batching display
// group, as the sort ordering is
// always applied from the DB.
if ((sortOrderings != null) && (ds instanceof EODatabaseDataSource)) {
EOFetchSpecification fs = ((EODatabaseDataSource) ds).fetchSpecification();
if (!fs.sortOrderings().equals(sortOrderings) && (fs.fetchLimit() != 0 || useBatchingDisplayGroup())) {
fs.setSortOrderings(sortOrderings);
_hasToUpdate = _hasToUpdate ? true : alwaysRefetchList();
}
}
// this will have the side effect of resetting the batch # to sth
// correct, in case
// the current index if out of range
log.debug("dg.currentBatchIndex() " + dg.currentBatchIndex());
dg.setCurrentBatchIndex(dg.currentBatchIndex());
if (listSize() > 0 && displayGroup().selectsFirstObjectAfterFetch()) {
d2wContext().takeValueForKey(dg.allObjects().objectAtIndex(0), "object");
}
}
}