use of com.haulmont.cuba.gui.components.data.value.LegacyCollectionDsValueSource in project cuba by cuba-platform.
the class TokenListLoader method loadDatasource.
@SuppressWarnings("unchecked")
protected void loadDatasource(TokenList tokenList, Element element) {
final String datasourceId = element.attributeValue("datasource");
if (StringUtils.isNotEmpty(datasourceId)) {
Datasource datasource = getComponentContext().getDsContext().get(datasourceId);
if (datasource == null) {
throw new GuiDevelopmentException(String.format("Datasource '%s' is not defined", datasourceId), context);
}
if (!(datasource instanceof CollectionDatasource)) {
throw new GuiDevelopmentException(String.format("Can't set datasource '%s' for TokenList because it supports only CollectionDatasources", datasourceId), context);
}
tokenList.setValueSource(new LegacyCollectionDsValueSource((CollectionDatasource) datasource));
}
}
use of com.haulmont.cuba.gui.components.data.value.LegacyCollectionDsValueSource in project cuba by cuba-platform.
the class WebTokenList method convertToModel.
@Override
protected Collection<V> convertToModel(Collection<V> componentRawValue) throws ConversionException {
ValueSource<Collection<V>> valueSource = getValueSource();
if (valueSource != null) {
Class<?> modelCollectionType = null;
if (valueSource instanceof EntityValueSource) {
MetaPropertyPath mpp = ((EntityValueSource) valueSource).getMetaPropertyPath();
modelCollectionType = mpp.getMetaProperty().getJavaType();
} else if (valueSource instanceof LegacyCollectionDsValueSource) {
CollectionDatasource datasource = ((LegacyCollectionDsValueSource) valueSource).getDatasource();
if (datasource instanceof NestedDatasource) {
MetaProperty property = ((NestedDatasource) datasource).getProperty().getInverse();
modelCollectionType = property == null ? null : property.getJavaType();
}
}
if (modelCollectionType != null) {
if (Set.class.isAssignableFrom(modelCollectionType)) {
return new LinkedHashSet<>(componentRawValue);
}
}
}
return new ArrayList<>(componentRawValue);
}
Aggregations