/** * Creates a new {@code ValueChange} event containing the given value, * originating from the given source component. * * @param component * the component, not null * @param hasValue * the HasValue instance bearing the value, not null * @param oldValue * the previous value held by the source of this event * @param userOriginated * {@code true} if this event originates from the client, * {@code false} otherwise. */ public ValueChangeEvent(Component component, HasValue<V> hasValue, V oldValue, boolean userOriginated) { super(hasValue); this.userOriginated = userOriginated; this.component = component; this.oldValue = oldValue; value = hasValue.getValue(); }
/** * Returns the current value of this object, wrapped in an {@code Optional}. * <p> * The {@code Optional} will be empty if the value is {@code null} or * {@code isEmpty()} returns {@code true}. * * @return the current value, wrapped in an {@code Optional} */ public default Optional<V> getOptionalValue() { return isEmpty() ? Optional.empty() : Optional.ofNullable(getValue()); }
/** * Returns whether this {@code HasValue} is considered to be empty. * <p> * By default this is an equality check between current value and empty * value. * * @return {@code true} if considered empty; {@code false} if not */ public default boolean isEmpty() { return Objects.equals(getValue(), getEmptyValue()); }
/** * Returns the field value run through all converters and validators, * but doesn't pass the {@link BindingValidationStatus} to any status * handler. * * @return the result of the conversion */ private Result<TARGET> doConversion() { FIELDVALUE fieldValue = field.getValue(); return converterValidatorChain.convertToModel(fieldValue, createValueContext()); }
@Override public V getValue() { return field.getValue(); }
private void colorChanged(ValueChangeEvent<Color> event) { event.getSource().setValue(event.getValue()); setValue(event.getValue()); updatingColors = true; setRgbSliderValues(selectedColor); float[] hsv = selectedColor.getHSV(); setHsvSliderValues(hsv); updatingColors = false; for (HasValue<Color> s : selectors) { if (event.getSource() != s && s != this && s.getValue() != selectedColor) { s.setValue(selectedColor); } } }
@Override public T getValue() { return fromInternalValue(getInternalField().getValue()); }
public <PT> BindingBuilder<T, PT> applyConfiguration(BindingBuilder<T, PT> bindingBuilder, FieldDefinition<PT> definition, Object... parameters) { if (definition.isRequired()) { bindingBuilder.asRequired(definition.getRequiredErrorMessage()); } bindingBuilder = definition.getValidators().stream() .map(this::newValidator) .reduce(bindingBuilder, BindingBuilder::withValidator, defaultCombiner()); final Converter converter = newConverter(definition, bindingBuilder.getField(), parameters); if (converter != null) { bindingBuilder = bindingBuilder.withConverter(converter); final Class<? extends FieldDefinition> definitionType = definition.getClass(); bindingBuilder = applyTextFieldNullValueRepresentationWorkaround(bindingBuilder, definitionType); } final PT fieldValue = (PT) bindingBuilder.getField().getValue(); if (converter == null && fieldValue != null && !definition.getType().isInstance(fieldValue)) { log.warn(String.format("Type mismatch for field named [%s]. Configured type is [%s] but bound component value type is [%s] and no suitable converter has been found. Please check your configuration.", definition.getName(), definition.getType(), fieldValue.getClass())); } Optional.ofNullable(definition.getDefaultValue()).ifPresent(bindingBuilder::withNullRepresentation); return bindingBuilder; }
@Override public void validate() throws ValidationException { if (hasValidationError()) { setValidationError(null); } if (!isVisibleRecursive() || !isEditableWithParent() || !isEnabledRecursive()) { return; } try { // if we cannot convert current presentation value into model - UI value is invalid convertToModel(component.getValue()); } catch (ConversionException ce) { LoggerFactory.getLogger(getClass()).trace("Unable to convert presentation value to model", ce); setValidationError(ce.getLocalizedMessage()); throw new ValidationException(ce.getLocalizedMessage()); } if (isEmpty() && isRequired()) { String requiredMessage = getRequiredMessage(); if (requiredMessage == null) { Messages messages = beanLocator.get(Messages.NAME); requiredMessage = messages.getMainMessage("validationFail.defaultRequiredMessage"); } throw new RequiredValueMissingException(requiredMessage, this); } V value = getValue(); triggerValidators(value); }