Search in sources :

Example 16 with EntityValueSource

use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.

the class TextFieldImpl method getConversionErrorMessageInternal.

protected String getConversionErrorMessageInternal() {
    String customErrorMessage = getConversionErrorMessage();
    if (StringUtils.isNotEmpty(customErrorMessage)) {
        return customErrorMessage;
    }
    Datatype<V> datatype = this.datatype;
    if (datatype == null && valueBinding != null && valueBinding.getSource() instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueBinding.getSource();
        datatype = entityValueSource.getMetaPropertyPath().getRange().asDatatype();
    }
    if (datatype != null) {
        String msg = getDatatypeConversionErrorMsg(datatype);
        if (StringUtils.isNotEmpty(msg)) {
            return msg;
        }
    }
    return applicationContext.getBean(Messages.class).getMessage("databinding.conversion.error");
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) Messages(io.jmix.core.Messages)

Example 17 with EntityValueSource

use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.

the class DatePickerLoader method getJavaType.

protected Class getJavaType(DatePicker resultComponent) {
    ValueSource valueSource = resultComponent.getValueSource();
    if (valueSource instanceof EntityValueSource) {
        MetaProperty metaProperty = ((EntityValueSource) valueSource).getMetaPropertyPath().getMetaProperty();
        return metaProperty.getRange().asDatatype().getJavaClass();
    }
    Datatype datatype = resultComponent.getDatatype();
    return datatype == null ? Date.class : datatype.getJavaClass();
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) ValueSource(io.jmix.ui.component.data.ValueSource) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) Datatype(io.jmix.core.metamodel.datatype.Datatype)

Example 18 with EntityValueSource

use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.

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(io.jmix.ui.component.data.meta.EntityValueSource) CollectionDatasource(com.haulmont.cuba.gui.data.CollectionDatasource) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath) NestedDatasource(com.haulmont.cuba.gui.data.NestedDatasource) LegacyCollectionDsValueSource(com.haulmont.cuba.gui.components.data.value.LegacyCollectionDsValueSource) MetaProperty(io.jmix.core.metamodel.model.MetaProperty)

Example 19 with EntityValueSource

use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.

the class WebOptionsGroup method valueBindingConnected.

@SuppressWarnings("unchecked")
@Override
protected void valueBindingConnected(ValueSource<V> valueSource) {
    super.valueBindingConnected(valueSource);
    if (valueSource instanceof EntityValueSource) {
        DataAwareComponentsTools dataAwareComponentsTools = applicationContext.getBean(DataAwareComponentsTools.class);
        dataAwareComponentsTools.setupOptions(this, (EntityValueSource) valueSource);
    }
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) DataAwareComponentsTools(io.jmix.ui.component.data.DataAwareComponentsTools)

Example 20 with EntityValueSource

use of io.jmix.ui.component.data.meta.EntityValueSource in project jmix by jmix-framework.

the class WebOptionsList method valueBindingConnected.

@Override
protected void valueBindingConnected(ValueSource<V> valueSource) {
    super.valueBindingConnected(valueSource);
    if (valueSource instanceof EntityValueSource) {
        DataAwareComponentsTools dataAwareComponentsTools = applicationContext.getBean(DataAwareComponentsTools.class);
        dataAwareComponentsTools.setupOptions(this, (EntityValueSource) valueSource);
    }
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) DataAwareComponentsTools(io.jmix.ui.component.data.DataAwareComponentsTools)

Aggregations

EntityValueSource (io.jmix.ui.component.data.meta.EntityValueSource)40 DataAwareComponentsTools (io.jmix.ui.component.data.DataAwareComponentsTools)11 MetaProperty (io.jmix.core.metamodel.model.MetaProperty)10 ValueSource (io.jmix.ui.component.data.ValueSource)9 Nullable (javax.annotation.Nullable)9 MetaPropertyPath (io.jmix.core.metamodel.model.MetaPropertyPath)8 Messages (io.jmix.core.Messages)5 ConversionException (io.jmix.ui.component.data.ConversionException)5 HasValueSource (io.jmix.ui.component.data.HasValueSource)5 Datatype (io.jmix.core.metamodel.datatype.Datatype)4 MetaClass (io.jmix.core.metamodel.model.MetaClass)4 ValueConversionException (io.jmix.ui.component.data.ValueConversionException)4 ParseException (java.text.ParseException)4 UiEntityAttributeContext (io.jmix.ui.accesscontext.UiEntityAttributeContext)3 io.jmix.ui.component (io.jmix.ui.component)3 Nested (io.jmix.ui.model.Nested)3 Range (io.jmix.core.metamodel.model.Range)2 DataContext (io.jmix.ui.model.DataContext)2 DatasourceValueSource (com.haulmont.cuba.gui.components.data.value.DatasourceValueSource)1 LegacyCollectionDsValueSource (com.haulmont.cuba.gui.components.data.value.LegacyCollectionDsValueSource)1