Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

## com.jgoodies.binding.extras
Class ChangeTracker

    java.lang.Object
      com.jgoodies.binding.beans.Model
          com.jgoodies.binding.extras.ChangeTracker

All Implemented Interfaces:
  Observable, Serializable

    public final class ChangeTracker

extends Model

Tracks changes in a set of bound bean properties. The tracker itself provides a read-only bound bean property changed that indicates whether one of the observed properties has changed. The changed state can be reset to `false` using `#reset`.

The tracker can observe readable bound bean properties if and only if the bean provides the optional support for listening on named properties as described in section 7.4.5 of the Java Bean Secification. The bean class must provide the following pair of methods:

     public void addPropertyChangeListener(String name, PropertyChangeListener l);
     public void removePropertyChangeListener(String name, PropertyChangeListener l);

Example:

     ChangeTracker tracker = new ChangeTracker();
     tracker.observe(address, "street");
     tracker.observe(address, "city");
     tracker.addPropertyChangeListener(new PropertyChangeListener() {

         public void propertyChange(PropertyChangeEvent evt) {
             System.out.println("Change state: " + evt.getNewValue());
         }
     });

     // Change the first ValueModel
     System.out.println(tracker.isChanged()); // Prints "false"
     address.setStreet("Belsenplatz");        // Prints "Change state: true"
     System.out.println(tracker.isChanged()); // Prints "true"
     tracker.reset();                         // Prints "Change state: false"
     System.out.println(tracker.isChanged()); // Prints "false"

Note: The classes `BeanAdapter` and `PresentationModel` already provide support for tracking changes. Typical binding code can use these classes and there seems to be no need to use the ChangeTracker.

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.13 $
Author:
  Karsten Lentzsch
See Also:
  `ValueModel`, Serialized Form

Field Summary
`static String` | `PROPERTYNAME_CHANGED` The name of the read-only bound bean property that indicates whether one of the observed properties has changed.

Constructor Summary
`ChangeTracker()` Constructs a change tracker with change state set to `false`.

Method Summary
`boolean` | `isChanged()` Answers whether one of the registered ValueModels has changed since this tracker has been reset last time.
`void` | `observe(Object bean, String propertyName)` Observes the specified readable bound bean property in the given bean.
`void` | `observe(ValueModel valueModel)` Observes value changes in the given ValueModel.
`void` | `reset()` Resets this tracker's changed state to `false`.
`void` | `retractInterestFor(Object bean, String propertyName)` Retracts interest for the specified readable bound bean property in the given bean.
`void` | `retractInterestFor(ValueModel valueModel)` Retracts interest for value changes in the given ValueModel.

Methods inherited from class com.jgoodies.binding.beans.Model
`addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, equals, fireMulticastPropertyChange, fireMultiplePropertiesChanged, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, 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, toString, wait, wait, wait`

Field Detail

### PROPERTYNAME_CHANGED

    public static final String PROPERTYNAME_CHANGED

  The name of the read-only bound bean property that indicates whether one of the observed properties has changed.

  See Also:
    `isChanged()`, Constant Field Values

Constructor Detail

### ChangeTracker

    public ChangeTracker()

  Constructs a change tracker with change state set to `false`.

Method Detail

### isChanged

    public boolean isChanged()

  Answers whether one of the registered ValueModels has changed since this tracker has been reset last time.

  Returns:
    true if an observed property has changed since the last reset

### reset

    public void reset()

  Resets this tracker's changed state to `false`.

### observe

    public void observe(Object bean,
                        String propertyName)

  Observes the specified readable bound bean property in the given bean.

  Parameters:
    `bean` - the bean to be observed
    `propertyName` - the name of the readable bound bean property
  Throws:
    `NullPointerException` - if the bean or propertyName is null
    `PropertyNotBindableException` - if this tracker can't add the PropertyChangeListener from the bean
  See Also:
    `retractInterestFor(Object, String)`

### observe

    public void observe(ValueModel valueModel)

  Observes value changes in the given ValueModel.

  Parameters:
    `valueModel` - the ValueModel to observe
  Throws:
    `NullPointerException` - if the valueModel is null
  See Also:
    `retractInterestFor(ValueModel)`

### retractInterestFor

    public void retractInterestFor(Object bean,
                                   String propertyName)

  Retracts interest for the specified readable bound bean property in the given bean.

  Parameters:
    `bean` - the bean to be observed
    `propertyName` - the name of the readable bound bean property
  Throws:
    `NullPointerException` - if the bean or propertyName is null
    `PropertyNotBindableException` - if this tracker can't remove the PropertyChangeListener from the bean
  See Also:
    `observe(Object, String)`

### retractInterestFor

    public void retractInterestFor(ValueModel valueModel)

  Retracts interest for value changes in the given ValueModel.

  Parameters:
    `valueModel` - the ValueModel to observe
  Throws:
    `NullPointerException` - if the valueModel is null
  See Also:
    `retractInterestFor(ValueModel)`

Overview | Package | Class | Use | Tree | Deprecated | Index | Help
PREV CLASS NEXT CLASS | FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD

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