use of com.haulmont.cuba.web.toolkit.ui.converters.StringToDatatypeConverter in project cuba by cuba-platform.
the class CubaCurrencyField method setDatatype.
public void setDatatype(Datatype datatype) {
this.datatype = datatype;
try {
Object parsedValue = datatype.parse(textField.getValue(), getLocale());
textField.setConverter(new StringToDatatypeConverter(datatype));
textField.setConvertedValue(parsedValue);
} catch (ParseException e) {
String message = String.format("Value %s cannot be parsed as %s datatype", textField.getValue(), datatype);
throw new RuntimeException(message, e);
}
}
use of com.haulmont.cuba.web.toolkit.ui.converters.StringToDatatypeConverter in project cuba by cuba-platform.
the class WebLabel method setDatasource.
@Override
public void setDatasource(Datasource datasource, String property) {
if ((datasource == null && property != null) || (datasource != null && property == null))
throw new IllegalArgumentException("Datasource and property should be either null or not null at the same time");
if (datasource == this.datasource && metaPropertyPath != null && metaPropertyPath.toString().equals(property))
return;
if (this.datasource != null)
unsubscribeDatasource();
if (datasource != null) {
// noinspection unchecked
this.datasource = datasource;
this.metaPropertyPath = resolveMetaPropertyPath(datasource.getMetaClass(), property);
this.metaProperty = metaPropertyPath.getMetaProperty();
switch(metaProperty.getType()) {
case ASSOCIATION:
component.setConverter(new StringToEntityConverter() {
@Override
public Formatter getFormatter() {
return WebLabel.this.formatter;
}
});
break;
case DATATYPE:
component.setConverter(new StringToDatatypeConverter(metaProperty.getRange().asDatatype()) {
@Override
public Formatter getFormatter() {
return WebLabel.this.formatter;
}
});
break;
case ENUM:
// noinspection unchecked
component.setConverter(new StringToEnumConverter((Class<Enum>) metaProperty.getJavaType()) {
@Override
public Formatter getFormatter() {
return WebLabel.this.formatter;
}
});
break;
default:
component.setConverter(new StringToDatatypeConverter(Datatypes.getNN(String.class)) {
@Override
public Formatter getFormatter() {
return WebLabel.this.formatter;
}
});
break;
}
itemWrapper = createDatasourceWrapper(datasource, Collections.singleton(this.metaPropertyPath));
component.setPropertyDataSource(itemWrapper.getItemProperty(this.metaPropertyPath));
}
}
use of com.haulmont.cuba.web.toolkit.ui.converters.StringToDatatypeConverter in project cuba by cuba-platform.
the class CubaCurrencyField method initTextField.
protected void initTextField() {
textField.setWidth("100%");
textField.addStyleName(CURRENCYFIELD_TEXT_STYLENAME);
textField.setValidationVisible(false);
textField.setShowBufferedSourceException(false);
textField.setShowErrorForDisabledState(false);
textField.setImmediate(true);
textField.setNullRepresentation(StringUtils.EMPTY);
textField.setConverter(new StringToDatatypeConverter(datatype));
textField.addValueChangeListener(event -> markAsDirty());
}
Aggregations