Search in sources :

Example 1 with CustomFieldGenerator

use of com.haulmont.cuba.gui.components.FieldGroup.CustomFieldGenerator in project cuba by cuba-platform.

the class FieldGroupLoader method loadDynamicAttributeFields.

protected List<FieldGroup.FieldConfig> loadDynamicAttributeFields(Datasource ds) {
    if (ds != null && metadataTools.isPersistent(ds.getMetaClass())) {
        String windowId = ComponentsHelper.getWindow(resultComponent).getId();
        Set<CategoryAttribute> attributesToShow = dynamicAttributesGuiTools.getAttributesToShowOnTheScreen(ds.getMetaClass(), windowId, resultComponent.getId());
        if (!attributesToShow.isEmpty()) {
            List<FieldGroup.FieldConfig> fields = new ArrayList<>();
            ds.setLoadDynamicAttributes(true);
            for (CategoryAttribute attribute : attributesToShow) {
                FieldGroup.FieldConfig field = resultComponent.createField(DynamicAttributesUtils.encodeAttributeCode(attribute.getCode()));
                field.setProperty(DynamicAttributesUtils.encodeAttributeCode(attribute.getCode()));
                field.setCaption(attribute.getLocaleName());
                field.setDatasource(ds);
                field.setRequired(attribute.getRequired());
                field.setRequiredMessage(messages.formatMainMessage("validation.required.defaultMsg", attribute.getLocaleName()));
                loadWidth(field, attribute.getWidth());
                // Currently, ListEditor does not support datasource binding so we create custom field
                if (BooleanUtils.isTrue(attribute.getIsCollection())) {
                    CustomFieldGenerator fieldGenerator = new DynamicAttributeCustomFieldGenerator();
                    Component fieldComponent = fieldGenerator.generateField(ds, DynamicAttributesUtils.encodeAttributeCode(attribute.getCode()));
                    field.setCustom(true);
                    field.setComponent(fieldComponent);
                    applyPermissions(fieldComponent);
                }
                fields.add(field);
            }
            dynamicAttributesGuiTools.listenDynamicAttributesChanges(ds);
            return fields;
        }
    }
    return Collections.emptyList();
}
Also used : CategoryAttribute(com.haulmont.cuba.core.entity.CategoryAttribute) DynamicAttributeCustomFieldGenerator(com.haulmont.cuba.gui.dynamicattributes.DynamicAttributeCustomFieldGenerator) DynamicAttributeCustomFieldGenerator(com.haulmont.cuba.gui.dynamicattributes.DynamicAttributeCustomFieldGenerator) CustomFieldGenerator(com.haulmont.cuba.gui.components.FieldGroup.CustomFieldGenerator)

Aggregations

CategoryAttribute (com.haulmont.cuba.core.entity.CategoryAttribute)1 CustomFieldGenerator (com.haulmont.cuba.gui.components.FieldGroup.CustomFieldGenerator)1 DynamicAttributeCustomFieldGenerator (com.haulmont.cuba.gui.dynamicattributes.DynamicAttributeCustomFieldGenerator)1