use of com.haulmont.chile.core.model.Range in project cuba by cuba-platform.
the class DesktopAbstractTextField method validateRawValue.
protected Object validateRawValue(String rawValue) {
if (trimming && rawValue != null)
rawValue = rawValue.trim();
if ((datasource != null) && (metaPropertyPath != null)) {
Range range = metaProperty.getRange();
if (range.isDatatype())
datatype = metaPropertyPath.getRange().asDatatype();
if (range.isClass())
return prevValue;
if (range.isEnum()) {
try {
return range.asEnumeration().parse(rawValue, locale);
} catch (ParseException e) {
showValidationMessage();
return prevValue;
}
}
}
if (datatype != null) {
try {
// double conversion to verify type constraints
// used for properly parsing BigDecimal values
Object datatypeValue = datatype.parse(rawValue, locale);
String formattedValue;
if (valueFormatter.getFormatter() == null) {
formattedValue = datatype.format(datatypeValue, locale);
} else {
formattedValue = valueFormatter.getFormatter().format(datatypeValue);
}
return datatype.parse(formattedValue, locale);
} catch (ParseException ignored) {
showValidationMessage();
return prevValue;
}
}
return rawValue;
}
use of com.haulmont.chile.core.model.Range in project cuba by cuba-platform.
the class CollectionDsHelper method createProperties.
public static List<MetaPropertyPath> createProperties(View view, MetaClass metaClass) {
List<MetaPropertyPath> properties = new ArrayList<>();
MetadataTools metadataTools = AppBeans.get(MetadataTools.NAME);
if (view != null && metadataTools.isPersistent(metaClass)) {
for (ViewProperty property : view.getProperties()) {
final String name = property.getName();
final MetaProperty metaProperty = metaClass.getProperty(name);
if (metaProperty == null) {
String message = String.format("Unable to find property %s for entity %s", name, metaClass.getName());
throw new DevelopmentException(message);
}
if (!metadataTools.isPersistent(metaProperty)) {
String message = String.format("Specified transient property %s in view for datasource with persistent entity %s", name, metaClass.getName());
LoggerFactory.getLogger(CollectionDsHelper.class).warn(message);
continue;
}
final Range range = metaProperty.getRange();
if (range == null) {
continue;
}
final Range.Cardinality cardinality = range.getCardinality();
if (!cardinality.isMany()) {
properties.add(new MetaPropertyPath(metaClass, metaProperty));
}
}
// add all non-persistent properties
for (MetaProperty metaProperty : metaClass.getProperties()) {
if (metadataTools.isNotPersistent(metaProperty)) {
properties.add(new MetaPropertyPath(metaClass, metaProperty));
}
}
} else {
if (view != null) {
LoggerFactory.getLogger(CollectionDsHelper.class).warn("Specified view {} for datasource with not persistent entity {}", view.getName(), metaClass.getName());
}
for (MetaProperty metaProperty : metaClass.getProperties()) {
final Range range = metaProperty.getRange();
if (range == null)
continue;
final Range.Cardinality cardinality = range.getCardinality();
if (!cardinality.isMany()) {
properties.add(new MetaPropertyPath(metaClass, metaProperty));
}
}
}
return properties;
}
use of com.haulmont.chile.core.model.Range in project cuba by cuba-platform.
the class AbstractComponentGenerationStrategy method createComponentInternal.
protected Component createComponentInternal(ComponentGenerationContext context) {
MetaClass metaClass = context.getMetaClass();
MetaPropertyPath mpp = resolveMetaPropertyPath(metaClass, context.getProperty());
Element xmlDescriptor = context.getXmlDescriptor();
if (mpp != null) {
Range mppRange = mpp.getRange();
if (mppRange.isDatatype()) {
Class type = mppRange.asDatatype().getJavaClass();
MetaProperty metaProperty = mpp.getMetaProperty();
if (DynamicAttributesUtils.isDynamicAttribute(metaProperty)) {
CategoryAttribute categoryAttribute = DynamicAttributesUtils.getCategoryAttribute(metaProperty);
if (categoryAttribute != null && categoryAttribute.getDataType() == PropertyType.ENUMERATION) {
return createEnumField(context);
}
}
if (xmlDescriptor != null && "true".equalsIgnoreCase(xmlDescriptor.attributeValue("link"))) {
return createDatatypeLinkField(context);
} else {
boolean hasMaskAttribute = xmlDescriptor != null && xmlDescriptor.attribute("mask") != null;
if (type.equals(String.class)) {
if (hasMaskAttribute) {
return createMaskedField(context);
} else {
return createStringField(context, mpp);
}
} else if (type.equals(UUID.class)) {
return createUuidField(context);
} else if (type.equals(Boolean.class)) {
return createBooleanField(context);
} else if (type.equals(java.sql.Date.class) || type.equals(Date.class)) {
return createDateField(context);
} else if (type.equals(Time.class)) {
return createTimeField(context);
} else if (Number.class.isAssignableFrom(type)) {
if (hasMaskAttribute) {
return createMaskedField(context);
} else {
Field currencyField = createCurrencyField(context, mpp);
if (currencyField != null) {
return currencyField;
}
return createNumberField(context);
}
}
}
} else if (mppRange.isClass()) {
MetaProperty metaProperty = mpp.getMetaProperty();
Class<?> javaType = metaProperty.getJavaType();
if (FileDescriptor.class.isAssignableFrom(javaType)) {
return createFileUploadField(context);
}
if (!Collection.class.isAssignableFrom(javaType)) {
return createEntityField(context, mpp);
}
} else if (mppRange.isEnum()) {
return createEnumField(context);
}
}
return null;
}
use of com.haulmont.chile.core.model.Range in project cuba by cuba-platform.
the class DomainModelBuilder method addProperty.
private void addProperty(EntityBuilder builder, MetaClass metaClass, MetaProperty prop) {
String name = prop.getName();
String userFriendlyName = null;
if (loadCaptions) {
userFriendlyName = messageTools.getPropertyCaption(metaClass, prop.getName());
}
boolean isEmbedded = metadataTools.isEmbedded(prop);
MetaProperty.Type type = prop.getType();
Class<?> javaType = prop.getJavaType();
Range range = prop.getRange();
switch(type) {
case COMPOSITION:
case ASSOCIATION:
if (range.isClass()) {
MetaClass rangeClass = range.asClass();
if (range.getCardinality().isMany()) {
builder.addCollectionReferenceAttribute(name, rangeClass.getName(), userFriendlyName);
} else {
builder.addReferenceAttribute(name, rangeClass.getName(), userFriendlyName, isEmbedded);
}
} else {
builder.addSingleValueAttribute(javaType, name, userFriendlyName);
}
break;
case ENUM:
// todo
builder.addSingleValueAttribute(javaType, name, userFriendlyName);
break;
case DATATYPE:
builder.addSingleValueAttribute(javaType, name, userFriendlyName);
break;
}
}
use of com.haulmont.chile.core.model.Range in project cuba by cuba-platform.
the class AttributeSecuritySupport method setNullPropertyValue.
protected void setNullPropertyValue(Entity entity, MetaProperty property) {
// Using reflective access to field because the attribute can be unfetched if loading not partial entities,
// which is the case when in-memory constraints exist
Range range = property.getRange();
if (range.isClass()) {
Object nullValue = null;
if (range.getCardinality().isMany()) {
Class<?> propertyType = property.getJavaType();
if (List.class.isAssignableFrom(propertyType)) {
nullValue = new ArrayList<>();
} else if (Set.class.isAssignableFrom(propertyType)) {
nullValue = new LinkedHashSet<>();
}
}
BaseEntityInternalAccess.setValue(entity, property.getName(), nullValue);
BaseEntityInternalAccess.setValueForHolder(entity, property.getName(), nullValue);
} else {
BaseEntityInternalAccess.setValue(entity, property.getName(), null);
}
}
Aggregations