com.jgoodies.binding.value
public abstract class AbstractVetoableValueModel extends AbstractValueModel
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; } }
PROPERTYNAME_VALUE
Modifier | Constructor and Description |
---|---|
protected |
AbstractVetoableValueModel(ValueModel subject)
Constructs an AbstractVetoableValueModel for the given ValueModel.
|
Modifier and Type | Method and Description |
---|---|
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) . |
addValueChangeListener, booleanValue, doubleValue, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, floatValue, getString, intValue, longValue, paramString, removeValueChangeListener, setValue, setValue, setValue, setValue, setValue, toString, valueString
createPropertyChangeSupport, firePropertyChange
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
addPropertyChangeListener, removePropertyChangeListener
protected AbstractVetoableValueModel(ValueModel subject)
subject
- the underlying (or wrapped) ValueModeljava.lang.NullPointerException
- if the subject is null
public abstract boolean proposedChange(java.lang.Object oldValue, java.lang.Object proposedNewValue)
oldValue
- the value before the changeproposedNewValue
- the new value if the change is acceptedpublic final java.lang.Object getValue()
public final void setValue(java.lang.Object newValue)
proposedChange(oldValue, newValue)
.newValue
- the value to setCopyright © 2002-2010 JGoodies Karsten Lentzsch. All Rights Reserved.