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()));
}
}
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));
}
}
Aggregations