Class AbstractVetoableValue<T>

Type Parameters:
T - the type of value being observed
All Implemented Interfaces:
IObservable, IObservableValue<T>, IVetoableValue<T>

public abstract class AbstractVetoableValue<T> extends AbstractObservableValue<T> implements IVetoableValue<T>

This class is thread safe. All state accessing methods must be invoked from the current realm. Methods for adding and removing listeners may be invoked from any thread.

Since:
1.0
  • Constructor Details

    • AbstractVetoableValue

      public AbstractVetoableValue()
      Creates a new vetoable value.
    • AbstractVetoableValue

      public AbstractVetoableValue(Realm realm)
      Parameters:
      realm - the realm
  • Method Details

    • doSetValue

      protected final void doSetValue(T value)
      Description copied from class: AbstractObservableValue
      Template method for setting the value of the observable. By default the method throws an UnsupportedOperationException.
      Overrides:
      doSetValue in class AbstractObservableValue<T>
      Parameters:
      value - the value to set
    • doSetApprovedValue

      protected abstract void doSetApprovedValue(T value)
      Sets the value. Invoked after performing veto checks. Should not fire change events.
      Parameters:
      value - the approved value to set
    • addValueChangingListener

      public void addValueChangingListener(IValueChangingListener<T> listener)
      Specified by:
      addValueChangingListener in interface IVetoableValue<T>
      Parameters:
      listener - the listener to add; not null
    • removeValueChangingListener

      public void removeValueChangingListener(IValueChangingListener<T> listener)
      Specified by:
      removeValueChangingListener in interface IVetoableValue<T>
      Parameters:
      listener - the listener to remove; not null
    • fireValueChanging

      protected boolean fireValueChanging(ValueDiff<T> diff)
      Notifies listeners about a pending change, and returns true if no listener vetoed the change.
      Parameters:
      diff - the pending change
      Returns:
      false if the change was vetoed, true otherwise
    • addListener

      protected void addListener(Object listenerType, IObservablesListener listener)
      Parameters:
      listenerType - arbitrary object to identify a type of the listener
      listener - the listener to add; not null
    • removeListener

      protected void removeListener(Object listenerType, IObservablesListener listener)
      Parameters:
      listenerType - arbitrary object to identify a type of the listener
      listener - the listener to remove; not null
    • hasListeners

      protected boolean hasListeners()
    • fireEvent

      protected void fireEvent(ObservableEvent event)
    • firstListenerAdded

      protected void firstListenerAdded()
    • lastListenerRemoved

      protected void lastListenerRemoved()
    • getRealm

      public Realm getRealm()
      Returns:
      Returns the realm.
    • clone

      protected Object clone() throws CloneNotSupportedException
      Overrides:
      clone in class Object
      Throws:
      CloneNotSupportedException