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);
}
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();
}
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;
}
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);
}
}
}
}
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);
}
}
Aggregations