@Override
public BeanBindingBuilder<BEAN, TARGET> withValidationStatusHandler(
- ValidationStatusHandler handler);
+ BindingValidationStatusHandler handler);
@Override
public default BeanBindingBuilder<BEAN, TARGET> withStatusLabel(
protected BeanBindingImpl(BeanBinder<BEAN> binder,
HasValue<FIELDVALUE> field,
Converter<FIELDVALUE, TARGET> converter,
- ValidationStatusHandler statusHandler) {
+ BindingValidationStatusHandler statusHandler) {
super(binder, field, converter, statusHandler);
}
@Override
public BeanBindingBuilder<BEAN, TARGET> withValidationStatusHandler(
- ValidationStatusHandler handler) {
+ BindingValidationStatusHandler handler) {
return (BeanBindingBuilder<BEAN, TARGET>) super.withValidationStatusHandler(
handler);
}
@Override
protected <FIELDVALUE, TARGET> BeanBindingImpl<BEAN, FIELDVALUE, TARGET> createBinding(
HasValue<FIELDVALUE> field, Converter<FIELDVALUE, TARGET> converter,
- ValidationStatusHandler handler) {
+ BindingValidationStatusHandler handler) {
Objects.requireNonNull(field, "field cannot be null");
Objects.requireNonNull(converter, "converter cannot be null");
return new BeanBindingImpl<>(this, field, converter, handler);
*
* @return the validation result.
*/
- public ValidationStatus<TARGET> validate();
+ public BindingValidationStatus<TARGET> validate();
}
* default behavior).
* <p>
* This is just a shorthand for
- * {@link #withValidationStatusHandler(ValidationStatusHandler)} method
+ * {@link #withValidationStatusHandler(BindingValidationStatusHandler)} method
* where the handler instance hides the {@code label} if there is no
* error and shows it with validation error message if validation fails.
* It means that it cannot be called after
- * {@link #withValidationStatusHandler(ValidationStatusHandler)} method
- * call or {@link #withValidationStatusHandler(ValidationStatusHandler)}
+ * {@link #withValidationStatusHandler(BindingValidationStatusHandler)} method
+ * call or {@link #withValidationStatusHandler(BindingValidationStatusHandler)}
* after this method call.
*
- * @see #withValidationStatusHandler(ValidationStatusHandler)
+ * @see #withValidationStatusHandler(BindingValidationStatusHandler)
* @see AbstractComponent#setComponentError(ErrorMessage)
* @param label
* label to show validation status for the field
}
/**
- * Sets a {@link ValidationStatusHandler} to track validation status
+ * Sets a {@link BindingValidationStatusHandler} to track validation status
* changes.
* <p>
* The validation state of each field is updated whenever the user
* @return this binding, for chaining
*/
public BindingBuilder<BEAN, TARGET> withValidationStatusHandler(
- ValidationStatusHandler handler);
+ BindingValidationStatusHandler handler);
/**
* Sets the field to be required. This means two things:
private final Binder<BEAN> binder;
private final HasValue<FIELDVALUE> field;
- private ValidationStatusHandler statusHandler;
+ private BindingValidationStatusHandler statusHandler;
private boolean isStatusHandlerChanged;
private boolean bound;
protected BindingBuilderImpl(Binder<BEAN> binder,
HasValue<FIELDVALUE> field,
Converter<FIELDVALUE, TARGET> converterValidatorChain,
- ValidationStatusHandler statusHandler) {
+ BindingValidationStatusHandler statusHandler) {
this.field = field;
this.binder = binder;
this.converterValidatorChain = converterValidatorChain;
@Override
public BindingBuilder<BEAN, TARGET> withValidationStatusHandler(
- ValidationStatusHandler handler) {
+ BindingValidationStatusHandler handler) {
checkUnbound();
Objects.requireNonNull(handler, "handler cannot be null");
if (isStatusHandlerChanged) {
throw new IllegalStateException(
- "A " + ValidationStatusHandler.class.getSimpleName()
+ "A " + BindingValidationStatusHandler.class.getSimpleName()
+ " has already been set");
}
isStatusHandlerChanged = true;
private final Binder<BEAN> binder;
private final HasValue<FIELDVALUE> field;
- private final ValidationStatusHandler statusHandler;
+ private final BindingValidationStatusHandler statusHandler;
private final SerializableFunction<BEAN, TARGET> getter;
private final SerializableBiConsumer<BEAN, TARGET> setter;
}
@Override
- public ValidationStatus<TARGET> validate() {
- ValidationStatus<TARGET> status = doValidation();
+ public BindingValidationStatus<TARGET> validate() {
+ BindingValidationStatus<TARGET> status = doValidation();
getBinder().getValidationStatusHandler()
- .accept(new BinderValidationStatus<>(getBinder(),
+ .statusChange(new BinderValidationStatus<>(getBinder(),
Arrays.asList(status), Collections.emptyList()));
getBinder().fireStatusChangeEvent(status.isError());
return status;
/**
* Returns the field value run through all converters and validators,
- * but doesn't pass the {@link ValidationStatus} to any status handler.
+ * but doesn't pass the {@link BindingValidationStatus} to any status handler.
*
* @return the result of the conversion
*/
createValueContext());
}
- private ValidationStatus<TARGET> toValidationStatus(
+ private BindingValidationStatus<TARGET> toValidationStatus(
Result<TARGET> result) {
- return new ValidationStatus<>(this,
+ return new BindingValidationStatus<>(this,
result.isError()
? ValidationResult.error(result.getMessage().get())
: ValidationResult.ok());
/**
* Returns the field value run through all converters and validators,
- * but doesn't pass the {@link ValidationStatus} to any status handler.
+ * but doesn't pass the {@link BindingValidationStatus} to any status handler.
*
* @return the validation status
*/
- private ValidationStatus<TARGET> doValidation() {
+ private BindingValidationStatus<TARGET> doValidation() {
return toValidationStatus(doConversion());
}
getBinder().setHasChanges(true);
List<ValidationResult> binderValidationResults = Collections
.emptyList();
- ValidationStatus<TARGET> fieldValidationStatus;
+ BindingValidationStatus<TARGET> fieldValidationStatus;
if (getBinder().getBean() != null) {
BEAN bean = getBinder().getBean();
fieldValidationStatus = writeFieldValue(bean);
if (!getBinder().bindings.stream()
.map(BindingImpl::doValidation)
- .anyMatch(ValidationStatus::isError)) {
+ .anyMatch(BindingValidationStatus::isError)) {
binderValidationResults = getBinder().validateBean(bean);
if (!binderValidationResults.stream()
.anyMatch(ValidationResult::isError)) {
BinderValidationStatus<BEAN> status = new BinderValidationStatus<>(
getBinder(), Arrays.asList(fieldValidationStatus),
binderValidationResults);
- getBinder().getValidationStatusHandler().accept(status);
+ getBinder().getValidationStatusHandler().statusChange(status);
getBinder().fireStatusChangeEvent(status.hasErrors());
}
* @param bean
* the bean to set the property value to
*/
- private ValidationStatus<TARGET> writeFieldValue(BEAN bean) {
+ private BindingValidationStatus<TARGET> writeFieldValue(BEAN bean) {
assert bean != null;
Result<TARGET> result = doConversion();
return binder;
}
- private void notifyStatusHandler(ValidationStatus<?> status) {
- statusHandler.accept(status);
+ private void notifyStatusHandler(BindingValidationStatus<?> status) {
+ statusHandler.statusChange(status);
}
}
bindings.forEach(b -> b.initFieldValue(bean));
// if there has been field value change listeners that trigger
// validation, need to make sure the validation errors are cleared
- getValidationStatusHandler().accept(
+ getValidationStatusHandler().statusChange(
BinderValidationStatus.createUnresolvedStatus(this));
fireStatusChangeEvent(false);
}
bindings.forEach(binding -> binding.initFieldValue(bean));
getValidationStatusHandler()
- .accept(BinderValidationStatus.createUnresolvedStatus(this));
+ .statusChange(BinderValidationStatus.createUnresolvedStatus(this));
fireStatusChangeEvent(false);
}
private BinderValidationStatus<BEAN> doWriteIfValid(BEAN bean) {
Objects.requireNonNull(bean, "bean cannot be null");
// First run fields level validation
- List<ValidationStatus<?>> bindingStatuses = validateBindings();
+ List<BindingValidationStatus<?>> bindingStatuses = validateBindings();
// If no validation errors then update bean
- if (bindingStatuses.stream().filter(ValidationStatus::isError).findAny()
+ if (bindingStatuses.stream().filter(BindingValidationStatus::isError).findAny()
.isPresent()) {
fireStatusChangeEvent(true);
return new BinderValidationStatus<>(this, bindingStatuses,
* @return validation status for the binder
*/
public BinderValidationStatus<BEAN> validate() {
- List<ValidationStatus<?>> bindingStatuses = validateBindings();
+ List<BindingValidationStatus<?>> bindingStatuses = validateBindings();
BinderValidationStatus<BEAN> validationStatus;
- if (bindingStatuses.stream().filter(ValidationStatus::isError).findAny()
+ if (bindingStatuses.stream().filter(BindingValidationStatus::isError).findAny()
.isPresent() || bean == null) {
validationStatus = new BinderValidationStatus<>(this,
bindingStatuses, Collections.emptyList());
validationStatus = new BinderValidationStatus<>(this,
bindingStatuses, validateBean(bean));
}
- getValidationStatusHandler().accept(validationStatus);
+ getValidationStatusHandler().statusChange(validationStatus);
fireStatusChangeEvent(validationStatus.hasErrors());
return validationStatus;
}
*
* @return an immutable list of validation results for bindings
*/
- private List<ValidationStatus<?>> validateBindings() {
- List<ValidationStatus<?>> results = new ArrayList<>();
+ private List<BindingValidationStatus<?>> validateBindings() {
+ List<BindingValidationStatus<?>> results = new ArrayList<>();
for (BindingImpl<?, ?, ?> binding : bindings) {
results.add(binding.doValidation());
}
* @throws NullPointerException
* for <code>null</code> status handler
* @see #setStatusLabel(Label)
- * @see BindingBuilder#withValidationStatusHandler(ValidationStatusHandler)
+ * @see BindingBuilder#withValidationStatusHandler(BindingValidationStatusHandler)
*/
public void setValidationStatusHandler(
BinderValidationStatusHandler<BEAN> statusHandler) {
*/
protected <FIELDVALUE, TARGET> BindingBuilder<BEAN, TARGET> createBinding(
HasValue<FIELDVALUE> field, Converter<FIELDVALUE, TARGET> converter,
- ValidationStatusHandler handler) {
+ BindingValidationStatusHandler handler) {
return new BindingBuilderImpl<>(this, field, converter, handler);
}
}
/**
- * Default {@link ValidationStatusHandler} functional method implementation.
+ * Default {@link BindingValidationStatusHandler} functional method implementation.
*
* @param status
* the validation status
*/
- protected void handleValidationStatus(ValidationStatus<?> status) {
+ protected void handleValidationStatus(BindingValidationStatus<?> status) {
HasValue<?> source = status.getField();
clearError(source);
if (status.isError()) {
bean = null;
}
getValidationStatusHandler()
- .accept(BinderValidationStatus.createUnresolvedStatus(this));
+ .statusChange(BinderValidationStatus.createUnresolvedStatus(this));
if (fireStatusEvent) {
fireStatusChangeEvent(false);
}
* @see BinderValidationStatusHandler
* @see Binder#setValidationStatusHandler(BinderStatusHandler)
* @see Binder#validate()
- * @see ValidationStatus
+ * @see BindingValidationStatus
*
* @since 8.0
*/
public class BinderValidationStatus<BEAN> implements Serializable {
private final Binder<BEAN> binder;
- private final List<ValidationStatus<?>> bindingStatuses;
+ private final List<BindingValidationStatus<?>> bindingStatuses;
private final List<ValidationResult> binderStatuses;
/**
Binder<BEAN> source) {
return new BinderValidationStatus<>(source,
source.getBindings().stream()
- .map(b -> ValidationStatus.createUnresolvedStatus(b))
+ .map(b -> BindingValidationStatus.createUnresolvedStatus(b))
.collect(Collectors.toList()),
Collections.emptyList());
}
* the validation results for binder level validation
*/
public BinderValidationStatus(Binder<BEAN> source,
- List<ValidationStatus<?>> bindingStatuses,
+ List<BindingValidationStatus<?>> bindingStatuses,
List<ValidationResult> binderStatuses) {
Objects.requireNonNull(binderStatuses,
"binding statuses cannot be null");
public boolean hasErrors() {
return binderStatuses.stream().filter(ValidationResult::isError)
.findAny().isPresent()
- || bindingStatuses.stream().filter(ValidationStatus::isError)
+ || bindingStatuses.stream().filter(BindingValidationStatus::isError)
.findAny().isPresent();
}
*
* @return the field validation statuses
*/
- public List<ValidationStatus<?>> getFieldValidationStatuses() {
+ public List<BindingValidationStatus<?>> getFieldValidationStatuses() {
return bindingStatuses;
}
*
* @return a list of failed field level validation statuses
*/
- public List<ValidationStatus<?>> getFieldValidationErrors() {
- return bindingStatuses.stream().filter(ValidationStatus::isError)
+ public List<BindingValidationStatus<?>> getFieldValidationErrors() {
+ return bindingStatuses.stream().filter(BindingValidationStatus::isError)
.collect(Collectors.toList());
}
*/
package com.vaadin.data;
-import java.io.Serializable;
-import java.util.function.Consumer;
-
+import com.vaadin.event.SerializableEventListener;
import com.vaadin.ui.AbstractComponent;
/**
*
* @see BinderValidationStatus
* @see Binder#validate()
- * @see ValidationStatus
+ * @see BindingValidationStatus
*
* @param <BEAN>
* the bean type of binder
*/
@FunctionalInterface
public interface BinderValidationStatusHandler<BEAN>
- extends Consumer<BinderValidationStatus<BEAN>>, Serializable {
+ extends SerializableEventListener {
+
+ /**
+ * Invoked when the validation status has changed in binder.
+ *
+ * @param statusChange
+ * the changed status
+ */
+ void statusChange(BinderValidationStatus<BEAN> statusChange);
}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.data;
+
+import java.io.Serializable;
+import java.util.Objects;
+import java.util.Optional;
+
+import com.vaadin.data.Binder.Binding;
+import com.vaadin.data.Binder.BindingBuilder;
+
+/**
+ * Represents the status of field validation. Status can be {@code Status.OK},
+ * {@code Status.ERROR} or {@code Status.RESET}. Status OK and ERROR are always
+ * associated with a ValidationResult {@link #getResult}.
+ * <p>
+ * Use
+ * {@link BindingBuilder#withValidationStatusHandler(BindingValidationStatusHandler)}
+ * to register a handler for field level validation status changes.
+ *
+ * @author Vaadin Ltd
+ *
+ * @param <TARGET>
+ * the target data type of the binding for which the validation
+ * status changed, matches the field type unless a converter has been
+ * set
+ *
+ * @see BindingBuilder#withValidationStatusHandler(BindingValidationStatusHandler)
+ * @see Binding#validate()
+ * @see BindingValidationStatusHandler
+ * @see BinderValidationStatus
+ *
+ * @since 8.0
+ */
+public class BindingValidationStatus<TARGET> implements Serializable {
+
+ /**
+ * Status of the validation.
+ * <p>
+ * The status is the part of {@link BindingValidationStatus} which indicates
+ * whether the validation failed or not, or whether it is in unresolved
+ * state (e.g. after clear or reset).
+ */
+ public enum Status {
+ /** Validation passed. */
+ OK,
+ /** Validation failed. */
+ ERROR,
+ /**
+ * Unresolved status, e.g field has not yet been validated because value
+ * was cleared.
+ * <p>
+ * In practice this status means that the value might be invalid, but
+ * validation errors should be hidden.
+ */
+ UNRESOLVED;
+ }
+
+ private final Status status;
+ private final ValidationResult result;
+ private final Binding<?, TARGET> binding;
+
+ /**
+ * Convenience method for creating a {@link Status#UNRESOLVED} validation
+ * status for the given binding.
+ *
+ * @param source
+ * the source binding
+ * @return unresolved validation status
+ * @param <TARGET>
+ * the target data type of the binding for which the validation
+ * status was reset
+ */
+ public static <TARGET> BindingValidationStatus<TARGET> createUnresolvedStatus(
+ Binding<?, TARGET> source) {
+ return new BindingValidationStatus<>(source, Status.UNRESOLVED, null);
+ }
+
+ /**
+ * Creates a new validation status for the given binding and validation
+ * result.
+ *
+ * @param source
+ * the source binding
+ * @param result
+ * the result of the validation
+ */
+ public BindingValidationStatus(Binding<?, TARGET> source,
+ ValidationResult result) {
+ this(source, result.isError() ? Status.ERROR : Status.OK, result);
+ }
+
+ /**
+ * Creates a new status change event.
+ * <p>
+ * The {@code message} must be {@code null} if the {@code status} is
+ * {@link Status#OK}.
+ *
+ * @param source
+ * field whose status has changed, not {@code null}
+ * @param status
+ * updated status value, not {@code null}
+ * @param result
+ * the related result, may be {@code null}
+ */
+ public BindingValidationStatus(Binding<?, TARGET> source, Status status,
+ ValidationResult result) {
+ Objects.requireNonNull(source, "Event source may not be null");
+ Objects.requireNonNull(status, "Status may not be null");
+ if (Objects.equals(status, Status.OK) && result.isError()
+ || Objects.equals(status, Status.ERROR) && !result.isError()
+ || Objects.equals(status, Status.UNRESOLVED)
+ && result != null) {
+ throw new IllegalStateException(
+ "Invalid validation status " + status + " for given result "
+ + (result == null ? "null" : result.toString()));
+ }
+ binding = source;
+ this.status = status;
+ this.result = result;
+ }
+
+ /**
+ * Gets status of the validation.
+ *
+ * @return status
+ */
+ public Status getStatus() {
+ return status;
+ }
+
+ /**
+ * Gets whether the validation failed or not.
+ *
+ * @return {@code true} if validation failed, {@code false} if validation
+ * passed
+ */
+ public boolean isError() {
+ return status == Status.ERROR;
+ }
+
+ /**
+ * Gets error validation message if status is {@link Status#ERROR}.
+ *
+ * @return an optional validation error status or an empty optional if
+ * status is not an error
+ */
+ public Optional<String> getMessage() {
+ return Optional.ofNullable(result).filter(ValidationResult::isError)
+ .map(ValidationResult::getErrorMessage);
+ }
+
+ /**
+ * Gets the validation result if status is either {@link Status#OK} or
+ * {@link Status#ERROR} or an empty optional if status is
+ * {@link Status#UNRESOLVED}.
+ *
+ * @return the validation result
+ */
+ public Optional<ValidationResult> getResult() {
+ return Optional.ofNullable(result);
+ }
+
+ /**
+ * Gets the source binding of the validation status.
+ *
+ * @return the source binding
+ */
+ public Binding<?, TARGET> getBinding() {
+ return binding;
+ }
+
+ /**
+ * Gets the bound field for this status.
+ *
+ * @return the field
+ */
+ public HasValue<?> getField() {
+ return getBinding().getField();
+ }
+}
--- /dev/null
+/*
+ * Copyright 2000-2016 Vaadin Ltd.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.data;
+
+import com.vaadin.data.Binder.BindingBuilder;
+import com.vaadin.event.SerializableEventListener;
+import com.vaadin.ui.AbstractComponent;
+
+/**
+ * Handler for {@link BindingValidationStatus} changes.
+ * <p>
+ * {@link BindingBuilder#withValidationStatusHandler(withValidationStatusHandler)
+ * Register} an instance of this class to be able to override the default
+ * handling, which is to show
+ * {@link AbstractComponent#setComponentError(com.vaadin.server.ErrorMessage) an
+ * error message} for failed field validations.
+ *
+ * @author Vaadin Ltd
+ *
+ * @see BindingBuilder#withValidationStatusHandler(withValidationStatusHandler)
+ * @see BindingValidationStatus
+ *
+ * @since 8.0
+ *
+ */
+@FunctionalInterface
+public interface BindingValidationStatusHandler
+ extends SerializableEventListener {
+
+ /**
+ * Invoked when the validation status has changed in a binding.
+ *
+ * @param statusChange
+ * the changed status
+ */
+ public void statusChange(BindingValidationStatus<?> statusChange);
+}
import java.util.EventObject;
import java.util.Objects;
import java.util.function.BiConsumer;
-import java.util.function.Consumer;
+import com.vaadin.event.SerializableEventListener;
import com.vaadin.shared.Registration;
import com.vaadin.ui.Component;
import com.vaadin.util.ReflectTools;
* @see Registration
*/
@FunctionalInterface
- public interface ValueChangeListener<V>
- extends Consumer<ValueChangeEvent<V>>, Serializable {
+ public interface ValueChangeListener<V> extends SerializableEventListener {
+
+ /** For internal use only. Might be removed in the future. */
@Deprecated
public static final Method VALUE_CHANGE_METHOD = ReflectTools
- .findMethod(ValueChangeListener.class, "accept",
+ .findMethod(ValueChangeListener.class, "valueChange",
ValueChangeEvent.class);
/**
* @param event
* the received event, not null
*/
- @Override
- public void accept(ValueChangeEvent<V> event);
+ public void valueChange(ValueChangeEvent<V> event);
}
/**
* <p>
* This is just a shorthand for resetting the value, see the methods
* {@link #setValue(Object)} and {@link #getEmptyValue()}.
- *
+ *
* @see #setValue(Object)
* @see #getEmptyValue()
*/
*/
package com.vaadin.data;
-import java.io.Serializable;
+import com.vaadin.event.SerializableEventListener;
/**
- * Listener interface for {@link StatusChangeEvent}s.
- *
- * @see StatusChangeEvent
+ * Listener interface for status change events from binder.
+ *
* @author Vaadin Ltd
*
+ * @since 8.0
+ *
+ * @see StatusChangeEvent
+ * @see Binder#addStatusChangeListener(StatusChangeListener)
*/
@FunctionalInterface
-public interface StatusChangeListener extends Serializable {
+public interface StatusChangeListener extends SerializableEventListener {
/**
* Notifies the listener about status change {@code event}.
- *
+ *
* @param event
* a status change event, not null
*/
*/
public class ValidationException extends Exception {
- private final List<ValidationStatus<?>> fieldValidationErrors;
+ private final List<BindingValidationStatus<?>> fieldValidationErrors;
private final List<ValidationResult> beanValidationErrors;
/**
* @param beanValidationErrors
* binder validation errors list
*/
- public ValidationException(List<ValidationStatus<?>> fieldValidationErrors,
+ public ValidationException(List<BindingValidationStatus<?>> fieldValidationErrors,
List<ValidationResult> beanValidationErrors) {
super("Validation has failed for some fields");
this.fieldValidationErrors = Collections
*
* @return binding validation errors list
*/
- public List<ValidationStatus<?>> getFieldValidationErrors() {
+ public List<BindingValidationStatus<?>> getFieldValidationErrors() {
return fieldValidationErrors;
}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.data;
-
-import java.io.Serializable;
-import java.util.Objects;
-import java.util.Optional;
-
-import com.vaadin.data.Binder.Binding;
-import com.vaadin.data.Binder.BindingBuilder;
-
-/**
- * Represents the status of field validation. Status can be {@code Status.OK},
- * {@code Status.ERROR} or {@code Status.RESET}. Status OK and ERROR are always
- * associated with a ValidationResult {@link #getResult}.
- * <p>
- * Use
- * {@link BindingBuilder#withValidationStatusHandler(ValidationStatusHandler)}
- * to register a handler for field level validation status changes.
- *
- * @author Vaadin Ltd
- *
- * @param <TARGET>
- * the target data type of the binding for which the validation
- * status changed, matches the field type unless a converter has been
- * set
- *
- * @see BindingBuilder#withValidationStatusHandler(ValidationStatusHandler)
- * @see Binding#validate()
- * @see ValidationStatusHandler
- * @see BinderValidationStatus
- *
- * @since 8.0
- */
-public class ValidationStatus<TARGET> implements Serializable {
-
- /**
- * Status of the validation.
- * <p>
- * The status is the part of {@link ValidationStatus} which indicates
- * whether the validation failed or not, or whether it is in unresolved
- * state (e.g. after clear or reset).
- */
- public enum Status {
- /** Validation passed. */
- OK,
- /** Validation failed. */
- ERROR,
- /**
- * Unresolved status, e.g field has not yet been validated because value
- * was cleared.
- * <p>
- * In practice this status means that the value might be invalid, but
- * validation errors should be hidden.
- */
- UNRESOLVED;
- }
-
- private final Status status;
- private final ValidationResult result;
- private final Binding<?, TARGET> binding;
-
- /**
- * Convenience method for creating a {@link Status#UNRESOLVED} validation
- * status for the given binding.
- *
- * @param source
- * the source binding
- * @return unresolved validation status
- * @param <TARGET>
- * the target data type of the binding for which the validation
- * status was reset
- */
- public static <TARGET> ValidationStatus<TARGET> createUnresolvedStatus(
- Binding<?, TARGET> source) {
- return new ValidationStatus<>(source, Status.UNRESOLVED, null);
- }
-
- /**
- * Creates a new validation status for the given binding and validation
- * result.
- *
- * @param source
- * the source binding
- * @param result
- * the result of the validation
- */
- public ValidationStatus(Binding<?, TARGET> source,
- ValidationResult result) {
- this(source, result.isError() ? Status.ERROR : Status.OK, result);
- }
-
- /**
- * Creates a new status change event.
- * <p>
- * The {@code message} must be {@code null} if the {@code status} is
- * {@link Status#OK}.
- *
- * @param source
- * field whose status has changed, not {@code null}
- * @param status
- * updated status value, not {@code null}
- * @param result
- * the related result, may be {@code null}
- */
- public ValidationStatus(Binding<?, TARGET> source, Status status,
- ValidationResult result) {
- Objects.requireNonNull(source, "Event source may not be null");
- Objects.requireNonNull(status, "Status may not be null");
- if (Objects.equals(status, Status.OK) && result.isError()
- || Objects.equals(status, Status.ERROR) && !result.isError()
- || Objects.equals(status, Status.UNRESOLVED)
- && result != null) {
- throw new IllegalStateException(
- "Invalid validation status " + status + " for given result "
- + (result == null ? "null" : result.toString()));
- }
- binding = source;
- this.status = status;
- this.result = result;
- }
-
- /**
- * Gets status of the validation.
- *
- * @return status
- */
- public Status getStatus() {
- return status;
- }
-
- /**
- * Gets whether the validation failed or not.
- *
- * @return {@code true} if validation failed, {@code false} if validation
- * passed
- */
- public boolean isError() {
- return status == Status.ERROR;
- }
-
- /**
- * Gets error validation message if status is {@link Status#ERROR}.
- *
- * @return an optional validation error status or an empty optional if
- * status is not an error
- */
- public Optional<String> getMessage() {
- return Optional.ofNullable(result).filter(ValidationResult::isError)
- .map(ValidationResult::getErrorMessage);
- }
-
- /**
- * Gets the validation result if status is either {@link Status#OK} or
- * {@link Status#ERROR} or an empty optional if status is
- * {@link Status#UNRESOLVED}.
- *
- * @return the validation result
- */
- public Optional<ValidationResult> getResult() {
- return Optional.ofNullable(result);
- }
-
- /**
- * Gets the source binding of the validation status.
- *
- * @return the source binding
- */
- public Binding<?, TARGET> getBinding() {
- return binding;
- }
-
- /**
- * Gets the bound field for this status.
- *
- * @return the field
- */
- public HasValue<?> getField() {
- return getBinding().getField();
- }
-}
+++ /dev/null
-/*
- * Copyright 2000-2016 Vaadin Ltd.
- *
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.vaadin.data;
-
-import java.io.Serializable;
-import java.util.function.Consumer;
-
-import com.vaadin.data.Binder.BindingBuilder;
-import com.vaadin.ui.AbstractComponent;
-
-/**
- * Handler for {@link ValidationStatus} changes.
- * <p>
- * {@link BindingBuilder#withValidationStatusHandler(withValidationStatusHandler)
- * Register} an instance of this class to be able to override the default
- * handling, which is to show
- * {@link AbstractComponent#setComponentError(com.vaadin.server.ErrorMessage) an
- * error message} for failed field validations.
- *
- * @author Vaadin Ltd
- *
- * @see BindingBuilder#withValidationStatusHandler(withValidationStatusHandler)
- * @see ValidationStatus
- *
- * @since 8.0
- *
- */
-@FunctionalInterface
-public interface ValidationStatusHandler
- extends Consumer<ValidationStatus<?>>, Serializable {
-
-}
*/
package com.vaadin.event.selection;
-import java.io.Serializable;
-import java.util.function.Consumer;
+import java.lang.reflect.Method;
+
+import com.vaadin.event.SerializableEventListener;
+import com.vaadin.util.ReflectTools;
/**
- * Listens to changes from a {@link com.vaadin.data.SelectionModel.Multi}.
+ * A listener for listening for selection changes from a multiselection
+ * component.
*
* @author Vaadin Ltd
*
* @since 8.0
*
* @param <T>
- * the data type of the selection model
+ * the type of the selected item
+ *
+ * @see SelectionModel.Multi
+ * @see MultiSelectionEvent
*/
@FunctionalInterface
-public interface MultiSelectionListener<T>
- extends Consumer<MultiSelectionEvent<T>>, Serializable {
- @Override
- // Explicitly defined to make reflection logic happy
- void accept(MultiSelectionEvent<T> event);
+public interface MultiSelectionListener<T> extends SerializableEventListener {
+
+ /** For internal use only. Might be removed in the future. */
+ @Deprecated
+ static final Method SELECTION_CHANGE_METHOD = ReflectTools.findMethod(
+ MultiSelectionListener.class, "selectionChange",
+ MultiSelectionEvent.class);
+
+ /**
+ * Invoked when the selection has changed by the user or programmatically.
+ *
+ * @param event
+ * the selection event, never {@code null}
+ */
+ public void selectionChange(MultiSelectionEvent<T> event);
}
*/
package com.vaadin.event.selection;
-import com.vaadin.server.SerializableConsumer;
+import com.vaadin.event.SerializableEventListener;
/**
* A listener for {@code SelectionEvent}.
* @since 8.0
*/
@FunctionalInterface
-public interface SelectionListener<T>
- extends SerializableConsumer<SelectionEvent<T>> {
+public interface SelectionListener<T> extends SerializableEventListener {
+
+ /**
+ * Invoked when the selection has changed by user or programmatically.
+ *
+ * @param event
+ * the selection event
+ */
+ public void selectionChange(SelectionEvent<T> event);
}
*/
package com.vaadin.event.selection;
-import java.io.Serializable;
-import java.util.function.Consumer;
+import java.lang.reflect.Method;
+
+import com.vaadin.event.SerializableEventListener;
+import com.vaadin.util.ReflectTools;
/**
- * A listener for {@code SingleSelectionEvent}.
+ * A listener for listening to selection changes on a single selection
+ * component.
*
* @author Vaadin Ltd.
*
+ * @since 8.0
+ *
* @param <T>
* the type of the selected item
*
+ * @see SelectionModel.Single
* @see SingleSelectionEvent
- *
- * @since 8.0
*/
@FunctionalInterface
-public interface SingleSelectionListener<T>
- extends Consumer<SingleSelectionEvent<T>>, Serializable {
+public interface SingleSelectionListener<T> extends SerializableEventListener {
+
+ /** For internal use only. Might be removed in the future. */
+ @Deprecated
+ static final Method SELECTION_CHANGE_METHOD = ReflectTools.findMethod(
+ SingleSelectionListener.class, "selectionChange",
+ SingleSelectionEvent.class);
- @Override
- public void accept(SingleSelectionEvent<T> event);
+ /**
+ * Invoked when selection has been changed by the user or programmatically.
+ *
+ * @param event
+ * the selection event
+ */
+ public void selectionChange(SingleSelectionEvent<T> event);
}
package com.vaadin.ui;
-import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Objects;
import com.vaadin.ui.Component.Focusable;
import com.vaadin.ui.declarative.DesignAttributeHandler;
import com.vaadin.ui.declarative.DesignContext;
-import com.vaadin.util.ReflectTools;
/**
* An abstract implementation of a field, or a {@code Component} allowing user
public abstract class AbstractField<T> extends AbstractComponent
implements HasValue<T>, Focusable {
- @Deprecated
- private static final Method VALUE_CHANGE_METHOD = ReflectTools.findMethod(
- ValueChangeListener.class, "accept", ValueChangeEvent.class);
-
@Override
public void setValue(T value) {
setValue(value, false);
public Registration addValueChangeListener(
ValueChangeListener<T> listener) {
return addListener(ValueChangeEvent.class, listener,
- VALUE_CHANGE_METHOD);
+ ValueChangeListener.VALUE_CHANGE_METHOD);
}
@Override
*/
package com.vaadin.ui;
-import java.lang.reflect.Method;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import com.vaadin.shared.ui.abstractmultiselect.AbstractMultiSelectState;
import com.vaadin.ui.declarative.DesignContext;
import com.vaadin.ui.declarative.DesignException;
-import com.vaadin.util.ReflectTools;
import elemental.json.JsonObject;
}
}
- @Deprecated
- private static final Method SELECTION_CHANGE_METHOD = ReflectTools
- .findMethod(MultiSelectionListener.class, "accept",
- MultiSelectionEvent.class);
-
/**
* The item enabled status provider. It is up to the implementing class to
* support this or not.
public Registration addSelectionListener(
MultiSelectionListener<T> listener) {
return addListener(MultiSelectionEvent.class, listener,
- SELECTION_CHANGE_METHOD);
+ MultiSelectionListener.SELECTION_CHANGE_METHOD);
}
@Override
@Override
public Registration addValueChangeListener(
HasValue.ValueChangeListener<Set<T>> listener) {
- return addSelectionListener(event -> listener.accept(
+ return addSelectionListener(event -> listener.valueChange(
new ValueChangeEvent<>(this, event.isUserOriginated())));
}
*/
package com.vaadin.ui;
-import java.lang.reflect.Method;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import com.vaadin.shared.ui.AbstractSingleSelectState;
import com.vaadin.ui.declarative.DesignContext;
import com.vaadin.ui.declarative.DesignException;
-import com.vaadin.util.ReflectTools;
import elemental.json.Json;
public abstract class AbstractSingleSelect<T> extends AbstractListing<T>
implements SingleSelect<T> {
- @Deprecated
- private static final Method SELECTION_CHANGE_METHOD = ReflectTools
- .findMethod(SingleSelectionListener.class, "accept",
- SingleSelectionEvent.class);
-
/**
* Creates a new {@code AbstractListing} with a default data communicator.
* <p>
public Registration addSelectionListener(
SingleSelectionListener<T> listener) {
return addListener(SingleSelectionEvent.class, listener,
- SELECTION_CHANGE_METHOD);
+ SingleSelectionListener.SELECTION_CHANGE_METHOD);
}
/**
@Override
public Registration addValueChangeListener(
HasValue.ValueChangeListener<T> listener) {
- return addSelectionListener(event -> listener.accept(
+ return addSelectionListener(event -> listener.valueChange(
new ValueChangeEvent<>(this, event.isUserOriginated())));
}
public Registration addValueChangeListener(
HasValue.ValueChangeListener<T> listener) {
return addSelectionListener(event -> {
- listener.accept(new ValueChangeEvent<>(event.getComponent(), this,
+ listener.valueChange(new ValueChangeEvent<>(event.getComponent(), this,
event.isUserOriginated()));
});
}
import java.util.UUID;
import java.util.function.BiFunction;
import java.util.function.BinaryOperator;
-import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.vaadin.data.Listing;
import com.vaadin.data.SelectionModel;
import com.vaadin.event.ConnectorEvent;
-import com.vaadin.event.ConnectorEventListener;
import com.vaadin.event.ContextClickEvent;
+import com.vaadin.event.SerializableEventListener;
import com.vaadin.event.selection.MultiSelectionListener;
import com.vaadin.event.selection.SelectionListener;
import com.vaadin.event.selection.SingleSelectionListener;
@Deprecated
private static final Method ITEM_CLICK_METHOD = ReflectTools
- .findMethod(ItemClickListener.class, "accept", ItemClick.class);
+ .findMethod(ItemClickListener.class, "itemClick", ItemClick.class);
@Deprecated
private static final Method COLUMN_VISIBILITY_METHOD = ReflectTools
@Override
public default Registration addSelectionListener(
SelectionListener<T> listener) {
- return addSingleSelectionListener(e -> listener.accept(e));
+ return addSingleSelectionListener(e -> listener.selectionChange(e));
}
/**
@Override
public default Registration addSelectionListener(
SelectionListener<T> listener) {
- return addMultiSelectionListener(e -> listener.accept(e));
+ return addMultiSelectionListener(e -> listener.selectionChange(e));
}
/**
* @see Registration
*/
@FunctionalInterface
- public interface ItemClickListener<T>
- extends Consumer<ItemClick<T>>, ConnectorEventListener {
+ public interface ItemClickListener<T> extends SerializableEventListener {
/**
* Invoked when this listener receives a item click event from a Grid to
* which it has been added.
* @param event
* the received event, not null
*/
- @Override
- public void accept(ItemClick<T> event);
+ public void itemClick(ItemClick<T> event);
}
/**
for (Column<T, ?> column : getColumns()) {
Object value = column.valueProvider.apply(item);
tableRow.appendElement("td")
- .append((Optional.ofNullable(value).map(Object::toString)
+ .append(Optional.ofNullable(value).map(Object::toString)
.map(DesignFormatter::encodeForTextNode)
- .orElse("")));
+ .orElse(""));
}
}
implements BinderValidationStatusHandler<T> {
@Override
- public void accept(BinderValidationStatus<T> status) {
+ public void statusChange(BinderValidationStatus<T> status) {
boolean ok = status.isOk();
if (saving) {
rpc.confirmSave(ok);
*/
package com.vaadin.ui.components.grid;
-import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedHashSet;
import com.vaadin.shared.ui.grid.MultiSelectionModelState;
import com.vaadin.ui.Grid.MultiSelectionModel;
import com.vaadin.ui.MultiSelect;
-import com.vaadin.util.ReflectTools;
/**
* Multiselection model for grid.
}
}
- @Deprecated
- private static final Method SELECTION_CHANGE_METHOD = ReflectTools
- .findMethod(MultiSelectionListener.class, "accept",
- MultiSelectionEvent.class);
-
private Set<T> selection = new LinkedHashSet<>();
private SelectAllCheckBoxVisibility selectAllCheckBoxVisibility = SelectAllCheckBoxVisibility.DEFAULT;
public Registration addMultiSelectionListener(
MultiSelectionListener<T> listener) {
return addListener(MultiSelectionEvent.class, listener,
- SELECTION_CHANGE_METHOD);
+ MultiSelectionListener.SELECTION_CHANGE_METHOD);
}
@Override
@Override
public Registration addValueChangeListener(
com.vaadin.data.HasValue.ValueChangeListener<Set<T>> listener) {
- return addSelectionListener(event -> listener.accept(event));
+ return addSelectionListener(
+ event -> listener.valueChange(event));
}
@Override
*/
package com.vaadin.ui.components.grid;
-import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import com.vaadin.ui.Component;
import com.vaadin.ui.Grid.SingleSelectionModel;
import com.vaadin.ui.SingleSelect;
-import com.vaadin.util.ReflectTools;
/**
* Single selection model for grid.
public class SingleSelectionModelImpl<T> extends AbstractSelectionModel<T>
implements SingleSelectionModel<T> {
- private static final Method SELECTION_CHANGE_METHOD = ReflectTools
- .findMethod(SingleSelectionListener.class, "accept",
- SingleSelectionEvent.class);
-
private T selectedItem = null;
@Override
public Registration addSingleSelectionListener(
SingleSelectionListener<T> listener) {
return addListener(SingleSelectionEvent.class, listener,
- SELECTION_CHANGE_METHOD);
+ SingleSelectionListener.SELECTION_CHANGE_METHOD);
}
@Override
com.vaadin.data.HasValue.ValueChangeListener<T> listener) {
return SingleSelectionModelImpl.this.addSingleSelectionListener(
(SingleSelectionListener<T>) event -> listener
- .accept(event));
+ .valueChange(event));
}
@Override
private void assertInvalid(HasValue<?> field, String message) {
BinderValidationStatus<?> status = binder.validate();
- List<ValidationStatus<?>> errors = status.getFieldValidationErrors();
+ List<BindingValidationStatus<?>> errors = status.getFieldValidationErrors();
assertEquals(1, errors.size());
assertSame(field, errors.get(0).getField());
assertEquals(message, errors.get(0).getMessage().get());
import com.vaadin.data.Binder.Binding;
import com.vaadin.data.Binder.BindingBuilder;
-import com.vaadin.data.ValidationStatus.Status;
+import com.vaadin.data.BindingValidationStatus.Status;
import com.vaadin.data.util.converter.Converter;
import com.vaadin.data.util.converter.StringToIntegerConverter;
import com.vaadin.data.util.converter.ValueContext;
departing.setValue(before);
returning.setValue(after);
- ValidationStatus<LocalDate> result = returnBinding.validate();
+ BindingValidationStatus<LocalDate> result = returnBinding.validate();
Assert.assertFalse(result.isError());
Assert.assertNull(departing.getComponentError());
@Test
public void withBindingStatusHandlerExample() {
Label nameStatus = new Label();
- AtomicReference<ValidationStatus<?>> statusCapture = new AtomicReference<>();
+ AtomicReference<BindingValidationStatus<?>> statusCapture = new AtomicReference<>();
String msg = "Full name must contain at least three characters";
binder.forField(field).withValidator(name -> name.length() >= 3, msg)
Assert.assertTrue(nameStatus.isVisible());
Assert.assertEquals(msg, nameStatus.getValue());
Assert.assertNotNull(statusCapture.get());
- ValidationStatus<?> status = statusCapture.get();
+ BindingValidationStatus<?> status = statusCapture.get();
Assert.assertEquals(Status.ERROR, status.getStatus());
Assert.assertEquals(msg, status.getMessage().get());
Assert.assertEquals(field, status.getField());
formStatusLabel.setVisible(!errorMessage.isEmpty());
// Let the default handler show messages for each field
- defaultHandler.accept(status);
+ defaultHandler.statusChange(status);
});
final String bindingMessage = "uneven";
binding.bind(Person::getFirstName, Person::setFirstName);
BinderValidationStatus<Person> status = binder.validate();
- List<ValidationStatus<?>> errors = status.getFieldValidationErrors();
+ List<BindingValidationStatus<?>> errors = status.getFieldValidationErrors();
assertEquals(1, errors.size());
- ValidationStatus<?> validationStatus = errors.stream().findFirst()
+ BindingValidationStatus<?> validationStatus = errors.stream().findFirst()
.get();
String msg = validationStatus.getMessage().get();
assertEquals(msg1, msg);
}
private void assertValidationErrors(
- List<ValidationStatus<?>> validationErrors,
+ List<BindingValidationStatus<?>> validationErrors,
String... errorMessages) {
assertEquals(errorMessages.length, validationErrors.size());
for (int i = 0; i < errorMessages.length; i++) {
Person person = new Person();
binder.setBean(person);
- List<ValidationStatus<?>> errors = binder.validate()
+ List<BindingValidationStatus<?>> errors = binder.validate()
.getFieldValidationErrors();
assertEquals(0, errors.size());
}
Person person = new Person();
binder.setBean(person);
- List<ValidationStatus<?>> errors = binder.validate()
+ List<BindingValidationStatus<?>> errors = binder.validate()
.getFieldValidationErrors();
assertEquals(1, errors.size());
- ValidationStatus<?> error = errors.get(0);
+ BindingValidationStatus<?> error = errors.get(0);
assertEquals(msg, error.getMessage().get());
assertEquals(nameField, error.getField());
}
Person person = new Person();
binder.setBean(person);
- List<ValidationStatus<?>> errors = binder.validate()
+ List<BindingValidationStatus<?>> errors = binder.validate()
.getFieldValidationErrors();
assertEquals(1, errors.size());
- ValidationStatus<?> error = errors.get(0);
+ BindingValidationStatus<?> error = errors.get(0);
assertEquals(msg1, error.getMessage().get());
assertEquals(nameField, error.getField());
binder.writeBean(person);
Assert.fail();
} catch (ValidationException exception) {
- List<ValidationStatus<?>> validationErrors = exception
+ List<BindingValidationStatus<?>> validationErrors = exception
.getFieldValidationErrors();
Assert.assertEquals(2, validationErrors.size());
- ValidationStatus<?> error = validationErrors.get(0);
+ BindingValidationStatus<?> error = validationErrors.get(0);
Assert.assertEquals(nameField, error.getField());
Assert.assertEquals(msg, error.getMessage().get());
import com.vaadin.data.Binder.Binding;
import com.vaadin.data.Binder.BindingBuilder;
-import com.vaadin.data.ValidationStatus.Status;
+import com.vaadin.data.BindingValidationStatus.Status;
import com.vaadin.tests.data.bean.Person;
import com.vaadin.ui.Label;
public class BinderValidationStatusTest
extends BinderTestBase<Binder<Person>, Person> {
- protected final static ValidationStatusHandler NOOP = event -> {
+ protected final static BindingValidationStatusHandler NOOP = event -> {
};
@Before
@Test
public void bindingWithStatusHandler_handlerGetsEvents() {
- AtomicReference<ValidationStatus<?>> statusCapture = new AtomicReference<>();
+ AtomicReference<BindingValidationStatus<?>> statusCapture = new AtomicReference<>();
BindingBuilder<Person, String> binding = binder.forField(nameField)
.withValidator(notEmpty).withValidationStatusHandler(evt -> {
Assert.assertNull(statusCapture.get());
binder.validate();
Assert.assertNotNull(statusCapture.get());
- ValidationStatus<?> evt = statusCapture.get();
+ BindingValidationStatus<?> evt = statusCapture.get();
Assert.assertEquals(Status.ERROR, evt.getStatus());
Assert.assertEquals(EMPTY_ERROR_MESSAGE, evt.getMessage().get());
Assert.assertEquals(nameField, evt.getField());
Assert.assertNull(nameField.getComponentError());
- List<ValidationStatus<?>> bindingStatuses = status
+ List<BindingValidationStatus<?>> bindingStatuses = status
.getFieldValidationStatuses();
Assert.assertNotNull(bindingStatuses);
Assert.assertEquals(1, status.getFieldValidationErrors().size());
Assert.assertEquals(2, bindingStatuses.size());
- ValidationStatus<?> r = bindingStatuses.get(0);
+ BindingValidationStatus<?> r = bindingStatuses.get(0);
Assert.assertTrue(r.isError());
Assert.assertEquals(EMPTY_ERROR_MESSAGE, r.getMessage().get());
Assert.assertEquals(nameField, r.getField());
Assert.assertNull(nameField.getComponentError());
- List<ValidationStatus<?>> bindingStatuses = status
+ List<BindingValidationStatus<?>> bindingStatuses = status
.getFieldValidationStatuses();
Assert.assertNotNull(bindingStatuses);
Assert.assertEquals(1, status.getFieldValidationErrors().size());
Assert.assertEquals(2, bindingStatuses.size());
- ValidationStatus<?> r = bindingStatuses.get(0);
+ BindingValidationStatus<?> r = bindingStatuses.get(0);
Assert.assertTrue(r.isError());
Assert.assertEquals(EMPTY_ERROR_MESSAGE, r.getMessage().get());
Assert.assertEquals(nameField, r.getField());
nameField.setValue("foo");
binder.validate();
- List<ValidationStatus<?>> results = capture.get()
+ List<BindingValidationStatus<?>> results = capture.get()
.getFieldValidationStatuses();
Assert.assertNotNull(results);
Assert.assertEquals(1, results.size());
});
Assert.assertSame(registration, actualRegistration);
- selectionListener.get().accept(new MultiSelectionEvent<>(grid,
+ selectionListener.get().selectionChange(new MultiSelectionEvent<>(grid,
model.asMultiSelect(), Collections.emptySet(), true));
Assert.assertEquals(grid, event.get().getComponent());
});
Assert.assertSame(registration, actualRegistration);
- selectionListener.get().accept(new SingleSelectionEvent<>(grid,
+ selectionListener.get().selectionChange(new SingleSelectionEvent<>(grid,
select.asSingleSelect(), true));
Assert.assertEquals(grid, event.get().getComponent());
@Test
public void valueChangeListenerInvoked() {
- l.accept(EasyMock.capture(capture));
+ l.valueChange(EasyMock.capture(capture));
replayAll();
field.setValue("foo");
@Test
public void valueChangeListenerInvokedFromClient() {
- l.accept(EasyMock.capture(capture));
+ l.valueChange(EasyMock.capture(capture));
replayAll();
field.setValue("foo");
Assert.assertSame(registration, actualRegistration);
- selectionListener.get().accept(new MultiSelectionEvent<>(select,
+ selectionListener.get().selectionChange(new MultiSelectionEvent<>(select,
Mockito.mock(Set.class), true));
Assert.assertEquals(select, event.get().getComponent());
Assert.assertSame(registration, actualRegistration);
selectionListener.get()
- .accept(new SingleSelectionEvent<>(select, true));
+ .selectionChange(new SingleSelectionEvent<>(select, true));
Assert.assertEquals(select, event.get().getComponent());
Assert.assertEquals(value, event.get().getValue());
private ValueChangeListener<V> valueChangeListener = new ValueChangeListener<V>() {
@Override
- public void accept(ValueChangeEvent<V> event) {
+ public void valueChange(ValueChangeEvent<V> event) {
log(event.getClass().getSimpleName() + ", new value: "
+ formatValue(event.getValue()));
}
}
@Override
- public void accept(ValueChangeEvent<LocalDate> event) {
+ public void valueChange(ValueChangeEvent<LocalDate> event) {
getMainWindow().showNotification("New value" + event.getValue());
}
};
@Override
- public void accept(ValueChangeEvent<Boolean> event) {
+ public void valueChange(ValueChangeEvent<Boolean> event) {
if (table.getListeners(HeaderClickEvent.class)
.isEmpty()) {
table.addHeaderClickListener(headerClickListener);
};
@Override
- public void accept(ValueChangeEvent<Boolean> event) {
+ public void valueChange(ValueChangeEvent<Boolean> event) {
if (table.getListeners(FooterClickEvent.class)
.isEmpty()) {
table.addFooterClickListener(footerClickListener);