use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class KeyValueMetaClass method getPropertyPath.
@Override
public MetaPropertyPath getPropertyPath(String propertyPath) {
MetaProperty currentProperty;
currentProperty = this.getProperty(propertyPath);
if (currentProperty == null)
return null;
return new MetaPropertyPath(this, currentProperty);
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class EntityBasicPropertyDiff method getCollectionString.
private String getCollectionString(Object collection) {
if (DynamicAttributesUtils.isDynamicAttribute(propertyName)) {
Metadata metadata = AppBeans.get(Metadata.class);
com.haulmont.chile.core.model.MetaClass metaClass = metadata.getClassNN(metaClassName);
MetaPropertyPath path = DynamicAttributesUtils.getMetaPropertyPath(metaClass, propertyName);
return metadata.getTools().format(collection, path.getMetaProperty());
}
return String.valueOf(beforeValue);
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class MessageTools method getPropertyCaption.
/**
* Get localized name of an entity property. Messages pack must be located in the same package as entity.
*
* @param metaClass MetaClass containing the property
* @param propertyName property's name
* @param locale locale, if value is null locale of current user is used
* @return localized name
*/
public String getPropertyCaption(MetaClass metaClass, String propertyName, @Nullable Locale locale) {
Class originalClass = extendedEntities.getOriginalClass(metaClass);
Class<?> ownClass = originalClass != null ? originalClass : metaClass.getJavaClass();
String className = ownClass.getSimpleName();
String key = className + "." + propertyName;
String message;
if (locale == null) {
message = messages.getMessage(ownClass, key);
} else {
message = messages.getMessage(ownClass, key, locale);
}
if (!message.equals(key)) {
return message;
}
MetaPropertyPath propertyPath = metaClass.getPropertyPath(propertyName);
if (propertyPath != null) {
return getPropertyCaption(propertyPath.getMetaProperty());
} else {
return message;
}
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class WebSuggestionField method convertToTextView.
protected String convertToTextView(Object value) {
if (value == null) {
return StringUtils.EMPTY;
}
if (value instanceof Entity) {
Entity entity = (Entity) value;
if (captionMode == CaptionMode.ITEM) {
return entityConverter.convertToPresentation(entity, String.class, userSession.getLocale());
}
if (StringUtils.isNotEmpty(captionProperty)) {
MetaPropertyPath propertyPath = entity.getMetaClass().getPropertyPath(captionProperty);
if (propertyPath == null) {
throw new IllegalArgumentException(String.format("Can't find property for given caption property: %s", captionProperty));
}
return metadataTools.format(entity.getValueEx(captionProperty), propertyPath.getMetaProperty());
}
log.warn("Using StringToEntityConverter to get entity text presentation. Caption property is not defined " + "while caption mode is \"PROPERTY\"");
return entityConverter.convertToPresentation(entity, String.class, userSession.getLocale());
}
return metadataTools.format(value);
}
use of com.haulmont.chile.core.model.MetaPropertyPath in project cuba by cuba-platform.
the class WebTimeField method createDatasourceWrapper.
@Override
protected ItemWrapper createDatasourceWrapper(Datasource datasource, Collection<MetaPropertyPath> propertyPaths) {
return new ItemWrapper(datasource, datasource.getMetaClass(), propertyPaths) {
private static final long serialVersionUID = 1729450322469573679L;
@Override
protected PropertyWrapper createPropertyWrapper(Object item, MetaPropertyPath propertyPath) {
return new PropertyWrapper(item, propertyPath) {
private static final long serialVersionUID = -4481934193197224070L;
@Override
public String getFormattedValue() {
Object value = this.getValue();
if (value instanceof Date) {
SimpleDateFormat sdf = new SimpleDateFormat(timeFormat);
return sdf.format(value);
}
return super.getFormattedValue();
}
@Override
protected Object valueOf(Object newValue) throws Converter.ConversionException {
if (newValue instanceof String) {
if (StringUtils.isNotEmpty((String) newValue) && !newValue.equals(placeholder)) {
try {
SimpleDateFormat sdf = new SimpleDateFormat(timeFormat);
Date date = sdf.parse((String) newValue);
if (component.getComponentError() != null) {
component.setComponentError(null);
}
return date;
} catch (Exception e) {
LoggerFactory.getLogger(WebTimeField.class).debug("Unable to parse value of component " + getId() + "\n" + e.getMessage());
component.setComponentError(new UserError("Invalid value"));
return null;
}
} else
return null;
} else
return newValue;
}
};
}
};
}
Aggregations