BasicCollectionMetadata fmd = (BasicCollectionMetadata) md;
// When adding items to basic collections, we will sometimes show a form to persist a new record
// and sometimes show a list grid to allow the user to associate an existing record.
if (fmd.getAddMethodType().equals(AddMethodType.PERSIST)) {
ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
if (entityForm == null) {
entityForm = formService.createEntityForm(collectionMetadata,sectionCrumbs);
entityForm.setCeilingEntityClassname(ppr.getCeilingEntityClassname());
entityForm.setEntityType(ppr.getCeilingEntityClassname());
} else {
formService.populateEntityForm(collectionMetadata, entityForm, sectionCrumbs);
formService.populateEntityFormFieldValues(collectionMetadata, entity, entityForm);
}
formService.removeNonApplicableFields(collectionMetadata, entityForm, ppr.getCeilingEntityClassname());
entityForm.getTabs().iterator().next().getIsVisible();
model.addAttribute("entityForm", entityForm);
model.addAttribute("viewType", "modal/simpleAddEntity");
} else {
DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
ListGrid listGrid = formService.buildCollectionListGrid(id, drs, collectionProperty, sectionKey, sectionCrumbs);
listGrid.setPathOverride(request.getRequestURL().toString());
model.addAttribute("listGrid", listGrid);
model.addAttribute("viewType", "modal/simpleSelectEntity");
}
} else if (md instanceof AdornedTargetCollectionMetadata) {
AdornedTargetCollectionMetadata fmd = (AdornedTargetCollectionMetadata) md;
// Even though this field represents an adorned target collection, the list we want to show in the modal
// is the standard list grid for the target entity of this field
ppr.setOperationTypesOverride(null);
ppr.setType(PersistencePackageRequest.Type.STANDARD);
ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
DynamicResultSet drs = service.getRecords(ppr).getDynamicResultSet();
ListGrid listGrid = formService.buildMainListGrid(drs, collectionMetadata, sectionKey, sectionCrumbs);
listGrid.setSubCollectionFieldName(collectionField);
listGrid.setPathOverride(request.getRequestURL().toString());
listGrid.setFriendlyName(collectionMetadata.getPolymorphicEntities().getFriendlyName());
if (entityForm == null) {
entityForm = formService.buildAdornedListForm(fmd, ppr.getAdornedList(), id);
} else {
formService.buildAdornedListForm(fmd, ppr.getAdornedList(), id, entityForm);
formService.populateEntityFormFieldValues(collectionMetadata, entity, entityForm);
}
listGrid.setListGridType(ListGrid.Type.ADORNED);
for (Entry<String, Field> entry : entityForm.getFields().entrySet()) {
if (entry.getValue().getIsVisible()) {
listGrid.setListGridType(ListGrid.Type.ADORNED_WITH_FORM);
break;
}
}
model.addAttribute("listGrid", listGrid);
model.addAttribute("entityForm", entityForm);
model.addAttribute("viewType", "modal/adornedSelectEntity");
} else if (md instanceof MapMetadata) {
MapMetadata fmd = (MapMetadata) md;
ClassMetadata collectionMetadata = service.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
if (entityForm == null) {
entityForm = formService.buildMapForm(fmd, ppr.getMapStructure(), collectionMetadata, id);
} else {
formService.buildMapForm(fmd, ppr.getMapStructure(), collectionMetadata, id, entityForm);