com.jgoodies.binding.value
Class AbstractVetoableValueModel

java.lang.Object
  extended by com.jgoodies.binding.beans.Model
      extended by com.jgoodies.binding.value.AbstractValueModel
          extended by com.jgoodies.binding.value.AbstractVetoableValueModel
All Implemented Interfaces:
Observable, ValueModel, java.io.Serializable

public abstract class AbstractVetoableValueModel
extends AbstractValueModel

A ValueModel that allows to accept or reject proposed value changes. Useful to request information from the user or to perform operations before a value is changed.

Wraps a given subject ValueModel and always returns the subject value as this model's value. Observes subject value changes and forwards them to listeners of this model. If a value is set to this model, the abstract method #proposedChange is invoked. In this method implementors define how to accept or reject value changes.

Implementors may veto against a proposed change based on the application state or by asking the user, and may also perform additional operations during the check, for example to save editor contents. Here's an example:

 public class CheckPendingEditValueModel extends AbstractVetoableValueModel {

     public CheckPendingEditValueModel(ValueModel subject) {
         super(subject);
     }

     public boolean proposedChange(Object oldValue, Object proposedNewValue) {
         if (equals(oldValue, proposedNewValue))
             return true;
         int option = JOptionPane.showConfirmDialog(
             Application.getDefaultParentFrame(),
             "Do you want to save the editor contents.");
         if (option == JOptionPane.YES_OPTION)
             model.save();
         return option != JOptionPane.CANCEL_OPTION;
     }
 }
 

Since:
1.1
Version:
$Revision: 1.9 $
Author:
Karsten Lentzsch
See Also:
Serialized Form

Field Summary
 
Fields inherited from class com.jgoodies.binding.value.AbstractValueModel
PROPERTYNAME_VALUE
 
Constructor Summary
protected AbstractVetoableValueModel(ValueModel subject)
          Constructs an AbstractVetoableValueModel for the given ValueModel.
 
Method Summary
 java.lang.Object getValue()
          Returns this model's current subject value.
abstract  boolean proposedChange(java.lang.Object oldValue, java.lang.Object proposedNewValue)
          Checks and answers whether the proposed value change shall be accepted or rejected.
 void setValue(java.lang.Object newValue)
          Sets the given value as new subject value if and only if 1) the new value differs from the old value and 2) the proposed change is accepted as checked by proposedChange(oldValue, newValue).
 
Methods inherited from class com.jgoodies.binding.value.AbstractValueModel
addValueChangeListener, booleanValue, doubleValue, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, floatValue, getString, intValue, longValue, removeValueChangeListener, setValue, setValue, setValue, setValue, setValue, toString
 
Methods inherited from class com.jgoodies.binding.beans.Model
addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, equals, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, fireMultiplePropertiesChanged, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

AbstractVetoableValueModel

protected AbstractVetoableValueModel(ValueModel subject)
Constructs an AbstractVetoableValueModel for the given ValueModel.

Parameters:
subject - the underlying (or wrapped) ValueModel
Throws:
java.lang.NullPointerException - if the subject is null
Method Detail

proposedChange

public abstract boolean proposedChange(java.lang.Object oldValue,
                                       java.lang.Object proposedNewValue)
Checks and answers whether the proposed value change shall be accepted or rejected. Implementors may perform additional operations, for example to save a pending editor content.

Parameters:
oldValue - the value before the change
proposedNewValue - the new value if the change is accepted
Returns:
true to accept the proposed value, false to veto against it.

getValue

public final java.lang.Object getValue()
Returns this model's current subject value.

Returns:
this model's current subject value.

setValue

public final void setValue(java.lang.Object newValue)
Sets the given value as new subject value if and only if 1) the new value differs from the old value and 2) the proposed change is accepted as checked by proposedChange(oldValue, newValue).

Parameters:
newValue - the value to set


Copyright © 2002-2008 JGoodies Karsten Lentzsch. All Rights Reserved.