Class PropertyHelper<S,V>
java.lang.Object
org.jdesktop.beansbinding.Property<S,V>
org.jdesktop.beansbinding.PropertyHelper<S,V>
- Type Parameters:
S- the type of source object that thisPropertyoperates onV- the type of value that thisPropertyrepresents
- Direct Known Subclasses:
BeanProperty, ELProperty
An abstract subclass of
Property that helps with the management of
PropertyStateListeners by implementing the methods for adding, removing,
and getting listeners. PropertyHelper can be constructed
to manage listeners for multiple source objects, or to ignore the source
object argument when dealing with listeners and associate them directly with
the PropertyHelper instance itself. This makes PropertyHelper
useful as a base for both property types described in the documentation for
Property.
PropertyHelper also provides, by way of the protected methods
listeningStarted(S) and listeningStopped(S) a hook for subclasses
to know when it's time to start tracking changes to a particular source object.
-
Constructor Summary
ConstructorsConstructorDescriptionCreate aPropertyHelperthat manages listeners for multiple source objects.PropertyHelper(boolean ignoresSource) Create aPropertyHelper, specifying whether it manages listeners for multiple source objects, or ignores the source object argument when dealing with listeners -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddPropertyStateListener(S source, PropertyStateListener listener) Adds aPropertyStateListenerto be notified when the state of thePropertychanges with respect to the given source.protected final voidNotify listeners that the state of this property has changed, as characterized by the givenPropertyStateEvent.final PropertyStateListener[]getPropertyStateListeners(S source) Returns an arry containing the listeners registered for the given source.abstract VReturns the value of thisPropertyfor the given source.getWriteType(S source) Returns the type of object that is suitable for setting as the value of thisPropertyby calls tosetValue.final booleanisListening(S source) Returns whether or not there are anyPropertyStateListenersinstalled for the given source object.abstract booleanisReadable(S source) Returns whether or not thePropertyis readable for the given source.abstract booleanisWriteable(S source) Returns whether or not thePropertyis writeable for the given source.protected voidlisteningStarted(S source) Called when thisPropertyHelperchanges from having no listeners installed for the given source object to having listeners installed for the given source object.protected voidlisteningStopped(S source) Called when thisPropertyHelperchanges from having listeners installed for the given source object to having no listeners installed for the given source object.final voidremovePropertyStateListener(S source, PropertyStateListener listener) Removes aPropertyStateListenerfor the given source.abstract voidSets the value of thisPropertyfor the given source.
-
Constructor Details
-
PropertyHelper
public PropertyHelper()Create aPropertyHelperthat manages listeners for multiple source objects. -
PropertyHelper
public PropertyHelper(boolean ignoresSource) Create aPropertyHelper, specifying whether it manages listeners for multiple source objects, or ignores the source object argument when dealing with listeners- Parameters:
ignoresSource- whether or not the source argument is ignored when dealing with listeners
-
-
Method Details
-
getWriteType
Returns the type of object that is suitable for setting as the value of thisPropertyby calls tosetValue.- Specified by:
getWriteTypein classProperty<S,V> - Parameters:
source- the source object on which to operate- Returns:
- the type of object suitable for setting as the value
- Throws:
UnsupportedOperationException- if thePropertyis not writeable for the given source- See Also:
-
getValue
Returns the value of thisPropertyfor the given source.- Specified by:
getValuein classProperty<S,V> - Parameters:
source- the source object on which to operate- Returns:
- the value of this
Propertyfor the given source - Throws:
UnsupportedOperationException- if thePropertyis not readable for the given source- See Also:
-
setValue
Sets the value of thisPropertyfor the given source.- Specified by:
setValuein classProperty<S,V> - Parameters:
source- the source object on which to operatevalue- the new value for theProperty- Throws:
UnsupportedOperationException- if thePropertyis not writeable for the given source- See Also:
-
isReadable
Returns whether or not thePropertyis readable for the given source.- Specified by:
isReadablein classProperty<S,V> - Parameters:
source- the source object on which to operate- Returns:
- whether or not the
Propertyis readable for the given source. - See Also:
-
isWriteable
Returns whether or not thePropertyis writeable for the given source.- Specified by:
isWriteablein classProperty<S,V> - Parameters:
source- the source object on which to operate- Returns:
- whether or not the
Propertyis writeable for the given source. - See Also:
-
listeningStarted
Called when thisPropertyHelperchanges from having no listeners installed for the given source object to having listeners installed for the given source object. This is the ideal time for subclasses to install any listeners needed to track change on the source object.- See Also:
-
listeningStopped
Called when thisPropertyHelperchanges from having listeners installed for the given source object to having no listeners installed for the given source object. This is the ideal time for subclasses to remove any listeners that they've installed to track changes on the source object.- See Also:
-
addPropertyStateListener
Adds aPropertyStateListenerto be notified when the state of thePropertychanges with respect to the given source. Does nothing if the listener isnull. If a listener is added more than once, notifications are sent to that listener once for every time that it has been added. The ordering of listener notification is unspecified.- Specified by:
addPropertyStateListenerin classProperty<S,V> - Parameters:
source- the source object on which to operatelistener- the listener to be notified
-
removePropertyStateListener
Removes aPropertyStateListenerfor the given source. Does nothing if the listener isnullor is not one of those registered for this source object. If the listener being removed was registered more than once, only one occurrence of the listener is removed from the list of listeners. The ordering of listener notification is unspecified.- Specified by:
removePropertyStateListenerin classProperty<S,V> - Parameters:
source- the source object on which to operatelistener- the listener to be removed- See Also:
-
getPropertyStateListeners
Returns an arry containing the listeners registered for the given source. Order is undefined. Returns an empty array if there are no listeners.- Specified by:
getPropertyStateListenersin classProperty<S,V> - Parameters:
source- the source object on which to operate- Returns:
- the set of listeners registered for the given source
- See Also:
-
firePropertyStateChange
Notify listeners that the state of this property has changed, as characterized by the givenPropertyStateEvent. If thisPropertyHelperis managing listeners for multiple sources, only the listeners associated with the object returned by thePropertyStateEvent's getSourceObject()method are notified.- Parameters:
pse- thePropertyStateEventcharacterizing the state change
-
isListening
Returns whether or not there are anyPropertyStateListenersinstalled for the given source object.- Parameters:
source- the source object of interest- Returns:
- whether or not there are any
PropertyStateListenersinstalled for the given source object
-