Search in sources :

Example 1 with AdminPresentationDataDrivenEnumeration

use of org.broadleafcommerce.common.presentation.AdminPresentationDataDrivenEnumeration in project BroadleafCommerce by BroadleafCommerce.

the class BasicFieldMetadataProvider method buildAdminPresentationDataDrivenEnumerationOverride.

protected void buildAdminPresentationDataDrivenEnumerationOverride(Map<String, FieldMetadata> mergedProperties, Map<String, AdminPresentationDataDrivenEnumerationOverride> presentationOverrides, String propertyName, String key) {
    AdminPresentationDataDrivenEnumerationOverride override = presentationOverrides.get(propertyName);
    if (override != null) {
        AdminPresentationDataDrivenEnumeration annot = override.value();
        if (annot != null) {
            if (!(mergedProperties.get(key) instanceof BasicFieldMetadata)) {
                return;
            }
            BasicFieldMetadata metadata = (BasicFieldMetadata) mergedProperties.get(key);
            metadata.setFieldType(SupportedFieldType.DATA_DRIVEN_ENUMERATION);
            metadata.setExplicitFieldType(SupportedFieldType.DATA_DRIVEN_ENUMERATION);
            metadata.setOptionListEntity(annot.optionListEntity().getName());
            metadata.setHideEnumerationIfEmpty(annot.optionHideIfEmpty());
            if (metadata.getOptionListEntity().equals(DataDrivenEnumerationValueImpl.class.getName())) {
                metadata.setOptionValueFieldName("key");
                metadata.setOptionDisplayFieldName("display");
            } else if (metadata.getOptionListEntity() == null && (StringUtils.isEmpty(metadata.getOptionValueFieldName()) || StringUtils.isEmpty(metadata.getOptionDisplayFieldName()))) {
                throw new IllegalArgumentException("Problem setting up data driven enumeration for (" + propertyName + "). The optionListEntity, optionValueFieldName and optionDisplayFieldName properties must all be included if not using DataDrivenEnumerationValueImpl as the optionListEntity.");
            } else {
                metadata.setOptionValueFieldName(annot.optionValueFieldName());
                metadata.setOptionDisplayFieldName(annot.optionDisplayFieldName());
            }
            if (!ArrayUtils.isEmpty(annot.optionFilterParams())) {
                String[][] params = new String[annot.optionFilterParams().length][3];
                for (int j = 0; j < params.length; j++) {
                    params[j][0] = annot.optionFilterParams()[j].param();
                    params[j][1] = annot.optionFilterParams()[j].value();
                    params[j][2] = String.valueOf(annot.optionFilterParams()[j].paramType());
                }
                metadata.setOptionFilterParams(params);
            } else {
                metadata.setOptionFilterParams(new String[][] {});
            }
            if (!StringUtils.isEmpty(metadata.getOptionListEntity())) {
                buildDataDrivenEnumList(metadata);
            }
        }
    }
}
Also used : BasicFieldMetadata(org.broadleafcommerce.openadmin.dto.BasicFieldMetadata) AdminPresentationDataDrivenEnumerationOverride(org.broadleafcommerce.common.presentation.override.AdminPresentationDataDrivenEnumerationOverride) AdminPresentationDataDrivenEnumeration(org.broadleafcommerce.common.presentation.AdminPresentationDataDrivenEnumeration) DataDrivenEnumerationValueImpl(org.broadleafcommerce.common.enumeration.domain.DataDrivenEnumerationValueImpl)

Aggregations

DataDrivenEnumerationValueImpl (org.broadleafcommerce.common.enumeration.domain.DataDrivenEnumerationValueImpl)1 AdminPresentationDataDrivenEnumeration (org.broadleafcommerce.common.presentation.AdminPresentationDataDrivenEnumeration)1 AdminPresentationDataDrivenEnumerationOverride (org.broadleafcommerce.common.presentation.override.AdminPresentationDataDrivenEnumerationOverride)1 BasicFieldMetadata (org.broadleafcommerce.openadmin.dto.BasicFieldMetadata)1