Class DefaultValueModel<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:
    DefaultTreeNodeModel, Table.DefaultCellValueModel, ValuePrototype

    public class DefaultValueModel<V>
    extends AbstractValueModel<V>
    A default implementation of a model representing a value.
    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
      DefaultValueModel​(java.lang.Class<V> valueClass)
      Constructs a value model indicating the type of value it can hold.
      DefaultValueModel​(java.lang.Class<V> valueClass, V defaultValue)
      Constructs a value model indicating the type of value it can hold, along with an initial value.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void clearValue()
      Clears the value by setting the value to null, which may be invalid according to any installed validators.
      V getDefaultValue()  
      V getValue()  
      void resetValue()
      Resets the value to a default value, which may be invalid according to any installed validators.
      void setValue​(V newValue)
      Sets the new value.
      • 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

      • DefaultValueModel

        public DefaultValueModel​(java.lang.Class<V> valueClass)
        Constructs a value model indicating the type of value it can hold. The default value is set to null.
        Parameters:
        valueClass - The class indicating the type of value held in the model.
        Throws:
        java.lang.NullPointerException - if the given value class is null.
      • DefaultValueModel

        public DefaultValueModel​(java.lang.Class<V> valueClass,
                                 V defaultValue)
        Constructs a value model indicating the type of value it can hold, along with an initial value.
        Parameters:
        valueClass - The class indicating the type of value held in the model.
        defaultValue - The default value, which will not be validated.
        Throws:
        java.lang.NullPointerException - if the given value class is null.
    • Method Detail

      • getDefaultValue

        public V getDefaultValue()
        Returns:
        The default value.
      • getValue

        public V getValue()
        Returns:
        The input value, or null if there is no input value.
      • setValue

        public void setValue​(V newValue)
                      throws java.beans.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().
        Parameters:
        newValue - The new value.
        Throws:
        java.beans.PropertyVetoException - if the provided value is not valid or the change has otherwise been vetoed.
        See Also:
        ValueModel.getValidator(), ValueModel.VALUE_PROPERTY
      • 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.
        See Also:
        ValueModel.VALUE_PROPERTY
      • 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.
        See Also:
        ValueModel.VALUE_PROPERTY