A helper class for observing changes in bound bean properties
where the target bean changes.
Provides two access styles to the target bean that holds the observed
property: you can specify a bean directly,
or you can use a
bean channel to access the bean indirectly.
In the latter case you specify a
ValueModel
that holds the bean that in turn holds the observed properties.
If the target bean is
null
, it won't report any changes.
It is recommended to remove all listener by invoking
#removeAll
if the observed bean lives much longer than this change support instance.
As an alternative you may use event listener lists that are based
on
WeakReference
s.
Constraints: All target bean classes must support
bound properties, i. e. must provide the following pair of methods
for registration of multicast property change event listeners:
public void addPropertyChangeListener(PropertyChangeListener x);
public void removePropertyChangeListener(PropertyChangeListener x);
and the following methods for listening on named properties:
public void addPropertyChangeListener(String, PropertyChangeListener x);
public void removePropertyChangeListener(String, PropertyChangeListener x);
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the list of bean listeners.
The listener is registered for all bound properties of the target bean.
If listener is
null
, no exception is thrown and no action is performed.
listener
- the PropertyChangeListener to be added
addPropertyChangeListener
public void addPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Adds a PropertyChangeListener to the list of bean listeners for a
specific property. The specified property may be user-defined.
Note that if the bean is inheriting a bound property, then no event
will be fired in response to a change in the inherited property.
If listener is
null
, no exception is thrown and no action is performed.
propertyName
- one of the property names listed abovelistener
- the PropertyChangeListener to be added
getBean
public Object getBean()
Returns the Java Bean that holds the observed properties.
- the Bean that holds the observed properties
getPropertyChangeListeners
public PropertyChangeListener[] getPropertyChangeListeners()
Returns an array of all the property change listeners
registered on this component.
- all of this component's
PropertyChangeListener
s
or an empty array if no property change
listeners are currently registered
getPropertyChangeListeners
public PropertyChangeListener[] getPropertyChangeListeners(String propertyName)
Returns an array of all the listeners which have been associated
with the named property.
propertyName
- the name of the property to lookup listeners
- all of the
PropertyChangeListeners
associated with
the named property or an empty array if no listeners have
been added
removeAll
public void removeAll()
Removes all registered PropertyChangeListeners from
the current target bean - if any.
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from the list of bean listeners.
This method should be used to remove PropertyChangeListeners that
were registered for all bound properties of the target bean.
If listener is
null
, no exception is thrown and no action is performed.
listener
- the PropertyChangeListener to be removed
removePropertyChangeListener
public void removePropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list for a specific
property. This method should be used to remove PropertyChangeListeners
that were registered for a specific bound property.
If listener is
null
, no exception is thrown and no action is performed.
propertyName
- a valid property namelistener
- the PropertyChangeListener to be removed
setBean
public void setBean(Object newBean)
Sets a new Java Bean as holder of the observed properties.
Removes all registered listeners from the old bean and
adds them to the new bean.
newBean
- the new holder of the observed properties