Search in sources :

Example 11 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty 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 12 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class ContainerValueSource method canUpdateMasterRefs.

protected boolean canUpdateMasterRefs() {
    MetaPropertyPath mpp = getEntityMetaClass().getPropertyPath(metaPropertyPath.toPathString());
    if (mpp == null) {
        return false;
    }
    if (!mpp.getMetaProperty().getRange().getCardinality().isMany()) {
        return false;
    }
    MetaProperty inverseProperty = mpp.getMetaProperty().getInverse();
    return inverseProperty != null && inverseProperty.getType() == MetaProperty.Type.ASSOCIATION && !inverseProperty.getRange().getCardinality().isMany();
}
Also used : MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 13 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class ValueBinder method bind.

public <V> ValueBinding<V> bind(HasValue<V> component, ValueSource<V> valueSource) {
    if (valueSource instanceof ApplicationContextAware) {
        ((ApplicationContextAware) valueSource).setApplicationContext(applicationContext);
    }
    ValueBindingImpl<V> binding = new ValueBindingImpl<>(component, valueSource);
    if (component instanceof Component.Editable) {
        ((Component.Editable) component).setEditable(!valueSource.isReadOnly());
    }
    if (valueSource instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueSource;
        MetaPropertyPath metaPropertyPath = entityValueSource.getMetaPropertyPath();
        if (component instanceof Field) {
            initRequired((Field) component, metaPropertyPath);
            initBeanValidator((Field<?>) component, metaPropertyPath);
        }
        if (entityValueSource.isDataModelSecurityEnabled()) {
            UiEntityAttributeContext attributeContext = new UiEntityAttributeContext(metaPropertyPath);
            accessManager.applyRegisteredConstraints(attributeContext);
            if (component instanceof Component.Editable) {
                MetaClass metaClass = entityValueSource.getEntityMetaClass();
                boolean permittedIfEmbedded = true;
                if (entityValueSource instanceof ContainerValueSource) {
                    InstanceContainer<?> container = ((ContainerValueSource<?, ?>) entityValueSource).getContainer();
                    if (container instanceof Nested && metaClass != null && metadataTools.isJpaEmbeddable(metaClass)) {
                        String embeddedProperty = ((Nested) container).getProperty();
                        MetaClass masterMetaClass = ((Nested) container).getMaster().getEntityMetaClass();
                        UiEntityAttributeContext embeddedAttributeContext = new UiEntityAttributeContext(masterMetaClass, embeddedProperty);
                        accessManager.applyRegisteredConstraints(embeddedAttributeContext);
                        permittedIfEmbedded = embeddedAttributeContext.canModify();
                    }
                    if (permittedIfEmbedded && metaPropertyPath.length() > 1) {
                        for (MetaProperty property : metaPropertyPath.getMetaProperties()) {
                            if (metadataTools.isEmbedded(property)) {
                                UiEntityAttributeContext childAttributeContext = new UiEntityAttributeContext(property.getDomain(), property.getName());
                                accessManager.applyRegisteredConstraints(childAttributeContext);
                                if (!childAttributeContext.canModify()) {
                                    permittedIfEmbedded = false;
                                    break;
                                }
                            }
                        }
                    }
                }
                if (!attributeContext.canModify() || !permittedIfEmbedded) {
                    ((Component.Editable) component).setEditable(false);
                }
            }
            if (!attributeContext.canView()) {
                component.setVisible(false);
            }
        }
    }
    binding.bind();
    return binding;
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) ApplicationContextAware(org.springframework.context.ApplicationContextAware) UiEntityAttributeContext(io.jmix.ui.accesscontext.UiEntityAttributeContext) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) Nested(io.jmix.ui.model.Nested) Field(io.jmix.ui.component.Field) MetaClass(io.jmix.core.metamodel.model.MetaClass) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 14 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class DataAwareComponentsTools method setupZoneId.

public void setupZoneId(DateField component, EntityValueSource valueSource) {
    if (component.getZoneId() == null) {
        MetaProperty metaProperty = valueSource.getMetaPropertyPath().getMetaProperty();
        Class javaType = metaProperty.getRange().asDatatype().getJavaClass();
        if (dateTimeTransformations.isDateTypeSupportsTimeZones(javaType)) {
            Boolean ignoreUserTimeZone = metadataTools.getMetaAnnotationValue(metaProperty, IgnoreUserTimeZone.class);
            if (!Boolean.TRUE.equals(ignoreUserTimeZone)) {
                TimeZone timeZone = currentAuthentication.getTimeZone();
                component.setTimeZone(timeZone);
            }
        }
    }
}
Also used : TimeZone(java.util.TimeZone) IgnoreUserTimeZone(io.jmix.core.entity.annotation.IgnoreUserTimeZone) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 15 with MetaProperty

use of io.jmix.core.metamodel.model.MetaProperty in project jmix by jmix-framework.

the class DataAwareComponentsTools method setupCaseConversion.

/**
 * Sets case conversion using {@link CaseConversion} annotation on entity property.
 *
 * @param component   UI component
 * @param valueSource value source
 */
public void setupCaseConversion(TextInputField.CaseConversionSupported component, EntityValueSource valueSource) {
    MetaProperty metaProperty = valueSource.getMetaPropertyPath().getMetaProperty();
    Map<String, Object> annotations = metaProperty.getAnnotations();
    String caseConversionAnnotation = CaseConversion.class.getName();
    // noinspection unchecked
    Map<String, Object> caseConversion = (Map<String, Object>) annotations.get(caseConversionAnnotation);
    if (MapUtils.isNotEmpty(caseConversion)) {
        ConversionType conversionType = (ConversionType) caseConversion.get("type");
        TextInputField.CaseConversion conversion = TextInputField.CaseConversion.valueOf(conversionType.name());
        component.setCaseConversion(conversion);
    }
}
Also used : ConversionType(io.jmix.core.entity.annotation.ConversionType) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) TextInputField(io.jmix.ui.component.TextInputField) Map(java.util.Map)

Aggregations

MetaProperty (io.jmix.core.metamodel.model.MetaProperty)267 MetaClass (io.jmix.core.metamodel.model.MetaClass)162 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)53 Nullable (javax.annotation.Nullable)36 Range (io.jmix.core.metamodel.model.Range)23 Autowired (org.springframework.beans.factory.annotation.Autowired)23 Collectors (java.util.stream.Collectors)22 java.util (java.util)20 Component (org.springframework.stereotype.Component)18 Entity (io.jmix.core.Entity)17 EntityValues (io.jmix.core.entity.EntityValues)17 io.jmix.core (io.jmix.core)16 Logger (org.slf4j.Logger)15 LoggerFactory (org.slf4j.LoggerFactory)15 ArrayList (java.util.ArrayList)12 Collection (java.util.Collection)12 EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)10 Metadata (io.jmix.core.Metadata)9 KeyValueMetaClass (io.jmix.core.impl.keyvalue.KeyValueMetaClass)9 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)8