Search in sources :

Example 11 with AttributeDefinition

use of io.jmix.dynattr.AttributeDefinition in project jmix by jmix-framework.

the class FieldGroupLoader method loadDynamicAttributeFields.

protected List<FieldGroup.FieldConfig> loadDynamicAttributeFields(Datasource ds) {
    if (ds != null && getMetadataTools().isJpaEntity(ds.getMetaClass())) {
        String windowId = getWindowId(context);
        Set<AttributeDefinition> attributes = getDynamicAttributesGuiTools().getAttributesToShowOnTheScreen(ds.getMetaClass(), windowId, resultComponent.getId());
        if (!attributes.isEmpty()) {
            List<FieldGroup.FieldConfig> fields = new ArrayList<>();
            ds.setLoadDynamicAttributes(true);
            for (AttributeDefinition attribute : attributes) {
                FieldGroup.FieldConfig field = resultComponent.createField(DynAttrUtils.getPropertyFromAttributeCode(attribute.getCode()));
                field.setProperty(DynAttrUtils.getPropertyFromAttributeCode(attribute.getCode()));
                field.setCaption(getMessageBundleTools().getLocalizedValue(attribute.getNameMsgBundle(), attribute.getName()));
                field.setDescription(getMessageBundleTools().getLocalizedValue(attribute.getDescriptionsMsgBundle(), attribute.getDescription()));
                field.setDatasource(ds);
                field.setRequired(attribute.isRequired());
                field.setRequiredMessage(getMessages().formatMessage("", "validation.required.defaultMsg", getMessageBundleTools().getLocalizedValue(attribute.getNameMsgBundle(), attribute.getName())));
                loadWidth(field, attribute.getConfiguration().getFormWidth());
                if (!Boolean.TRUE.equals(attribute.isCollection())) {
                    Collection<Consumer<?>> validators = getDynamicAttributesGuiTools().createValidators(attribute);
                    if (validators != null && !validators.isEmpty()) {
                        for (Consumer<?> validator : validators) {
                            field.addValidator(validator);
                        }
                    }
                }
                fields.add(field);
            }
            getDynamicAttributesGuiTools().listenDynamicAttributesChanges(ds);
            return fields;
        }
    }
    return Collections.emptyList();
}
Also used : Consumer(java.util.function.Consumer) FieldGroup(com.haulmont.cuba.gui.components.FieldGroup) AttributeDefinition(io.jmix.dynattr.AttributeDefinition)

Example 12 with AttributeDefinition

use of io.jmix.dynattr.AttributeDefinition in project jmix by jmix-framework.

the class DynAttrPropertyFilterComponentGenerationStrategy method createComponentInternal.

@Override
protected Component createComponentInternal(ComponentGenerationContext context, MetaClass metaClass, String propertyName) {
    AttributeDefinition attribute = dynamicModelMetadata.getAttributeByCode(metaClass, DynAttrUtils.getAttributeCodeFromProperty(propertyName)).orElse(null);
    if (attribute == null) {
        return null;
    }
    PropertyFilterComponentGenerationContext pfContext = (PropertyFilterComponentGenerationContext) context;
    PropertyFilter.Operation.Type type = pfContext.getOperation().getType();
    Component resultComponent;
    if (type == PropertyFilter.Operation.Type.UNARY) {
        resultComponent = createUnaryField(context);
    } else if (attribute.isCollection() || type == PropertyFilter.Operation.Type.LIST) {
        resultComponent = createCollectionField(context, attribute);
    } else if (attribute.getDataType() == ENTITY) {
        resultComponent = createClassField(context, attribute);
    } else if (type == PropertyFilter.Operation.Type.INTERVAL) {
        resultComponent = createIntervalField(context);
    } else {
        resultComponent = createDatatypeField(context, attribute);
    }
    return resultComponent;
}
Also used : AttributeDefinition(io.jmix.dynattr.AttributeDefinition) PropertyFilterComponentGenerationContext(io.jmix.ui.component.factory.PropertyFilterComponentGenerationContext)

Example 13 with AttributeDefinition

use of io.jmix.dynattr.AttributeDefinition in project jmix by jmix-framework.

the class DynamicAttributesPanel method initPropertiesForm.

protected void initPropertiesForm() {
    propertiesForm.removeAll();
    Map<AttributeDefinition, Component> fields = new HashMap<>();
    for (AttributeDefinition attribute : getAttributesByCategory()) {
        Component resultComponent = generateFieldComponent(attribute);
        fields.put(attribute, resultComponent);
    }
    addFieldsToForm(propertiesForm, fields);
    initFieldCaptionWidth(propertiesForm);
}
Also used : AttributeDefinition(io.jmix.dynattr.AttributeDefinition) StudioComponent(io.jmix.ui.meta.StudioComponent)

Aggregations

AttributeDefinition (io.jmix.dynattr.AttributeDefinition)13 MetaClass (io.jmix.core.metamodel.model.MetaClass)3 DynAttrMetadata (io.jmix.dynattr.DynAttrMetadata)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Strings (com.google.common.base.Strings)2 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)2 MsgBundleTools (io.jmix.dynattr.MsgBundleTools)2 StudioComponent (io.jmix.ui.meta.StudioComponent)2 java.util (java.util)2 Collectors (java.util.stream.Collectors)2 Op (com.haulmont.cuba.core.global.filter.Op)1 FieldGroup (com.haulmont.cuba.gui.components.FieldGroup)1 ConditionParamBuilder (com.haulmont.cuba.gui.components.filter.ConditionParamBuilder)1 Param (com.haulmont.cuba.gui.components.filter.Param)1 MessageTools (io.jmix.core.MessageTools)1 Messages (io.jmix.core.Messages)1 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)1 Range (io.jmix.core.metamodel.model.Range)1 CurrentAuthentication (io.jmix.core.security.CurrentAuthentication)1 AttributeType (io.jmix.dynattr.AttributeType)1