use of org.broadleafcommerce.openadmin.web.form.component.ListGridActionGroup in project BroadleafCommerce by BroadleafCommerce.
the class FormBuilderServiceImpl method populateEntityForm.
@Override
public void populateEntityForm(ClassMetadata cmd, Entity entity, Map<String, DynamicResultSet> collectionRecords, EntityForm ef, List<SectionCrumb> sectionCrumbs) throws ServiceException {
// Get the form with values for this entity
populateEntityForm(cmd, entity, ef, sectionCrumbs);
// Attach the sub-collection list grids and specialty UI support
for (Property p : cmd.getProperties()) {
if (p.getMetadata() instanceof BasicFieldMetadata) {
continue;
}
if (!ArrayUtils.contains(p.getMetadata().getAvailableToTypes(), entity.getType()[0])) {
continue;
}
if (collectionRecords != null) {
DynamicResultSet subCollectionEntities = collectionRecords.get(p.getName());
String containingEntityId = entity.getPMap().get(ef.getIdProperty()).getValue();
ListGrid listGrid = buildCollectionListGrid(containingEntityId, subCollectionEntities, p, ef.getSectionKey(), sectionCrumbs);
CollectionMetadata md = ((CollectionMetadata) p.getMetadata());
if (md instanceof BasicCollectionMetadata) {
PersistencePackageRequest ppr = PersistencePackageRequest.fromMetadata(md, sectionCrumbs);
ClassMetadata collectionCmd = adminEntityService.getClassMetadata(ppr).getDynamicResultSet().getClassMetaData();
if (collectionCmd.getPolymorphicEntities().getChildren().length != 0) {
List<ClassTree> entityTypes = collectionCmd.getPolymorphicEntities().getCollapsedClassTrees();
ListGridActionGroup actionGroup = new ListGridActionGroup().withName("Add");
for (ClassTree entityType : entityTypes) {
ListGridAction ADD = new ListGridAction(ListGridAction.ADD).withButtonClass(AddMethodType.PERSIST_EMPTY == ((BasicCollectionMetadata) md).getAddMethodType() ? "sub-list-grid-add-empty" : "sub-list-grid-add").withActionTargetEntity(entityType.getFullyQualifiedClassname()).withUrlPostfix("/add").withIconClass("fa fa-plus").withDisplayText(BLCMessageUtils.getMessage(entityType.getFriendlyName()));
actionGroup.getListGridActions().add(0, ADD);
}
listGrid.addToolbarActionGroup(actionGroup);
} else {
listGrid.getToolbarActions().add(0, AddMethodType.PERSIST_EMPTY == ((BasicCollectionMetadata) md).getAddMethodType() ? DefaultListGridActions.ADD_EMPTY : DefaultListGridActions.ADD);
}
} else {
listGrid.getToolbarActions().add(0, DefaultListGridActions.ADD);
}
if (subCollectionEntities.getUnselectedTabMetadata().get(md.getTab()) != null) {
ef.addListGrid(cmd, listGrid, md.getTab(), md.getTabOrder(), md.getGroup(), true);
} else {
ef.addListGrid(cmd, listGrid, md.getTab(), md.getTabOrder(), md.getGroup(), false);
}
}
}
if (CollectionUtils.isEmpty(ef.getActions())) {
ef.addAction(DefaultEntityFormActions.SAVE);
}
addDeleteActionIfAllowed(ef, cmd, entity);
setReadOnlyState(ef, cmd, entity);
// check for fields that should be hidden based on annotations
setVisibilityBasedOnShowIfFieldEquals(cmd, entity, ef);
extensionManager.getProxy().modifyDetailEntityForm(ef);
}
Aggregations