use of com.haulmont.cuba.web.toolkit.ui.converters.StringToEnumConverter 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));
}
}
Aggregations