Search in sources :

Example 1 with LegacyCollectionDsValueSource

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));
    }
}
Also used : Datasource(com.haulmont.cuba.gui.data.Datasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) GuiDevelopmentException(com.haulmont.cuba.gui.GuiDevelopmentException) LegacyCollectionDsValueSource(com.haulmont.cuba.gui.components.data.value.LegacyCollectionDsValueSource)

Example 2 with LegacyCollectionDsValueSource

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);
}
Also used : EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) MetaPropertyPath(com.haulmont.chile.core.model.MetaPropertyPath) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) LegacyCollectionDsValueSource(com.haulmont.cuba.gui.components.data.value.LegacyCollectionDsValueSource) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Aggregations

LegacyCollectionDsValueSource (com.haulmont.cuba.gui.components.data.value.LegacyCollectionDsValueSource)2 CollectionDatasource (com.haulmont.cuba.gui.data.CollectionDatasource)2 MetaProperty (com.haulmont.chile.core.model.MetaProperty)1 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)1 GuiDevelopmentException (com.haulmont.cuba.gui.GuiDevelopmentException)1 EntityValueSource (com.haulmont.cuba.gui.components.data.meta.EntityValueSource)1 Datasource (com.haulmont.cuba.gui.data.Datasource)1 NestedDatasource (com.haulmont.cuba.gui.data.NestedDatasource)1