Class Binding<T>

java.lang.Object
be.imgn.swing.ui.Binding<T>
Type Parameters:
T - the type of the value

public final class Binding<T> extends Object
The binding of a component to a property in a Form, with the rules its value must meet.

Its validation has a check per requirement: first the converter's, if it has one, then one per rule, in the order they were added. Every rule is tested at each validation, whether or not an earlier one failed. When the converter rejects the field's text, the rules' checks are Check.Status.UNKNOWN. A rule that throws is a bug in the rule: the exception goes to the FailureHandler, and the rule's check is Check.Status.UNKNOWN; an Error is not caught. The binding is validated when it is bound, at each change of its component and at each change of its property.

Its error, the requirement of the first check that isn't met, is shown on its component by the ValidationFeedback while shown() is true, and hidden as soon as the binding has no error.

Every method is called on the EDT, and every subscription it makes belongs to the view's scope.

  • Method Summary

    Modifier and Type
    Method
    Description
    check(Rule<? super T> rule)
    Adds a rule to this binding, whose check follows those of the rules added before.
    check(Validator<? super T> validator)
    Adds the rules of a validator to this binding, in their order, after the rules added before.
    Validates this binding again at each change of another observable, on the EDT, such as the property of another field that a rule compares the value with: before the change returns for a change made on the EDT, such as the user's change of that field, once the list has released its lock for one delivered by an observable list, and in a posted update for one made on another thread.
    Returns whether this binding's error is shown: false until the user changes the component or Form.validate() is called, then true for the binding's life.
    Returns whether Form.validate() was called since the user last changed the component: false until it is called, then true until the user changes the component.
    Returns the last validation of this binding.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • check

      public Binding<T> check(Rule<? super T> rule)
      Adds a rule to this binding, whose check follows those of the rules added before.
      Parameters:
      rule - the rule
      Returns:
      this binding
      Throws:
      NullPointerException - if rule is null
    • check

      public Binding<T> check(Validator<? super T> validator)
      Adds the rules of a validator to this binding, in their order, after the rules added before.
      Parameters:
      validator - the validator
      Returns:
      this binding
      Throws:
      NullPointerException - if validator is null
    • revalidateOn

      public Binding<T> revalidateOn(Observable<?> other)
      Validates this binding again at each change of another observable, on the EDT, such as the property of another field that a rule compares the value with: before the change returns for a change made on the EDT, such as the user's change of that field, once the list has released its lock for one delivered by an observable list, and in a posted update for one made on another thread. A change of other is not a user change of this binding's component: it doesn't change shown() or validated().
      Parameters:
      other - the observable
      Returns:
      this binding
      Throws:
      NullPointerException - if other is null
    • validation

      public Observable<Validation> validation()
      Returns the last validation of this binding.
      Returns:
      the validation
    • shown

      public Observable<Boolean> shown()
      Returns whether this binding's error is shown: false until the user changes the component or Form.validate() is called, then true for the binding's life.
      Returns:
      whether the error is shown
    • validated

      public Observable<Boolean> validated()
      Returns whether Form.validate() was called since the user last changed the component: false until it is called, then true until the user changes the component. A change of the property, or of an observable the binding revalidates on, doesn't change it. A view that lists the requirements uses it to show them as failed after validate(), such as on OK, even for a value it otherwise shows as not yet checked.
      Returns:
      whether the binding was validated since the user last changed the component