Search in sources :

Example 1 with AttributeDefinition

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

the class DynAttrMetaPropertyPathResolver method resolveMetaPropertyPath.

@Override
public MetaPropertyPath resolveMetaPropertyPath(MetaClass metaClass, String propertyPath) {
    String[] properties = propertyPath.split("\\.");
    MetaProperty[] metaProperties = new MetaProperty[properties.length];
    MetaProperty currentProperty;
    MetaClass currentClass = metaClass;
    for (int i = 0; i < properties.length; i++) {
        if (currentClass == null) {
            return null;
        }
        currentProperty = currentClass.findProperty(properties[i]);
        if (currentProperty == null) {
            if (!DynAttrUtils.isDynamicAttributeProperty(properties[i])) {
                return null;
            }
            AttributeDefinition attribute = dynAttrMetadata.getAttributeByCode(currentClass, DynAttrUtils.getAttributeCodeFromProperty(properties[i])).orElse(null);
            if (attribute == null) {
                return null;
            }
            currentProperty = attribute.getMetaProperty();
        }
        Range range = currentProperty.getRange();
        currentClass = range.isClass() ? range.asClass() : null;
        metaProperties[i] = currentProperty;
    }
    return new MetaPropertyPath(metaClass, metaProperties);
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) AttributeDefinition(io.jmix.dynattr.AttributeDefinition) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Range(io.jmix.core.metamodel.model.Range)

Example 2 with AttributeDefinition

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

the class ListEmbeddingStrategy method getColumnFormatter.

@SuppressWarnings("rawtypes")
protected Formatter getColumnFormatter(AttributeDefinition attribute) {
    if (attribute.getDataType() == AttributeType.ENUMERATION) {
        if (!attribute.isCollection()) {
            return value -> {
                if (value == null) {
                    return null;
                } else {
                    return msgBundleTools.getLocalizedEnumeration(attribute.getEnumerationMsgBundle(), (String) value);
                }
            };
        }
    } else if (!Strings.isNullOrEmpty(attribute.getConfiguration().getNumberFormatPattern())) {
        return value -> {
            if (value == null) {
                return null;
            } else {
                DecimalFormatSymbols symbols = new DecimalFormatSymbols(currentAuthentication.getLocale());
                DecimalFormat format = new DecimalFormat(attribute.getConfiguration().getNumberFormatPattern(), symbols);
                return format.format(value);
            }
        };
    }
    return null;
}
Also used : Strings(com.google.common.base.Strings) CurrentAuthentication(io.jmix.core.security.CurrentAuthentication) Formatter(io.jmix.ui.component.formatter.Formatter) AttributeDefinition(io.jmix.dynattr.AttributeDefinition) AttributeType(io.jmix.dynattr.AttributeType) DecimalFormatSymbols(java.text.DecimalFormatSymbols) MsgBundleTools(io.jmix.dynattr.MsgBundleTools) DecimalFormat(java.text.DecimalFormat) Autowired(org.springframework.beans.factory.annotation.Autowired) DecimalFormatSymbols(java.text.DecimalFormatSymbols) DecimalFormat(java.text.DecimalFormat)

Example 3 with AttributeDefinition

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

the class DynamicAttributesPanel method addFieldsToForm.

protected void addFieldsToForm(Form newPropertiesForm, Map<AttributeDefinition, Component> fields) {
    if (fields.keySet().stream().anyMatch(attr -> attr.getConfiguration().getColumnNumber() != null && attr.getConfiguration().getRowNumber() != null)) {
        List<AttributeDefinition> attributesToAdd = fields.keySet().stream().filter(attr -> attr.getConfiguration().getColumnNumber() != null && attr.getConfiguration().getRowNumber() != null).collect(Collectors.toList());
        int maxColumnIndex = attributesToAdd.stream().mapToInt(attr -> attr.getConfiguration().getColumnNumber()).max().orElse(0);
        newPropertiesForm.setColumns(maxColumnIndex + 1);
        for (int i = 0; i <= maxColumnIndex; i++) {
            int columnIndex = i;
            List<AttributeDefinition> columnAttributes = attributesToAdd.stream().filter(attr -> columnIndex == attr.getConfiguration().getColumnNumber()).sorted(Comparator.comparing(attr -> attr.getConfiguration().getRowNumber())).collect(Collectors.toList());
            int currentRowNumber = 0;
            for (AttributeDefinition attr : columnAttributes) {
                while (attr.getConfiguration().getRowNumber() > currentRowNumber) {
                    // add empty row
                    newPropertiesForm.add(createEmptyComponent(), columnIndex, currentRowNumber);
                    currentRowNumber++;
                }
                newPropertiesForm.add(fields.get(attr), columnIndex, currentRowNumber);
                currentRowNumber++;
            }
        }
    } else {
        int propertiesCount = getAttributesByCategory().size();
        int rowsPerColumn = getRowsPerColumn(propertiesCount);
        int columnNo = 0;
        int fieldsCount = 0;
        for (Component field : fields.values()) {
            fieldsCount++;
            newPropertiesForm.add(field, columnNo);
            if (fieldsCount % rowsPerColumn == 0) {
                columnNo++;
                newPropertiesForm.setColumns(columnNo + 1);
            }
        }
    }
}
Also used : Positive(javax.validation.constraints.Positive) java.util(java.util) CategoryDefinition(io.jmix.dynattr.CategoryDefinition) StudioProperty(io.jmix.ui.meta.StudioProperty) ContainerValueSourceProvider(io.jmix.ui.component.data.value.ContainerValueSourceProvider) Autowired(org.springframework.beans.factory.annotation.Autowired) DynAttrMetadata(io.jmix.dynattr.DynAttrMetadata) ContainerValueSource(io.jmix.ui.component.data.value.ContainerValueSource) Messages(io.jmix.core.Messages) DynAttrQueryHints(io.jmix.dynattr.DynAttrQueryHints) Strings(com.google.common.base.Strings) Categorized(io.jmix.dynattr.model.Categorized) UiComponents(io.jmix.ui.UiComponents) InstanceContainer(io.jmix.ui.model.InstanceContainer) StudioComponent(io.jmix.ui.meta.StudioComponent) Category(io.jmix.dynattr.model.Category) DataLoader(io.jmix.ui.model.DataLoader) HasLoader(io.jmix.ui.model.HasLoader) Nullable(javax.annotation.Nullable) PropertyType(io.jmix.ui.meta.PropertyType) ValueSource(io.jmix.ui.component.data.ValueSource) Collectors(java.util.stream.Collectors) GuiDevelopmentException(io.jmix.ui.GuiDevelopmentException) CanvasIconSize(io.jmix.ui.meta.CanvasIconSize) AttributeDefinition(io.jmix.dynattr.AttributeDefinition) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) io.jmix.ui.component(io.jmix.ui.component) AttributeDefinition(io.jmix.dynattr.AttributeDefinition) StudioComponent(io.jmix.ui.meta.StudioComponent)

Example 4 with AttributeDefinition

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

the class AttributeDefaultValues method initDefaultAttributeValues.

public void initDefaultAttributeValues(Object entity) {
    MetaClass metaClass = metadata.getClass(entity);
    Collection<AttributeDefinition> attributes = dynAttrMetadata.getAttributes(metaClass);
    for (AttributeDefinition attribute : attributes) {
        setDefaultAttributeValue(entity, attribute, timeSource.currentTimestamp());
    }
}
Also used : MetaClass(io.jmix.core.metamodel.model.MetaClass) AttributeDefinition(io.jmix.dynattr.AttributeDefinition)

Example 5 with AttributeDefinition

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

the class AttributeDependencies method getDependentAttributes.

public Set<AttributeDefinition> getDependentAttributes(AttributeDefinition attribute) {
    Set<AttributeDefinition> dependentAttributes = new HashSet<>();
    Collection<AttributeDefinition> attributes = dynAttrMetadata.getAttributes(attribute.getMetaProperty().getDomain());
    for (AttributeDefinition currentAttribute : attributes) {
        if (currentAttribute.getConfiguration().getDependsOnAttributeCodes() != null && !currentAttribute.getConfiguration().getDependsOnAttributeCodes().isEmpty()) {
            List<AttributeDefinition> attributeDefinitions = currentAttribute.getConfiguration().getDependsOnAttributeCodes().stream().map(code -> dynAttrMetadata.getAttributeByCode(currentAttribute.getMetaProperty().getDomain(), code)).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toList());
            if (attributeDefinitions.contains(attribute)) {
                dependentAttributes.add(currentAttribute);
            }
        }
    }
    return dependentAttributes;
}
Also used : Component(org.springframework.stereotype.Component) java.util(java.util) AttributeDefinition(io.jmix.dynattr.AttributeDefinition) Autowired(org.springframework.beans.factory.annotation.Autowired) DynAttrMetadata(io.jmix.dynattr.DynAttrMetadata) Collectors(java.util.stream.Collectors) AttributeDefinition(io.jmix.dynattr.AttributeDefinition)

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