public BindingImpl(BindingBuilderImpl<BEAN, FIELDVALUE, TARGET> builder, ValueProvider<BEAN, TARGET> getter, Setter<BEAN, TARGET> setter) { this.binder = builder.getBinder(); this.field = builder.field; this.statusHandler = builder.statusHandler; converterValidatorChain = ((Converter<FIELDVALUE, TARGET>) builder.converterValidatorChain); onValueChange = getField() .addValueChangeListener(this::handleFieldValueChange); this.getter = getter; this.setter = setter; readOnly = setter == null; }
/** * Adds a value change listener. The listener is called when the value of * this {@code HasValue} is changed either by the user or programmatically. * * @see HasValue#addValueChangeListener(com.vaadin.data.HasValue.ValueChangeListener) * @param listener * the value change listener, not null * @return this (for method chaining) <b>NOT</b> a registration */ public default S withValueChangeListener(ValueChangeListener<V> listener) { ((HasValue<V>) this).addValueChangeListener(listener); return (S) this; } }
/** * * Binds a HasValue<V> to a cookie that lives for a month. The cookies value is updated via a * ValueChangeListener. * * @param <V> The value-type of the HasValue<> * @param field The HasValue<V> that gets bound. * @param name The name of the cookie * @param cb A BrowserCookie.Callback that gets called with the actual value of the cookie. The value is guaranteed to be not null. * * @throws IllegalArgumentException if field or name are null or if name is empty. */ public static <V> void bindValueToCookie(HasValue<V> field, String name, Callback cb) { if (Objects.isNull(name) || name.isEmpty()) { throw new IllegalArgumentException("Name must not be null or empty"); } if (Objects.isNull(field)) { throw new IllegalArgumentException("Field must not be null"); } detectCookieValue(name, (v) -> { if (v != null) { cb.onValueDetected(v); } }); field.addValueChangeListener((event) -> { setCookie(name, event.getValue().toString(), LocalDateTime.now().plusMonths(1l)); }); }
/** * Binds a HasValue<String> to a cookie that lives for a month. The cookies value is updated via a * ValueChangeListener. Its crrent value is copied into the HasValue<String>. * * @param field The HasValue<String> that gets bound. * @param name The name of the cookie * * @throws IllegalArgumentException if field or name are null or if name is empty. */ public static void bindValueToCookie(HasValue<String> field, String name) { if (Objects.isNull(name) || name.isEmpty()) { throw new IllegalArgumentException("Name must not be null or empty"); } if (Objects.isNull(field)) { throw new IllegalArgumentException("Field must not be null"); } detectCookieValue(name, (v) -> { if (v != null) { field.setValue(v); } }); field.addValueChangeListener((event) -> { setCookie(name, event.getValue(), LocalDateTime.now().plusMonths(1l)); }); } }
protected void attachValueChangeListener(T component) { component.addValueChangeListener(event -> componentValueChanged(event.getOldValue(), event.getValue(), event.isUserOriginated()) ); }
/** * Adapt a {@link ValueChangeListener} to be handled as a standard Vaadin * {@link com.vaadin.data.HasValue.ValueChangeListener}. * @param <V> Field type * @param field Source field * @param valueHolder Value holder * @param listener Value change listener * @return Listener registration */ public static <V> Registration adapt(HasValue<V> field, ValueHolder<V> valueHolder, ValueChangeListener<V> listener) { ObjectUtils.argumentNotNull(listener, "ValueChangeListener must be not null"); return field.addValueChangeListener(e -> listener.valueChange( new DefaultValueChangeEvent<>(valueHolder, e.getOldValue(), e.getValue(), e.isUserOriginated()))); }
@Override public Registration addValueChangeListener( final com.holonplatform.vaadin.components.Input.ValueChangeListener<T> listener) { ObjectUtils.argumentNotNull(listener, "ValueChangeListener must be not null"); return getInternalField().addValueChangeListener(e -> listener.valueChange(new DefaultValueChangeEvent<>(this, fromInternalValue(e.getOldValue()), fromInternalValue(e.getValue()), e.isUserOriginated()))); }