/* * Copyright 2000-2022 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.Collections; import java.util.List; 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.UNRESOLVED}. Status OK and ERROR are * always associated with a ValidationResult {@link #getResult}. *
* Use
* {@link BindingBuilder#withValidationStatusHandler(BindingValidationStatusHandler)}
* to register a handler for field level validation status changes.
*
* @author Vaadin Ltd
*
* @param
* 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.
*
* In practice this status means that the value might be invalid, but
* validation errors should be hidden.
*/
UNRESOLVED;
}
private final Status status;
private final List
* 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}
*/
@Deprecated
public BindingValidationStatus(Binding, TARGET> source, Status status,
ValidationResult result) {
this(result.isError() ? Result.error(result.getErrorMessage())
: Result.ok(null), source);
}
/**
* Creates a new status change event.
*
* If {@code result} is {@code null}, the {@code status} is
* {@link Status#UNRESOLVED}.
*
* @param result
* the related result object, may be {@code null}
* @param source
* field whose status has changed, not {@code null}
*
* @since 8.2
*/
public BindingValidationStatus(Result