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;
}
}
author: Karsten Lentzsch version: $Revision: 1.7 $ since: 1.1 |