Class AbstractLayoutValueControl<V>

Type Parameters:
V - The type of value to represent.
All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable, com.globalmentor.beans.PropertyConstrainable, com.globalmentor.model.MutableValued<V>, com.globalmentor.model.Valued<V>, io.clogr.Clogged, Component, CompositeComponent, Control, InputFocusableComponent, LayoutComponent, LayoutControl, ValueControl<V>, ValuedComponent<V>, Displayable, Enableable, InfoModel, LabelModel, Model, PresentationModel, ValueModel<V>, DepictedObject
Direct Known Subclasses:
CalendarControl, DateTimeControl, DateTimeFieldsControl

public abstract class AbstractLayoutValueControl<V> extends AbstractLayoutControl implements ValueControl<V>
An abstract implementation of a layout component that is also a value control. The component valid status is updated before a change in the ValueModel.VALUE_PROPERTY or the ValueModel.VALIDATOR_PROPERTY is fired.
Author:
Garret Wilson
  • Constructor Details

    • AbstractLayoutValueControl

      public AbstractLayoutValueControl(Layout<?> layout, ValueModel<V> valueModel)
      Layout and value model constructor.
      Parameters:
      layout - The layout definition for the layout component.
      valueModel - The component value model.
      Throws:
      NullPointerException - if the given layout and/or value model is null.
  • Method Details

    • getValueModel

      protected ValueModel<V> getValueModel()
      Returns:
      The value model used by this component.
    • firePropertyChange

      protected <VV> void firePropertyChange(String propertyName, VV oldValue, VV newValue)

      This version first updates the valid status if the value is reported as being changed.

      Overrides:
      firePropertyChange in class com.globalmentor.beans.BoundPropertyObject
    • determineValid

      protected boolean determineValid()
      Checks the state of the component for validity. This version returns true.

      This version calls AbstractCompositeComponent.determineChildrenValid().

      This version checks the validity of the value model.

      Overrides:
      determineValid in class AbstractCompositeComponent
      Returns:
      true if the component and all children passes all validity tests, else false.
    • validate

      public boolean validate()
      Validates the user input of this component and all child components. The component will be updated with error information.

      This version clears all notifications. This version calls AbstractComponent.updateValid().

      This version first calls AbstractCompositeComponent.validateChildren() so that all children will be validated before checks are performed on this component.

      This version validates the associated value model.

      Specified by:
      validate in interface Component
      Overrides:
      validate in class AbstractCompositeComponent
      Returns:
      The current state of Component.isValid() as a convenience.
    • getDefaultValue

      public V getDefaultValue()
      Specified by:
      getDefaultValue in interface ValueModel<V>
      Returns:
      The default value.
    • getValue

      public V getValue()
      Specified by:
      getValue in interface com.globalmentor.model.Valued<V>
      Specified by:
      getValue in interface ValuedComponent<V>
      Specified by:
      getValue in interface ValueModel<V>
      Returns:
      The input value, or null if there is no input value.
    • setValue

      public void setValue(V newValue) throws PropertyVetoException
      Description copied from interface: ValueModel
      Sets the new value. This is a bound property that only fires a change event when the new value is different via the equals() method. If a validator is installed, the value will first be validated before the current value is changed. Validation always occurs if a validator is installed, even if the value is not changing. If the value change is vetoed by the installed validator, the validation exception will be accessible via Throwable.getCause().
      Specified by:
      setValue in interface com.globalmentor.model.MutableValued<V>
      Specified by:
      setValue in interface ValuedComponent<V>
      Specified by:
      setValue in interface ValueModel<V>
      Parameters:
      newValue - The new value.
      Throws:
      PropertyVetoException - if the provided value is not valid or the change has otherwise been vetoed.
      See Also:
    • clearValue

      public void clearValue()
      Description copied from interface: ValueModel
      Clears the value by setting the value to null, which may be invalid according to any installed validators. No validation occurs.
      Specified by:
      clearValue in interface ValueModel<V>
      See Also:
    • resetValue

      public void resetValue()
      Description copied from interface: ValueModel
      Resets the value to a default value, which may be invalid according to any installed validators. No validation occurs.
      Specified by:
      resetValue in interface ValueModel<V>
      See Also:
    • getValidator

      public Validator<V> getValidator()
      Specified by:
      getValidator in interface ValueModel<V>
      Returns:
      The validator for this model, or null if no validator is installed.
    • setValidator

      public void setValidator(Validator<V> newValidator)
      Description copied from interface: ValueModel
      Sets the validator. This is a bound property
      Specified by:
      setValidator in interface ValueModel<V>
      Parameters:
      newValidator - The validator for this model, or null if no validator should be used.
      See Also:
    • isValidValue

      public boolean isValidValue()
      Description copied from interface: ValueModel
      Determines whether the value of this model is valid.
      Specified by:
      isValidValue in interface ValueModel<V>
      Returns:
      Whether the value of this model is valid.
    • validateValue

      public void validateValue() throws ValidationException
      Description copied from interface: ValueModel
      Validates the value of this model, throwing an exception if the model is not valid.
      Specified by:
      validateValue in interface ValueModel<V>
      Throws:
      ValidationException - if the value of this model is not valid.
    • getValueClass

      public Class<V> getValueClass()
      Specified by:
      getValueClass in interface ValuedComponent<V>
      Specified by:
      getValueClass in interface ValueModel<V>
      Returns:
      The class representing the type of value this model can hold.