Search in sources :

Example 1 with MessageTools

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();
}
Also used : MessageTools(com.haulmont.cuba.core.global.MessageTools) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 2 with MessageTools

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();
    }
}
Also used : MessageTools(com.haulmont.cuba.core.global.MessageTools) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) ArrayList(java.util.ArrayList) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 3 with MessageTools

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;
    }
}
Also used : MessageTools(com.haulmont.cuba.core.global.MessageTools) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath)

Example 4 with MessageTools

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));
        }
    }
}
Also used : MessageTools(com.haulmont.cuba.core.global.MessageTools) ValidationException(com.haulmont.cuba.gui.components.ValidationException) Matcher(java.util.regex.Matcher)

Example 5 with MessageTools

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()));
    }
}
Also used : MessageTools(com.haulmont.cuba.core.global.MessageTools) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Aggregations

MessageTools (com.haulmont.cuba.core.global.MessageTools)7 MetaProperty (com.haulmont.chile.core.model.MetaProperty)3 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)3 MetaClass (com.haulmont.chile.core.model.MetaClass)1 ValidationException (com.haulmont.cuba.gui.components.ValidationException)1 WeakItemChangeListener (com.haulmont.cuba.gui.data.impl.WeakItemChangeListener)1 WeakItemPropertyChangeListener (com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener)1 ItemWrapper (com.haulmont.cuba.web.gui.data.ItemWrapper)1 Property (com.vaadin.data.Property)1 ArrayList (java.util.ArrayList)1 Matcher (java.util.regex.Matcher)1