Search in sources :

Example 1 with ListGridActionGroup

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);
}
Also used : ClassMetadata(org.broadleafcommerce.openadmin.dto.ClassMetadata) ListGridAction(org.broadleafcommerce.openadmin.web.form.component.ListGridAction) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) AdornedTargetCollectionMetadata(org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata) CollectionMetadata(org.broadleafcommerce.openadmin.dto.CollectionMetadata) ClassTree(org.broadleafcommerce.openadmin.dto.ClassTree) PersistencePackageRequest(org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest) ListGridActionGroup(org.broadleafcommerce.openadmin.web.form.component.ListGridActionGroup) ListGrid(org.broadleafcommerce.openadmin.web.form.component.ListGrid) BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) BasicCollectionMetadata(org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata) Property(org.broadleafcommerce.openadmin.dto.Property) DynamicResultSet(org.broadleafcommerce.openadmin.dto.DynamicResultSet)

Aggregations

AdornedTargetCollectionMetadata (org.broadleafcommerce.openadmin.dto.AdornedTargetCollectionMetadata)1 BasicCollectionMetadata (org.broadleafcommerce.openadmin.dto.BasicCollectionMetadata)1 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)1 ClassMetadata (org.broadleafcommerce.openadmin.dto.ClassMetadata)1 ClassTree (org.broadleafcommerce.openadmin.dto.ClassTree)1 CollectionMetadata (org.broadleafcommerce.openadmin.dto.CollectionMetadata)1 DynamicResultSet (org.broadleafcommerce.openadmin.dto.DynamicResultSet)1 Property (org.broadleafcommerce.openadmin.dto.Property)1 PersistencePackageRequest (org.broadleafcommerce.openadmin.server.domain.PersistencePackageRequest)1 ListGrid (org.broadleafcommerce.openadmin.web.form.component.ListGrid)1 ListGridAction (org.broadleafcommerce.openadmin.web.form.component.ListGridAction)1 ListGridActionGroup (org.broadleafcommerce.openadmin.web.form.component.ListGridActionGroup)1