|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectAbstractBean
com.jgoodies.binding.beans.Model
com.jgoodies.binding.util.ChangeTracker
public final class ChangeTracker
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 Specification. 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.
ValueModel
Field Summary | |
---|---|
static java.lang.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(java.lang.Object bean,
java.lang.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(java.lang.Object bean,
java.lang.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 |
---|
createPropertyChangeSupport, firePropertyChange |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.jgoodies.binding.beans.Observable |
---|
addPropertyChangeListener, removePropertyChangeListener |
Field Detail |
---|
public static final java.lang.String PROPERTYNAME_CHANGED
isChanged()
,
Constant Field ValuesConstructor Detail |
---|
public ChangeTracker()
false
.
Method Detail |
---|
public boolean isChanged()
public void reset()
false
.
public void observe(java.lang.Object bean, java.lang.String propertyName)
bean
- the bean to be observedpropertyName
- the name of the readable bound bean property
java.lang.NullPointerException
- if the bean or propertyName is null
PropertyNotBindableException
- if this tracker can't add
the PropertyChangeListener from the beanretractInterestFor(Object, String)
public void observe(ValueModel valueModel)
valueModel
- the ValueModel to observe
java.lang.NullPointerException
- if the valueModel is nullretractInterestFor(ValueModel)
public void retractInterestFor(java.lang.Object bean, java.lang.String propertyName)
bean
- the bean to be observedpropertyName
- the name of the readable bound bean property
java.lang.NullPointerException
- if the bean or propertyName is null
PropertyNotBindableException
- if this tracker can't remove
the PropertyChangeListener from the beanobserve(Object, String)
public void retractInterestFor(ValueModel valueModel)
valueModel
- the ValueModel to observe
java.lang.NullPointerException
- if the valueModel is nullretractInterestFor(ValueModel)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |