use of com.haulmont.cuba.core.global.MessageTools in project cuba by cuba-platform.
the class DynamicAttributesCondition method getLocCaption.
@Override
public String getLocCaption() {
if (isBlank(caption) && !isBlank(propertyPath)) {
MessageTools messageTools = AppBeans.get(MessageTools.class);
String propertyCaption = messageTools.getPropertyCaption(datasource.getMetaClass(), propertyPath);
if (!isBlank(propertyCaption)) {
return propertyCaption + "." + locCaption;
}
} else if (isNotBlank(caption)) {
MessageTools messageTools = AppBeans.get(MessageTools.class);
return messageTools.loadString(messagesPack, caption);
}
MetaPropertyPath mpp = DynamicAttributesUtils.getMetaPropertyPath(datasource.getMetaClass(), getCategoryAttributeId());
if (mpp != null) {
return DynamicAttributesUtils.getCategoryAttribute(mpp.getMetaProperty()).getLocaleName();
}
return super.getLocCaption();
}
use of com.haulmont.cuba.core.global.MessageTools in project cuba by cuba-platform.
the class FilterConditionUtils method getPropertyLocCaption.
public static String getPropertyLocCaption(MetaClass metaClass, String propertyPath) {
MessageTools messageTools = AppBeans.get(MessageTools.class);
MetaPropertyPath mpp = metaClass.getPropertyPath(propertyPath);
if (mpp == null) {
return propertyPath;
} else {
MetaProperty[] metaProperties = mpp.getMetaProperties();
StringBuilder sb = new StringBuilder();
List<String> metaPropertyNames = new ArrayList<>();
for (int i = 0; i < metaProperties.length; i++) {
metaPropertyNames.add(metaProperties[i].getName());
String currentMetaPropertyPath = StringUtils.join(metaPropertyNames, ".");
sb.append(messageTools.getPropertyCaption(metaClass, currentMetaPropertyPath));
if (i < metaProperties.length - 1) {
sb.append(".");
}
}
return sb.toString();
}
}
use of com.haulmont.cuba.core.global.MessageTools in project cuba by cuba-platform.
the class PropertyConditionDescriptor method getTreeCaption.
@Override
public String getTreeCaption() {
if (!Strings.isNullOrEmpty(this.caption)) {
return locCaption;
} else {
MessageTools messageTools = AppBeans.get(MessageTools.class);
MetaPropertyPath mpp = datasourceMetaClass.getPropertyPath(name);
return mpp != null ? messageTools.getPropertyCaption(datasourceMetaClass, name) : name;
}
}
use of com.haulmont.cuba.core.global.MessageTools in project cuba by cuba-platform.
the class SizeWithUnitValidator method validate.
@Override
public void validate(Object value) throws ValidationException {
if (value == null) {
return;
}
MessageTools messages = AppBeans.get(MessageTools.NAME);
if (!(value instanceof String)) {
throw new ValidationException(messages.loadString(messagesPack, message));
}
String s = (String) value;
s = s.trim();
if ("".equals(value)) {
return;
}
Matcher matcher = Pattern.compile(SIZE_PATTERN).matcher(s);
if (!matcher.find()) {
throw new ValidationException(messages.loadString(messagesPack, message));
}
double size = Double.parseDouble(matcher.group(1));
String symbol = matcher.group(2);
if ("%".equals(symbol)) {
if (size < 1 || size > MAX_SIZE_PERCENTS) {
throw new ValidationException(messages.loadString(messagesPack, message));
}
} else if ("px".equals(symbol) || symbol == null) {
if (size < 1 || size > MAX_SIZE_PIXELS) {
throw new ValidationException(messages.loadString(messagesPack, message));
}
}
}
use of com.haulmont.cuba.core.global.MessageTools in project cuba by cuba-platform.
the class DesktopAbstractField method initRequired.
protected void initRequired(MetaPropertyPath metaPropertyPath) {
MetaProperty metaProperty = metaPropertyPath.getMetaProperty();
boolean newRequired = metaProperty.isMandatory();
Object notNullUiComponent = metaProperty.getAnnotations().get(NotNull.class.getName() + "_notnull_ui_component");
if (Boolean.TRUE.equals(notNullUiComponent)) {
newRequired = true;
}
setRequired(newRequired);
if (StringUtils.isEmpty(getRequiredMessage())) {
MessageTools messageTools = AppBeans.get(MessageTools.NAME);
setRequiredMessage(messageTools.getDefaultRequiredMessage(metaPropertyPath.getMetaClass(), metaPropertyPath.toString()));
}
}
Aggregations