Class AbstractValueModel<V>

java.lang.Object
com.globalmentor.beans.BoundPropertyObject
io.guise.framework.model.AbstractModel
io.guise.framework.model.AbstractValueModel<V>
Type Parameters:
V - The type of value contained in the model.
All Implemented Interfaces:
com.globalmentor.beans.PropertyBindable, com.globalmentor.beans.PropertyConstrainable, com.globalmentor.model.MutableValued<V>, com.globalmentor.model.Valued<V>, Model, ValueModel<V>
Direct Known Subclasses:
DefaultListSelectModel, DefaultValueModel

public abstract class AbstractValueModel<V> extends AbstractModel implements ValueModel<V>
An abstract implementation of a model representing a value. A derived class need only implement the value access methods.
Author:
Garret Wilson
  • Field Summary

    Fields inherited from class com.globalmentor.beans.BoundPropertyObject

    NO_PROPERTY_CHANGE_LISTENERS, NO_VETOABLE_CHANGE_LISTENERS

    Fields inherited from interface io.guise.framework.model.ValueModel

    VALIDATOR_PROPERTY, VALUE_PROPERTY
  • Constructor Summary

    Constructors
    Constructor
    Description
    AbstractValueModel(Class<V> valueClass)
    Constructs a value model indicating the type of value it can hold.
  • Method Summary

    Modifier and Type
    Method
    Description
    createPropertyVetoException(Object source, ValidationException validationException, String propertyName, VV oldValue, VV newValue)
    Creates a property veto exception that represents a validation exception.
     
     
    boolean
    Determines whether the value of this model is valid.
    void
    setValidator(Validator<V> newValidator)
    Sets the validator.
    void
    Validates the value of this model, throwing an exception if the model is not valid.

    Methods inherited from class io.guise.framework.model.AbstractModel

    getEventListenerManager, getPlainText

    Methods inherited from class com.globalmentor.beans.BoundPropertyObject

    addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, createPostponedPropertyChangeEvent, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getForwardPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, getPropertyChangeSupport, getRepeatPropertyChangeListener, getRepeatVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, getVetoableChangeSupport, hasPropertyChangeListeners, hasVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.globalmentor.beans.PropertyBindable

    addPropertyChangeListener, addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, hasPropertyChangeListeners, removePropertyChangeListener, removePropertyChangeListener

    Methods inherited from interface com.globalmentor.beans.PropertyConstrainable

    addVetoableChangeListener, addVetoableChangeListener, getVetoableChangeListeners, getVetoableChangeListeners, hasVetoableChangeListeners, removeVetoableChangeListener, removeVetoableChangeListener

    Methods inherited from interface io.guise.framework.model.ValueModel

    clearValue, getDefaultValue, getValue, resetValue, setValue
  • Constructor Details

    • AbstractValueModel

      public AbstractValueModel(Class<V> valueClass)
      Constructs a value model indicating the type of value it can hold.
      Parameters:
      valueClass - The class indicating the type of value held in the model.
      Throws:
      NullPointerException - if the given value class is null.
  • Method Details

    • 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:
    • getValueClass

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

      public boolean isValidValue()
      Determines whether the value of this model is valid.

      This version delegates to the validator, if one is installed.

      Specified by:
      isValidValue in interface ValueModel<V>
      Returns:
      Whether the value of this model is valid.
      See Also:
    • validateValue

      public void validateValue() throws ValidationException
      Validates the value of this model, throwing an exception if the model is not valid.

      This version validates the current value if there is a validator installed.

      Specified by:
      validateValue in interface ValueModel<V>
      Throws:
      ValidationException - if the value of this model is not valid.
    • createPropertyVetoException

      public static <VV> PropertyVetoException createPropertyVetoException(Object source, ValidationException validationException, String propertyName, VV oldValue, VV newValue)
      Creates a property veto exception that represents a validation exception. The validation exception will be accessible via Throwable.getCause(). This is useful for converting a validation exception into a property veto exception in ValueModel.setValue(Object) if an installed validator deems a value invalid.
      Type Parameters:
      VV - The type of property the change of which was vetoed because of invalidity.
      Parameters:
      source - The source of the property change event.
      validationException - The validation exception that is the cause of the property veto.
      propertyName - The name of the property the change of which was vetoed.
      oldValue - The old value of the property.
      newValue - The new value of the property.
      Returns:
      A property veto exception representing the validation error.