Search in sources :

Example 11 with EntityValueSource

use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.

the class WebDateField method valueBindingConnected.

@Override
protected void valueBindingConnected(ValueSource<V> valueSource) {
    super.valueBindingConnected(valueSource);
    if (valueSource instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueSource;
        DataAwareComponentsTools dataAwareComponentsTools = beanLocator.get(DataAwareComponentsTools.class);
        dataAwareComponentsTools.setupDateFormat(this, entityValueSource);
        dataAwareComponentsTools.setupZoneId(this, entityValueSource);
        if (valueSourceStateChangeSubscription != null) {
            valueSourceStateChangeSubscription.remove();
        }
        // setup dateRange after valueSource is activated and value is set because
        // Vaadin dateField rejects value if it is not in range
        valueSourceStateChangeSubscription = valueSource.addStateChangeListener(event -> {
            if (event.getState() == BindingState.ACTIVE) {
                dataAwareComponentsTools.setupDateRange(this, entityValueSource);
            }
        });
    }
}
Also used : CubaCssActionsLayout(com.haulmont.cuba.web.widgets.CubaCssActionsLayout) java.util(java.util) TimeMode(com.haulmont.cuba.gui.components.TimeField.TimeMode) ConversionException(com.haulmont.cuba.gui.components.data.ConversionException) CubaDateField(com.haulmont.cuba.web.widgets.CubaDateField) LoggerFactory(org.slf4j.LoggerFactory) StringUtils(org.apache.commons.lang3.StringUtils) InitializingBean(org.springframework.beans.factory.InitializingBean) Inject(javax.inject.Inject) Pair(com.haulmont.bali.datastruct.Pair) java.time(java.time) Datatype(com.haulmont.chile.core.datatypes.Datatype) HasValue(com.vaadin.data.HasValue) Subscription(com.haulmont.bali.events.Subscription) DataAwareComponentsTools(com.haulmont.cuba.gui.components.data.DataAwareComponentsTools) FormatStringsRegistry(com.haulmont.chile.core.datatypes.FormatStringsRegistry) AppUI(com.haulmont.cuba.web.AppUI) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) WebWrapperUtils.fromVaadinTimeMode(com.haulmont.cuba.web.gui.components.WebWrapperUtils.fromVaadinTimeMode) DateTimeTransformations(com.haulmont.cuba.core.global.DateTimeTransformations) DateResolution(com.vaadin.shared.ui.datefield.DateResolution) Preconditions.checkNotNullArgument(com.haulmont.bali.util.Preconditions.checkNotNullArgument) com.haulmont.cuba.gui.components(com.haulmont.cuba.gui.components) MetaProperty(com.haulmont.chile.core.model.MetaProperty) WebWrapperUtils.toVaadinTimeMode(com.haulmont.cuba.web.gui.components.WebWrapperUtils.toVaadinTimeMode) ValueSource(com.haulmont.cuba.gui.components.data.ValueSource) App(com.haulmont.cuba.web.App) Messages(com.haulmont.cuba.core.global.Messages) ErrorMessage(com.vaadin.server.ErrorMessage) UserSessionSource(com.haulmont.cuba.core.global.UserSessionSource) Preconditions(com.haulmont.bali.util.Preconditions) CubaTimeFieldWrapper(com.haulmont.cuba.web.widgets.CubaTimeFieldWrapper) TestIdManager(com.haulmont.cuba.gui.sys.TestIdManager) Consumer(java.util.function.Consumer) AbstractComponent(com.vaadin.ui.AbstractComponent) BindingState(com.haulmont.cuba.gui.components.data.BindingState) ThemeConstants(com.haulmont.cuba.gui.theme.ThemeConstants) Notifications(com.haulmont.cuba.gui.Notifications) UserError(com.vaadin.server.UserError) ComponentsHelper(com.haulmont.cuba.gui.ComponentsHelper) EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) DataAwareComponentsTools(com.haulmont.cuba.gui.components.data.DataAwareComponentsTools)

Example 12 with EntityValueSource

use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.

the class WebDateField method constructModelValue.

@SuppressWarnings("unchecked")
protected V constructModelValue() {
    LocalDate dateValue = dateField.getValue();
    if (dateValue == null) {
        return null;
    }
    LocalTime timeValue = timeField.getValue() != null ? timeField.getValue() : LocalTime.MIDNIGHT;
    LocalDateTime localDateTime = LocalDateTime.of(dateValue, timeValue);
    ValueSource<V> valueSource = getValueSource();
    if (valueSource instanceof EntityValueSource) {
        MetaProperty metaProperty = ((EntityValueSource) valueSource).getMetaPropertyPath().getMetaProperty();
        return (V) convertFromLocalDateTime(localDateTime, zoneId, metaProperty.getRange().asDatatype().getJavaClass());
    }
    return (V) convertFromLocalDateTime(localDateTime, zoneId, datatype == null ? Date.class : datatype.getJavaClass());
}
Also used : EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 13 with EntityValueSource

use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.

the class WebTimeField method constructModelValue.

@SuppressWarnings("unchecked")
protected V constructModelValue() {
    LocalTime timeValue = component.getValue();
    if (timeValue == null) {
        return null;
    }
    ValueSource<V> valueSource = getValueSource();
    if (valueSource instanceof EntityValueSource) {
        MetaProperty metaProperty = ((EntityValueSource) valueSource).getMetaPropertyPath().getMetaProperty();
        return (V) convertFromLocalTime(timeValue, metaProperty.getRange().asDatatype().getJavaClass());
    }
    return (V) convertFromLocalTime(timeValue, datatype == null ? Date.class : datatype.getJavaClass());
}
Also used : EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) LocalTime(java.time.LocalTime) MetaProperty(com.haulmont.chile.core.model.MetaProperty)

Example 14 with EntityValueSource

use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.

the class WebCurrencyField 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 beanLocator.get(Messages.class).getMainMessage("databinding.conversion.error");
}
Also used : EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource) Messages(com.haulmont.cuba.core.global.Messages)

Example 15 with EntityValueSource

use of com.haulmont.cuba.gui.components.data.meta.EntityValueSource in project cuba by cuba-platform.

the class WebCurrencyField method convertToPresentation.

@Override
protected String convertToPresentation(V modelValue) throws ConversionException {
    Datatype<V> datatype = getDatatypeInternal();
    // Vaadin TextField does not permit `null` value
    if (datatype != null) {
        return nullToEmpty(datatype.format(modelValue, locale));
    }
    if (valueBinding != null && valueBinding.getSource() instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueBinding.getSource();
        Datatype<V> propertyDataType = entityValueSource.getMetaPropertyPath().getRange().asDatatype();
        return nullToEmpty(propertyDataType.format(modelValue, locale));
    }
    return nullToEmpty(super.convertToPresentation(modelValue));
}
Also used : EntityValueSource(com.haulmont.cuba.gui.components.data.meta.EntityValueSource)

Aggregations

EntityValueSource (com.haulmont.cuba.gui.components.data.meta.EntityValueSource)39 MetaProperty (com.haulmont.chile.core.model.MetaProperty)10 DataAwareComponentsTools (com.haulmont.cuba.gui.components.data.DataAwareComponentsTools)10 MetaPropertyPath (com.haulmont.chile.core.model.MetaPropertyPath)9 ValueSource (com.haulmont.cuba.gui.components.data.ValueSource)9 HasValueSource (com.haulmont.cuba.gui.components.data.HasValueSource)6 Messages (com.haulmont.cuba.core.global.Messages)5 ConversionException (com.haulmont.cuba.gui.components.data.ConversionException)5 Datatype (com.haulmont.chile.core.datatypes.Datatype)4 ValueConversionException (com.haulmont.chile.core.datatypes.ValueConversionException)4 Entity (com.haulmont.cuba.core.entity.Entity)4 ParseException (java.text.ParseException)4 MetaClass (com.haulmont.chile.core.model.MetaClass)3 Range (com.haulmont.chile.core.model.Range)2 com.haulmont.cuba.gui.components (com.haulmont.cuba.gui.components)2 Field (com.haulmont.cuba.gui.components.Field)2 DatasourceValueSource (com.haulmont.cuba.gui.components.data.value.DatasourceValueSource)2 Pair (com.haulmont.bali.datastruct.Pair)1 Subscription (com.haulmont.bali.events.Subscription)1 Preconditions (com.haulmont.bali.util.Preconditions)1