Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.jgoodies.binding.extras
Class AbstractVetoableValueModel  view AbstractVetoableValueModel download AbstractVetoableValueModel.java

java.lang.Object
  extended byAbstractValueModel
      extended bycom.jgoodies.binding.extras.AbstractVetoableValueModel

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;    
     }
 }
 
Note: This class is not yet part of the binary Binding library; it comes with the Binding distributions as an extra. The API is work in progress and may change without notice; this class may even be completely removed from future distributions. If you want to use this class, you may consider copying it into your codebase.

Version:
$Revision: 1.6 $

Nested Class Summary
private  class AbstractVetoableValueModel.SubjectValueChangeHandler
           
 
Field Summary
private  ValueModel subject
           
 
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.
(package private) 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

subject

private final ValueModel subject
Constructor Detail

AbstractVetoableValueModel

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

Method Detail

proposedChange

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.


getValue

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


setValue

public 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).