}
protected ListGrid createListGrid(String className, List<Field> headerFields, ListGrid.Type type, DynamicResultSet drs,
String sectionKey, int order, String idProperty, List<SectionCrumb> sectionCrumbs) {
// Create the list grid and set some basic attributes
ListGrid listGrid = new ListGrid();
listGrid.setClassName(className);
listGrid.getHeaderFields().addAll(headerFields);
listGrid.setListGridType(type);
listGrid.setSectionCrumbs(sectionCrumbs);
listGrid.setSectionKey(sectionKey);
listGrid.setOrder(order);
listGrid.setIdProperty(idProperty);
listGrid.setStartIndex(drs.getStartIndex());
listGrid.setTotalRecords(drs.getTotalRecords());
listGrid.setPageSize(drs.getPageSize());
AdminSection section = navigationService.findAdminSectionByClass(className);
if (section != null) {
listGrid.setExternalEntitySectionKey(section.getUrl());
}
// For each of the entities (rows) in the list grid, we need to build the associated
// ListGridRecord and set the required fields on the record. These fields are the same ones
// that are used for the header fields.
for (Entity e : drs.getRecords()) {
ListGridRecord record = new ListGridRecord();
record.setListGrid(listGrid);
record.setDirty(e.isDirty());
if (e.findProperty("hasError") != null) {
Boolean hasError = Boolean.parseBoolean(e.findProperty("hasError").getValue());
record.setIsError(hasError);
record.setErrorKey("listgrid.record.error");
}
if (e.findProperty(idProperty) != null) {
record.setId(e.findProperty(idProperty).getValue());
}
for (Field headerField : headerFields) {
Property p = e.findProperty(headerField.getName());
if (p != null) {
Field recordField = new Field().withName(headerField.getName())
.withFriendlyName(headerField.getFriendlyName())
.withOrder(p.getMetadata().getOrder());
if (headerField instanceof ComboField) {
recordField.setValue(((ComboField) headerField).getOption(p.getValue()));
recordField.setDisplayValue(p.getDisplayValue());
} else {
recordField.setValue(p.getValue());
recordField.setDisplayValue(p.getDisplayValue());
}
recordField.setDerived(isDerivedField(headerField, recordField, p));
record.getFields().add(recordField);
}
}
if (e.findProperty(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY) != null) {
Field hiddenField = new Field().withName(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY);
hiddenField.setValue(e.findProperty(AdminMainEntity.MAIN_ENTITY_NAME_PROPERTY).getValue());
record.getHiddenFields().add(hiddenField);
}
if (e.findProperty(BasicPersistenceModule.ALTERNATE_ID_PROPERTY) != null) {
record.setAltId(e.findProperty(BasicPersistenceModule.ALTERNATE_ID_PROPERTY).getValue());
}
extensionManager.getProxy().modifyListGridRecord(className, record, e);
listGrid.getRecords().add(record);
}
return listGrid;
}