Search in sources :

Example 6 with MessageTools

use of com.haulmont.cuba.core.global.MessageTools in project cuba by cuba-platform.

the class WebAbstractField 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)

Example 7 with MessageTools

use of com.haulmont.cuba.core.global.MessageTools in project cuba by cuba-platform.

the class WebEntityLinkField method setDatasource.

@Override
public void setDatasource(Datasource datasource, String property) {
    Preconditions.checkNotNullArgument(datasource, "datasource is null");
    if (this.datasource != null) {
        throw new UnsupportedOperationException("Changing datasource is not supported by the EntityLinkField component");
    }
    // noinspection unchecked
    this.datasource = datasource;
    MetaClass metaClass = datasource.getMetaClass();
    resolveMetaPropertyPath(metaClass, property);
    if (metaProperty.getRange().isClass()) {
        this.metaClass = metaProperty.getRange().asClass();
    }
    ItemWrapper wrapper = createDatasourceWrapper(datasource, Collections.singleton(metaPropertyPath));
    Property itemProperty = wrapper.getItemProperty(metaPropertyPath);
    component.setPropertyDataSource(itemProperty);
    itemChangeListener = e -> {
        Object newValue = InstanceUtils.getValueEx(e.getItem(), metaPropertyPath.getPath());
        setValue(newValue);
    };
    // noinspection unchecked
    datasource.addItemChangeListener(new WeakItemChangeListener(datasource, itemChangeListener));
    itemPropertyChangeListener = e -> {
        if (e.getProperty().equals(metaPropertyPath.toString())) {
            setValue(e.getValue());
        }
    };
    // noinspection unchecked
    datasource.addItemPropertyChangeListener(new WeakItemPropertyChangeListener(datasource, itemPropertyChangeListener));
    if (datasource.getState() == Datasource.State.VALID && datasource.getItem() != null) {
        if (property.equals(metaPropertyPath.toString())) {
            Object newValue = InstanceUtils.getValueEx(datasource.getItem(), metaPropertyPath.getPath());
            setValue(newValue);
        }
    }
    setRequired(metaProperty.isMandatory());
    if (StringUtils.isEmpty(getRequiredMessage())) {
        MessageTools messageTools = AppBeans.get(MessageTools.NAME);
        setRequiredMessage(messageTools.getDefaultRequiredMessage(metaClass, property));
    }
}
Also used : ItemWrapper(com.haulmont.cuba.web.gui.data.ItemWrapper) WeakItemChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemChangeListener) MessageTools(com.haulmont.cuba.core.global.MessageTools) MetaClass(com.haulmont.chile.core.model.MetaClass) WeakItemPropertyChangeListener(com.haulmont.cuba.gui.data.impl.WeakItemPropertyChangeListener) Property(com.vaadin.data.Property)

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