Class 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
    • Constructor Summary

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

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static <VV> java.beans.PropertyVetoException createPropertyVetoException​(java.lang.Object source, ValidationException validationException, java.lang.String propertyName, VV oldValue, VV newValue)
      Creates a property veto exception that represents a validation exception.
      Validator<V> getValidator()  
      java.lang.Class<V> getValueClass()  
      boolean isValidValue()
      Determines whether the value of this model is valid.
      void setValidator​(Validator<V> newValidator)
      Sets the validator.
      void validateValue()
      Validates the value of this model, throwing an exception if the model is not valid.
      • 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
    • Constructor Detail

      • AbstractValueModel

        public AbstractValueModel​(java.lang.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:
        java.lang.NullPointerException - if the given value class is null.
    • Method Detail

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

        public java.lang.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:
        getValidator(), ValueModel.getValue()
      • 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> java.beans.PropertyVetoException createPropertyVetoException​(java.lang.Object source,
                                                                                        ValidationException validationException,
                                                                                        java.lang.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.