Search in sources :

Example 1 with SerializableBiConsumer

use of com.vaadin.flow.function.SerializableBiConsumer in project flow by vaadin.

the class WebComponentBinding method bindProperty.

/**
 * Adds a property to {@code this} web component binding based on the {@code
 * propertyConfiguration}. If a property with an existing name is bound, the
 * previous binding is removed.
 *
 * @param propertyConfiguration
 *            property configuration, not {@code null}
 * @param overrideDefault
 *            set to {@code true} if the property should be initialized with
 *            {@code startingValue} instead of default value found in
 *            {@link PropertyData}
 * @param startingValue
 *            starting value for the property. Can be {@code null}.
 *            {@code overrideDefault} must be {@code true} for this value to
 *            have any effect
 * @throws NullPointerException
 *             if {@code propertyConfiguration} is {@code null}
 */
public void bindProperty(PropertyConfigurationImpl<C, ? extends Serializable> propertyConfiguration, boolean overrideDefault, JsonValue startingValue) {
    Objects.requireNonNull(propertyConfiguration, "Parameter 'propertyConfiguration' cannot be null!");
    final SerializableBiConsumer<C, Serializable> consumer = propertyConfiguration.getOnChangeHandler();
    final Serializable selectedStartingValue = !overrideDefault ? propertyConfiguration.getPropertyData().getDefaultValue() : jsonValueToConcreteType(startingValue, propertyConfiguration.getPropertyData().getType());
    final PropertyBinding<? extends Serializable> binding = new PropertyBinding<>(propertyConfiguration.getPropertyData(), consumer == null ? null : value -> consumer.accept(component, value), selectedStartingValue);
    properties.put(propertyConfiguration.getPropertyData().getName(), binding);
}
Also used : Objects(java.util.Objects) JsonValue(elemental.json.JsonValue) Component(com.vaadin.flow.component.Component) WebComponentConfiguration(com.vaadin.flow.component.webcomponent.WebComponentConfiguration) SerializableBiConsumer(com.vaadin.flow.function.SerializableBiConsumer) JsonCodec(com.vaadin.flow.internal.JsonCodec) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) SerializableConsumer(com.vaadin.flow.function.SerializableConsumer) Serializable(java.io.Serializable) Serializable(java.io.Serializable)

Aggregations

Component (com.vaadin.flow.component.Component)1 WebComponentConfiguration (com.vaadin.flow.component.webcomponent.WebComponentConfiguration)1 SerializableBiConsumer (com.vaadin.flow.function.SerializableBiConsumer)1 SerializableConsumer (com.vaadin.flow.function.SerializableConsumer)1 JsonCodec (com.vaadin.flow.internal.JsonCodec)1 JsonValue (elemental.json.JsonValue)1 Serializable (java.io.Serializable)1 HashMap (java.util.HashMap)1 Objects (java.util.Objects)1 LoggerFactory (org.slf4j.LoggerFactory)1