com.holonplatform.vaadin.components.ValidatableInput Maven / Gradle / Ivy
/*
* Copyright 2000-2017 Holon TDCN.
*
* 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.holonplatform.vaadin.components;
import java.util.Optional;
import com.holonplatform.core.Validator;
import com.holonplatform.core.internal.utils.ObjectUtils;
import com.holonplatform.vaadin.components.builders.ValidatableInputBuilder;
import com.holonplatform.vaadin.internal.components.ValidatableInputWrapper;
import com.holonplatform.vaadin.internal.components.builders.DefaultValidatableInputBuilder;
import com.vaadin.data.HasValue;
import com.vaadin.shared.Registration;
import com.vaadin.ui.Component;
/**
* An {@link Input} component with validation support using {@link Validator}s.
*
* @param Value type
*
* @since 5.0.0
*/
public interface ValidatableInput extends Input, Validatable {
/**
* Adds a {@link Validator} to validate the input value.
* @param validator The validator to add (not null)
* @return The validator registration reference
*/
Registration addValidator(Validator validator);
/**
* Sets whether to validate the value, using registered {@link Validator}s, every time the {@link Input} value
* changes.
* @param validateOnValueChange true
to perform value validation every time the {@link Input} value
* changes, false
if not
*/
void setValidateOnValueChange(boolean validateOnValueChange);
/**
* Gets whether to validate the value, using registered {@link Validator}s, every time the {@link Input} value
* changes.
*
* Default is true
.
*
* @return true
if the value validation must be performed every time the {@link Input} value changes
*/
boolean isValidateOnValueChange();
/**
* Set the {@link ValidationStatusHandler} to use to track validation status changes.
* @param validationStatusHandler the {@link ValidationStatusHandler} to set
*/
void setValidationStatusHandler(ValidationStatusHandler validationStatusHandler);
/**
* Get the {@link ValidationStatusHandler} to use to track validation status changes, if available.
* @return the optional {@link ValidationStatusHandler}
*/
Optional getValidationStatusHandler();
/**
* Create a {@link ValidatableInput} from given {@link Input} instance.
* @param Value type
* @param input The {@link Input} instance (not null)
* @return A new {@link ValidatableInput} component which wraps the given input
*/
static ValidatableInput from(Input input) {
ObjectUtils.argumentNotNull(input, "Input must be not null");
return (input instanceof ValidatableInput) ? (ValidatableInput) input : new ValidatableInputWrapper<>(input);
}
/**
* Create a {@link ValidatableInput} component type from given {@link HasValue} component.
* @param Value type
* @param {@link HasValue} component type
* @param field The field instance (not null)
* @return A new {@link ValidatableInput} component which wraps the given field
*/
static & Component, T> ValidatableInput from(F field) {
return from(Input.from(field));
}
/**
* Get a fluent builder to create and setup a {@link ValidatableInput} from given {@link Input}.
* @param Value type
* @param input Concrete input component (not null)
* @return {@link ValidatableInput} builder
*/
static ValidatableInputBuilder> builder(Input input) {
return new DefaultValidatableInputBuilder<>(input);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy