Search in sources :

Example 6 with EntityValueSource

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

the class EntityFieldCreationSupport method addDefaultActions.

public boolean addDefaultActions(EntityPicker entityPicker) {
    ValueSource valueSource = entityPicker.getValueSource();
    if (!(valueSource instanceof EntityValueSource)) {
        return false;
    }
    EntityValueSource entityValueSource = (EntityValueSource) entityPicker.getValueSource();
    MetaPropertyPath mpp = entityValueSource.getMetaPropertyPath();
    MetaClass metaClass = mpp.getMetaProperty().getRange().asClass();
    List<String> actionIds = componentProperties.getEntityFieldActions().get(metaClass.getName());
    if (actionIds == null || actionIds.isEmpty()) {
        return false;
    }
    addActions(entityPicker, actionIds);
    return true;
}
Also used : EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) MetaClass(io.jmix.core.metamodel.model.MetaClass) ValueSource(io.jmix.ui.component.data.ValueSource) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) MetaPropertyPath(io.jmix.core.metamodel.model.MetaPropertyPath)

Example 7 with EntityValueSource

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

the class CurrencyFieldImpl method convertToModel.

@Nullable
@Override
protected V convertToModel(@Nullable String componentRawValue) throws ConversionException {
    String value = StringUtils.trimToNull(emptyToNull(componentRawValue));
    Datatype<V> datatype = getDatatypeInternal();
    if (datatype != null) {
        try {
            return datatype.parse(value, locale);
        } catch (ValueConversionException e) {
            throw new ConversionException(e.getLocalizedMessage(), e);
        } catch (ParseException e) {
            throw new ConversionException(getConversionErrorMessageInternal(), e);
        }
    }
    if (valueBinding != null && valueBinding.getSource() instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueBinding.getSource();
        Datatype<V> propertyDataType = entityValueSource.getMetaPropertyPath().getRange().asDatatype();
        try {
            return propertyDataType.parse(componentRawValue, locale);
        } catch (ValueConversionException e) {
            throw new ConversionException(e.getLocalizedMessage(), e);
        } catch (ParseException e) {
            throw new ConversionException(getConversionErrorMessageInternal(), e);
        }
    }
    return super.convertToModel(componentRawValue);
}
Also used : ValueConversionException(io.jmix.ui.component.data.ValueConversionException) ConversionException(io.jmix.ui.component.data.ConversionException) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) ParseException(java.text.ParseException) ValueConversionException(io.jmix.ui.component.data.ValueConversionException) Nullable(javax.annotation.Nullable)

Example 8 with EntityValueSource

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

the class DateFieldImpl method valueBindingConnected.

@Override
protected void valueBindingConnected(ValueSource<V> valueSource) {
    super.valueBindingConnected(valueSource);
    if (valueSource instanceof EntityValueSource) {
        EntityValueSource entityValueSource = (EntityValueSource) valueSource;
        DataAwareComponentsTools dataAwareComponentsTools = applicationContext.getBean(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 : java.util(java.util) Preconditions(io.jmix.core.common.util.Preconditions) WrapperUtils.toVaadinTimeMode(io.jmix.ui.component.impl.WrapperUtils.toVaadinTimeMode) LoggerFactory(org.slf4j.LoggerFactory) Autowired(org.springframework.beans.factory.annotation.Autowired) StringUtils(org.apache.commons.lang3.StringUtils) InitializingBean(org.springframework.beans.factory.InitializingBean) Messages(io.jmix.core.Messages) Notifications(io.jmix.ui.Notifications) DataAwareComponentsTools(io.jmix.ui.component.data.DataAwareComponentsTools) java.time(java.time) HasValue(com.vaadin.data.HasValue) TestIdManager(io.jmix.ui.sys.TestIdManager) ConversionException(io.jmix.ui.component.data.ConversionException) DateResolution(com.vaadin.shared.ui.datefield.DateResolution) JmixCssActionsLayout(io.jmix.ui.widget.JmixCssActionsLayout) Nullable(javax.annotation.Nullable) Preconditions.checkNotNullArgument(io.jmix.core.common.util.Preconditions.checkNotNullArgument) CurrentAuthentication(io.jmix.core.security.CurrentAuthentication) FormatStringsRegistry(io.jmix.core.metamodel.datatype.FormatStringsRegistry) Subscription(io.jmix.core.common.event.Subscription) ValueSource(io.jmix.ui.component.data.ValueSource) ThemeConstants(io.jmix.ui.theme.ThemeConstants) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) ErrorMessage(com.vaadin.server.ErrorMessage) Datatype(io.jmix.core.metamodel.datatype.Datatype) JmixTimeFieldWrapper(io.jmix.ui.widget.JmixTimeFieldWrapper) Validator(io.jmix.ui.component.validation.Validator) AbstractComponent(com.vaadin.ui.AbstractComponent) AppUI(io.jmix.ui.AppUI) App(io.jmix.ui.App) WrapperUtils.fromVaadinTimeMode(io.jmix.ui.component.impl.WrapperUtils.fromVaadinTimeMode) UserError(com.vaadin.server.UserError) JmixDateField(io.jmix.ui.widget.JmixDateField) MetaProperty(io.jmix.core.metamodel.model.MetaProperty) BindingState(io.jmix.ui.component.data.BindingState) DateTimeTransformations(io.jmix.core.DateTimeTransformations) io.jmix.ui.component(io.jmix.ui.component) EntityValueSource(io.jmix.ui.component.data.meta.EntityValueSource) DataAwareComponentsTools(io.jmix.ui.component.data.DataAwareComponentsTools)

Example 9 with EntityValueSource

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

the class CheckBoxGroupImpl method valueBindingConnected.

@Override
protected void valueBindingConnected(ValueSource<Collection<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 10 with EntityValueSource

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

the class ComboBoxImpl 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