Class Binding<SS,SV,TS,TV>
- java.lang.Object
-
- org.jdesktop.beansbinding.Binding<SS,SV,TS,TV>
-
- Type Parameters:
SS- the type of source objectSV- the type of value that the source property representsTS- the type of target objectTV- the type of value that the target property represents
- Direct Known Subclasses:
AbstractColumnBinding,AutoBinding
public abstract class Binding<SS,SV,TS,TV> extends Object
Bindingis an abstract class that represents the concept of a binding between two properties, typically of two objects, and contains methods for explicitly syncing the values of the two properties.Bindingitself does no automatic syncing between property values. Subclasses will typically keep the values in sync according to some strategy.Some
Bindingsare managed, often by anotherBinding. A managedBindingdoes not allow certain methods to be called by the user. These methods are identified in their documentation. Subclasses should callsetManaged(true)to make themselves managed.Bindingprovides protected versions of the managed methods with the suffix"Unmanaged"for subclasses to use internally without checking whether or not they are managed.Any
PropertyResolutionExceptionsthrown byPropertyobjects used by this binding are allowed to flow through to the caller of theBindingmethods.- Author:
- Shannon Hickey
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classBinding.CSTstatic classBinding.SyncFailureSyncFailurerepresents a failure to sync (saveorrefresh) aBinding.static classBinding.SyncFailureTypeAn enumeration representing the reasons a sync (saveorrefresh) can fail on aBinding.static classBinding.ValueResult<V>Encapsulates the result from callinggetSourceValueForTarget()orgetTargetValueForSource(), which can either be a successful value or a failure.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidaddBindingListener(BindingListener listener)Adds aBindingListenerto be notified of changes to thisBinding.voidaddPropertyChangeListener(PropertyChangeListener listener)Adds aPropertyChangeListenerto be notified when any property of thisBindingchanges.voidaddPropertyChangeListener(String propertyName, PropertyChangeListener listener)Adds aPropertyChangeListenerto be notified when the property identified by thepropertyNameargument changes on thisBinding.voidbind()Binds this binding.protected abstract voidbindImpl()Called bybind()to allow subclasses to initiate binding.protected voidbindUnmanaged()A protected version ofbind()that allows managed subclasses to bind without throwing an exception for being managed.protected voidfirePropertyChange(String propertyName, Object oldValue, Object newValue)Sends aPropertyChangeEventto thePropertyChangeListenersregistered on theBinding.BindingListener[]getBindingListeners()Returns the list ofBindingListenersregistered on thisBinding.Converter<SV,TV>getConverter()Returns theBinding's Converter, which may benull.StringgetName()Returns theBinding'sname, which may benull.PropertyChangeListener[]getPropertyChangeListeners()Returns the list ofPropertyChangeListenersregistered on thisBinding.PropertyChangeListener[]getPropertyChangeListeners(String propertyName)Returns the list ofPropertyChangeListenersregistered on thisBindingfor the given property name.TVgetSourceNullValue()Returns the value to be returned bygetSourceValueForTarget()when the source property returnsnullfor the source object.SSgetSourceObject()Returns theBinding'ssource object, which may benull.Property<SS,SV>getSourceProperty()Returns theBinding'ssource property, which may not benull.TVgetSourceUnreadableValue()If set, returns the value to be returned bygetSourceValueForTarget()when the source property is unreadable for the source object.Binding.ValueResult<TV>getSourceValueForTarget()Fetches the value of the source property for the source object and returns aValueResultrepresenting that value in terms that can be set on the target property for the target object.SVgetTargetNullValue()Returns the value to be returned bygetTargetValueForSource()when the target property returnsnullfor the target object.TSgetTargetObject()Returns theBinding'starget object, which may benull.Property<TS,TV>getTargetProperty()Returns theBinding'starget property, which may not benull.Binding.ValueResult<SV>getTargetValueForSource()Fetches the value of the target property for the target object and returns aValueResultrepresenting that value in terms that can be set on the source property for the source object.Validator<? super SV>getValidator()Returns theBinding's Validator, which may benull.booleanisBound()Returns whether or not thisBindingis bound.booleanisManaged()Returns whether or not thisBindingis managed.booleanisSourceUnreadableValueSet()Returns the value of thesourceUnreadableValueSetproperty, which indicates whether or not thesourceUnreadableValueproperty is set on theBinding.protected voidnotifySynced()Notifies all registeredBindingListenersof a successful sync (refreshorsave), by callingsyncedon each one.protected voidnotifySyncFailed(Binding.SyncFailure failure)Notifies all registeredBindingListenersof a failure to sync (refreshorsave), by callingsyncFailedon each one.protected voidnotifySyncWarning(Binding.SyncFailure failure)Notifies all registeredBindingListenersof a warning to sync (refreshorsave), by callingsyncFailedon each one.protected StringparamString()Returns a string representing the internal state of theBinding.Binding.SyncFailurerefresh()Fetches the value of the source property for the source object and sets it as the value of the target property for the target object.Binding.SyncFailurerefreshAndNotify()The same asrefresh()with the additional behavior of notifying all registeredBindingListenerswithsyncedifrefreshreturnsnullorsyncFailedifrefreshreturns aSyncFailure.protected Binding.SyncFailurerefreshAndNotifyUnmanaged()A protected version ofrefreshAndNotify()that allows managed subclasses to refresh and notify without throwing an exception for being managed.protected Binding.SyncFailurerefreshUnmanaged()A protected version ofrefresh()that allows managed subclasses to refresh without throwing an exception for being managed.voidremoveBindingListener(BindingListener listener)Removes aBindingListenerfrom theBinding.voidremovePropertyChangeListener(PropertyChangeListener listener)Removes aPropertyChangeListenerfrom theBinding.voidremovePropertyChangeListener(String propertyName, PropertyChangeListener listener)Removes aPropertyChangeListenerfrom theBindingfor the given property name.Binding.SyncFailuresave()Fetches the value of the target property for the target object and sets it as the value of the source property for the source object.Binding.SyncFailuresaveAndNotify()The same assave()with the additional behavior of notifying all registeredBindingListenerswithsyncedifsavereturnsnullorsyncFailedifsavereturns aSyncFailure.protected Binding.SyncFailuresaveAndNotifyUnmanaged()A protected version ofsaveAndNotify()that allows managed subclasses to save and notify without throwing an exception for being managed.protected Binding.SyncFailuresaveUnmanaged()A protected version ofsave()that allows managed subclasses to save without throwing an exception for being managed.voidsetConverter(Converter<SV,TV> converter)Sets theConverterfor theBinding, which may benull.protected voidsetManaged(boolean isManaged)Sets whether or not thisBindingis managed.voidsetSourceNullValue(TV sourceNullValue)Sets the value to be returned bygetSourceValueForTarget()when the source property returnsnullfor the source object.voidsetSourceObject(SS sourceObject)Sets theBinding'ssource object, which may benull.protected voidsetSourceObjectUnmanaged(SS sourceObject)A protected version ofsetSourceObject(SS)that allows managed subclasses to set the source object without throwing an exception for being managed.protected voidsetSourceProperty(Property<SS,SV> sourceProperty)Sets theBinding'ssource property.voidsetSourceUnreadableValue(TV sourceUnreadableValue)Sets the value to be returned bygetSourceValueForTarget()when the source property is unreadable for the source object.voidsetTargetNullValue(SV targetNullValue)Sets the value to be returned bygetTargetValueForSource()when the target property returnsnullfor the target object.voidsetTargetObject(TS targetObject)Sets theBinding'starget object, which may benull.protected voidsetTargetObjectUnmanaged(TS targetObject)A protected version ofsetTargetObject(TS)that allows managed subclasses to set the target object without throwing an exception for being managed.protected voidsetTargetProperty(Property<TS,TV> targetProperty)Sets theBinding'starget property.voidsetValidator(Validator<? super SV> validator)Sets theValidatorfor theBinding, which may benull.protected voidsourceChangedImpl(PropertyStateEvent pse)Called to indicate that the source property has fired aPropertyStateEventto indicate that its state has changed for the source object.protected voidtargetChangedImpl(PropertyStateEvent pse)Called to indicate that the target property has fired aPropertyStateEventto indicate that its state has changed for the target object.protected voidthrowIfBound()Throws an IllegalStateException if theBindingis bound.protected voidthrowIfManaged()Throws an UnsupportedOperationException if theBindingis managed.protected voidthrowIfUnbound()Throws an IllegalStateException if theBindingis unbound.StringtoString()Returns a string representation of theBinding.voidunbind()Unbinds this binding.protected abstract voidunbindImpl()Called byunbind()to allow subclasses to uninitiate binding.protected voidunbindUnmanaged()A protected version ofunbind()that allows managed subclasses to unbind without throwing an exception for being managed.voidunsetSourceUnreadableValue()Unsets the value of thesourceUnreadableValueproperty by clearing the value and setting the value of thesourceUnreadableValueSetproperty tofalse.
-
-
-
Constructor Detail
-
Binding
protected Binding(SS sourceObject, Property<SS,SV> sourceProperty, TS targetObject, Property<TS,TV> targetProperty, String name)
Create an instance ofBindingbetween two properties of two objects.- Parameters:
sourceObject- the source objectsourceProperty- a property on the source objecttargetObject- the target objecttargetProperty- a property on the target objectname- a name for theBinding- Throws:
IllegalArgumentException- if the source property or target property isnull
-
-
Method Detail
-
setSourceProperty
protected final void setSourceProperty(Property<SS,SV> sourceProperty)
Sets theBinding'ssource property.Bindingfires a property change notification with property name"sourceProperty"when the value of this property changes.This method may not be called on a bound binding.
- Parameters:
sourceProperty- the source property- Throws:
IllegalArgumentException- if the source property isnullIllegalStateException- if theBindingis bound- See Also:
isBound()
-
setTargetProperty
protected final void setTargetProperty(Property<TS,TV> targetProperty)
Sets theBinding'starget property.Bindingfires a property change notification with property name"targetProperty"when the value of this property changes.This method may not be called on a bound binding.
- Parameters:
targetProperty- the target property- Throws:
IllegalArgumentException- if the target property isnullIllegalStateException- if theBindingis bound- See Also:
isBound()
-
getName
public final String getName()
Returns theBinding'sname, which may benull.- Returns:
- the
Binding'sname, ornull
-
getSourceProperty
public final Property<SS,SV> getSourceProperty()
Returns theBinding'ssource property, which may not benull.- Returns:
- the
Binding'ssource property,non-null - See Also:
setSourceProperty(org.jdesktop.beansbinding.Property<SS, SV>)
-
getTargetProperty
public final Property<TS,TV> getTargetProperty()
Returns theBinding'starget property, which may not benull.- Returns:
- the
Binding'starget property,non-null - See Also:
setTargetProperty(org.jdesktop.beansbinding.Property<TS, TV>)
-
getSourceObject
public final SS getSourceObject()
Returns theBinding'ssource object, which may benull.- Returns:
- the
Binding'ssource object, ornull - See Also:
setSourceObject(SS)
-
getTargetObject
public final TS getTargetObject()
Returns theBinding'starget object, which may benull.- Returns:
- the
Binding'starget object, ornull - See Also:
setTargetObject(TS)
-
setSourceObject
public final void setSourceObject(SS sourceObject)
Sets theBinding'ssource object, which may benull.Bindingfires a property change notification with property name"sourceObject"when the value of this property changes.This method may not be called on a managed or bound binding.
- Parameters:
sourceObject- the source object, ornull- Throws:
UnsupportedOperationException- if theBindingis managedIllegalStateException- if theBindingis bound- See Also:
isManaged(),isBound()
-
setSourceObjectUnmanaged
protected final void setSourceObjectUnmanaged(SS sourceObject)
A protected version ofsetSourceObject(SS)that allows managed subclasses to set the source object without throwing an exception for being managed.- Parameters:
sourceObject- the source object, ornull- Throws:
IllegalStateException- if theBindingis bound- See Also:
isManaged(),isBound()
-
setTargetObject
public final void setTargetObject(TS targetObject)
Sets theBinding'starget object, which may benull.Bindingfires a property change notification with property name"targetObject"when the value of this property changes.This method may not be called on a managed or bound binding.
- Parameters:
targetObject- the target object, ornull- Throws:
UnsupportedOperationException- if theBindingis managedIllegalStateException- if theBindingis bound- See Also:
isManaged(),isBound()
-
setTargetObjectUnmanaged
protected final void setTargetObjectUnmanaged(TS targetObject)
A protected version ofsetTargetObject(TS)that allows managed subclasses to set the target object without throwing an exception for being managed.- Parameters:
targetObject- the target object, ornull- Throws:
IllegalStateException- if theBindingis bound- See Also:
isManaged(),isBound()
-
setValidator
public final void setValidator(Validator<? super SV> validator)
Sets theValidatorfor theBinding, which may benull.Bindingfires a property change notification with property name"validator"when the value of this property changes.This method may not be called on a bound binding.
See the documentation on
getTargetValueForSource()for details on how aBinding's Validatoris used.- Parameters:
validator- theValidator, ornull- Throws:
IllegalStateException- if theBindingis bound- See Also:
isBound()
-
getValidator
public final Validator<? super SV> getValidator()
Returns theBinding's Validator, which may benull.- Returns:
- the
Binding's Validator, ornull - See Also:
setValidator(org.jdesktop.beansbinding.Validator<? super SV>)
-
setConverter
public final void setConverter(Converter<SV,TV> converter)
Sets theConverterfor theBinding, which may benull.Bindingfires a property change notification with property name"converter"when the value of this property changes.This method may not be called on a bound binding.
See the documentation on
getTargetValueForSource()andgetSourceValueForTarget()for details on how aBinding's Converteris used.- Parameters:
converter- theConverter, ornull- Throws:
IllegalStateException- if theBindingis bound- See Also:
isBound()
-
getConverter
public final Converter<SV,TV> getConverter()
Returns theBinding's Converter, which may benull.- Returns:
- the
Binding's Converter, ornull - See Also:
setConverter(org.jdesktop.beansbinding.Converter<SV, TV>)
-
setSourceNullValue
public final void setSourceNullValue(TV sourceNullValue)
Sets the value to be returned bygetSourceValueForTarget()when the source property returnsnullfor the source object. The default for this property isnull.Bindingfires a property change notification with property name"sourceNullValue"when the value of this property changes.This method may not be called on a bound binding.
- Parameters:
sourceNullValue- the value, ornull- Throws:
IllegalStateException- if theBindingis bound
-
getSourceNullValue
public final TV getSourceNullValue()
Returns the value to be returned bygetSourceValueForTarget()when the source property returnsnullfor the source object. The default for this property isnull.- Returns:
- the value that replaces a source value of
null, ornullif there is no replacement - See Also:
setSourceNullValue(TV)
-
setTargetNullValue
public final void setTargetNullValue(SV targetNullValue)
Sets the value to be returned bygetTargetValueForSource()when the target property returnsnullfor the target object. The default for this property isnull.Bindingfires a property change notification with property name"targetNullValue"when the value of this property changes.This method may not be called on a bound binding.
- Parameters:
targetNullValue- the value, ornull- Throws:
IllegalStateException- if theBindingis bound
-
getTargetNullValue
public final SV getTargetNullValue()
Returns the value to be returned bygetTargetValueForSource()when the target property returnsnullfor the target object. The default for this property isnull.- Returns:
- the value that replaces a target value of
null, ornullif there is no replacement - See Also:
setTargetNullValue(SV)
-
setSourceUnreadableValue
public final void setSourceUnreadableValue(TV sourceUnreadableValue)
Sets the value to be returned bygetSourceValueForTarget()when the source property is unreadable for the source object. Calling this method stores the given value and indicates thatgetSourceValueForTargetshould use it, by setting thesourceUnreadableValueSetproperty totrue.By default, the
sourceUnreadableValueproperty is unset, indicated by thesourceUnreadableValueSetproperty beingfalse.Setting this property to
nullacts the same as setting it to any other value. To return the property to the unset state (clearing the value and settingsourceUnreadableValueSetback tofalse) callunsetSourceUnreadableValue().If this property was previously unset, this method fires a property change notification with property name
"sourceUnreadableValueSet". For all invocations, it also fires a property change notification with property name"sourceUnreadableValue", if necessary, to indicate a change in the property value. If previously unset, the event will indicate an old value ofnull.This method may not be called on a bound binding.
- Parameters:
sourceUnreadableValue- the value, which may benull- Throws:
IllegalStateException- if theBindingis bound- See Also:
isSourceUnreadableValueSet(),getSourceUnreadableValue()
-
unsetSourceUnreadableValue
public final void unsetSourceUnreadableValue()
Unsets the value of thesourceUnreadableValueproperty by clearing the value and setting the value of thesourceUnreadableValueSetproperty tofalse.If the property was previously set, fires a property change notification with property name
"sourceUnreadableValueSet", and a property change notification with property name"sourceUnreadableValue". The event for the latter notification will have a new value ofnull.See the documentation for
setSourceUnreadableValue(TV)for more information on thesourceUnreadableValueproperty.This method may not be called on a bound binding.
- Throws:
IllegalStateException- if theBindingis bound- See Also:
isSourceUnreadableValueSet(),getSourceUnreadableValue()
-
isSourceUnreadableValueSet
public final boolean isSourceUnreadableValueSet()
Returns the value of thesourceUnreadableValueSetproperty, which indicates whether or not thesourceUnreadableValueproperty is set on theBinding.See the documentation for
setSourceUnreadableValue(TV)for more information on thesourceUnreadableValueproperty.- Returns:
- whether or not the
sourceUnreadableValueproperty is set on theBinding - See Also:
unsetSourceUnreadableValue(),getSourceUnreadableValue()
-
getSourceUnreadableValue
public final TV getSourceUnreadableValue()
If set, returns the value to be returned bygetSourceValueForTarget()when the source property is unreadable for the source object. ThrowsUnsupportedOperationExceptionif the property is not set, as indicated byisSourceUnreadableValueSet().See the documentation for
setSourceUnreadableValue(TV)for more information on this property.- Returns:
- the value that replaces an unreadable source value, which may
be
null - Throws:
UnsupportedOperationException- if the property is not set, as indicated byisSourceUnreadableValueSet- See Also:
unsetSourceUnreadableValue()
-
addBindingListener
public final void addBindingListener(BindingListener listener)
Adds aBindingListenerto be notified of changes to thisBinding. 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.- Parameters:
listener- the listener to add
-
removeBindingListener
public final void removeBindingListener(BindingListener listener)
Removes aBindingListenerfrom theBinding. Does nothing if the listener isnullor is not one of those registered. 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.- Parameters:
listener- the listener to remove- See Also:
addBindingListener(org.jdesktop.beansbinding.BindingListener)
-
getBindingListeners
public final BindingListener[] getBindingListeners()
Returns the list ofBindingListenersregistered on thisBinding. Order is undefined. Returns an empty array if there are no listeners.- Returns:
- the list of
BindingListenersregistered on thisBinding - See Also:
addBindingListener(org.jdesktop.beansbinding.BindingListener)
-
getSourceValueForTarget
public final Binding.ValueResult<TV> getSourceValueForTarget()
Fetches the value of the source property for the source object and returns aValueResultrepresenting that value in terms that can be set on the target property for the target object.First, if the target property is not writeable for the target object, a
ValueResultis returned representing a failure with failure typeSyncFailureType.TARGET_UNWRITEABLE. Then, if the source property is unreadable for the source object, the value ofisSourceUnreadableValueSet()is checked. Iftruethen aValueResultis returned containing the value of theBinding'sgetSourceUnreadableValue(). Otherwise aValueResultis returned representing a failure with failure typeSyncFailureType.SOURCE_UNREADABLE.Next, the value of the source property is fetched for the source object. If the value is
null, aValueResultis returned containing the value of theBinding'sgetSourceNullValue(). If the value isnon-null, theBinding's Converter, if any, is run to convert the value from source type to the target property'sgetWriteType, by calling itsconvertForwardmethod with the value. If noConverteris registered, a set of default converters is checked to see if one of them can convert the value to the target type. Finally, the value (converted or not) is cast to the target write type.This final value is returned in a
ValueResult.Any
RuntimeExceptionorClassCastExceptionthrown by a converter or the final cast is propogated up to the caller of this method.- Returns:
- a
ValueResultas described above - Throws:
RuntimeException- if thrown by any of the convertersClassCastException- if thrown by a converter or the final cast
-
getTargetValueForSource
public final Binding.ValueResult<SV> getTargetValueForSource()
Fetches the value of the target property for the target object and returns aValueResultrepresenting that value in terms that can be set on the source property for the source object.First, if the source property is not writeable for the source object, a
ValueResultis returned representing a failure with failure typeSyncFailureType.SOURCE_UNWRITEABLE. Then, if the target property is not readable for the target object, aValueResultis returned representing a failure with failure typeSyncFailureType.TARGET_UNREADABLE.Next, the value of the target property is fetched for the target object. If the value is
null, aValueResultis returned containing the value of theBinding'sgetTargetNullValue(). If the value isnon-null, theBinding's Converter, if any, is run to convert the value from target type to the source property'sgetWriteType, by calling itsconvertReversemethod with the value. If noConverteris registered, a set of default converters is checked to see if one of them can convert the value to the source type. Finally, the value (converted or not) is cast to the source write type.If a converter throws a
RuntimeExceptionother thanClassCastException, this method returns aValueResultcontaining the failure, with failure typeSyncFailureType.CONVERSION_FAILURE.As the last step, the
Binding's Validator, if any, is called upon to validate the final value. If theValidatorreturnsnon-nullfrom itsvalidatemethod, aValueResultis returned containing the validation result, with failure typeSyncFailureType.VALIDATION_FAILURE. Otherwise aValueResultis returned containing the final validated value.Any
ClassCastExceptionthrown by a converter or the final cast is propogated up to the caller of this method.- Returns:
- a
ValueResultas described above - Throws:
ClassCastException- if thrown by a converter or the final cast
-
bind
public final void bind()
Binds this binding. CallsbindImpl()to allow subclasses to initiate binding, adds aPropertyStateListenerto the source property for the source object and the target property for the target object to start tracking changes, notifies all registeredBindingListenersthat the binding has become bound, and fires a property change notification to indicate a change to the"bound"property.- Throws:
UnsupportedOperationException- if theBindingis managedIllegalStateException- if theBindingis already bound- See Also:
isBound(),isManaged(),unbind()
-
bindUnmanaged
protected final void bindUnmanaged()
A protected version ofbind()that allows managed subclasses to bind without throwing an exception for being managed.- Throws:
IllegalStateException- if theBindingis bound- See Also:
isManaged(),isBound()
-
bindImpl
protected abstract void bindImpl()
Called bybind()to allow subclasses to initiate binding. Subclasses typically need not installPropertyStateListenerson the source property and target property as they will be notified by calls tosourceChangedImpl(org.jdesktop.beansbinding.PropertyStateEvent)andtargetChangedImpl(org.jdesktop.beansbinding.PropertyStateEvent)when the source and target properties change respectively.- See Also:
unbindImpl()
-
unbind
public final void unbind()
Unbinds this binding. Removes thePropertyStateListenersadded bybind, callsunbindImpl()to allow subclasses to uninitiate binding, notifies all registeredBindingListenersthat the binding has become unbound, and fires a property change notification to indicate a change to the"bound"property.- Throws:
UnsupportedOperationException- if theBindingis managedIllegalStateException- if theBindingis not bound- See Also:
isBound(),isManaged(),bind()
-
unbindUnmanaged
protected final void unbindUnmanaged()
A protected version ofunbind()that allows managed subclasses to unbind without throwing an exception for being managed.- Throws:
IllegalStateException- if theBindingis not bound- See Also:
isManaged(),isBound()
-
unbindImpl
protected abstract void unbindImpl()
Called byunbind()to allow subclasses to uninitiate binding.- See Also:
bindImpl()
-
isBound
public final boolean isBound()
Returns whether or not thisBindingis bound.Bindingfires a property change notification with property name"bound"when the value of this property changes.
-
setManaged
protected final void setManaged(boolean isManaged)
Sets whether or not thisBindingis managed. SomeBindingsare managed, often by anotherBinding. A managedBindingdoes not allow certain methods to be called by the user. These methods are identified in their documentation. Subclasses should callsetManaged(true)to make themselves managed.Bindingprovides protected versions of the managed methods, with the suffix"Unmanaged", for subclasses to use internally without checking whether or not they are managed.
-
isManaged
public final boolean isManaged()
Returns whether or not thisBindingis managed. SomeBindingsare managed, often by anotherBinding. A managedBindingdoes not allow certain methods to be called by the user. These methods are identified in their documentation. Subclasses should callsetManaged(true)to make themselves managed.Bindingprovides protected versions of the managed methods, with the suffix"Unmanaged", for subclasses to use internally without checking whether or not they are managed.- Returns:
- whether or not the
Bindingis managed - See Also:
setManaged(boolean)
-
notifySynced
protected final void notifySynced()
Notifies all registeredBindingListenersof a successful sync (refreshorsave), by callingsyncedon each one.
-
notifySyncFailed
protected final void notifySyncFailed(Binding.SyncFailure failure)
Notifies all registeredBindingListenersof a failure to sync (refreshorsave), by callingsyncFailedon each one.- Parameters:
failure- the reason that the sync failed
-
notifySyncWarning
protected final void notifySyncWarning(Binding.SyncFailure failure)
Notifies all registeredBindingListenersof a warning to sync (refreshorsave), by callingsyncFailedon each one.- Parameters:
failure- the reason that the sync warning
-
refreshAndNotify
public final Binding.SyncFailure refreshAndNotify()
The same asrefresh()with the additional behavior of notifying all registeredBindingListenerswithsyncedifrefreshreturnsnullorsyncFailedifrefreshreturns aSyncFailure.- Returns:
- the return value from the call to
refresh - Throws:
UnsupportedOperationException- if theBindingis managedRuntimeException- as specified byrefresh()ClassCastException- as specified byrefresh()- See Also:
isManaged()
-
refreshAndNotifyUnmanaged
protected final Binding.SyncFailure refreshAndNotifyUnmanaged()
A protected version ofrefreshAndNotify()that allows managed subclasses to refresh and notify without throwing an exception for being managed.- Returns:
- the return value from the call to
refresh - Throws:
RuntimeException- as specified byrefresh()ClassCastException- as specified byrefresh()- See Also:
isManaged()
-
saveAndNotify
public final Binding.SyncFailure saveAndNotify()
The same assave()with the additional behavior of notifying all registeredBindingListenerswithsyncedifsavereturnsnullorsyncFailedifsavereturns aSyncFailure.- Returns:
- the return value from the call to
save - Throws:
UnsupportedOperationException- if theBindingis managedClassCastException- as specified byrefresh()- See Also:
isManaged()
-
saveAndNotifyUnmanaged
protected final Binding.SyncFailure saveAndNotifyUnmanaged()
A protected version ofsaveAndNotify()that allows managed subclasses to save and notify without throwing an exception for being managed.- Returns:
- the return value from the call to
save - Throws:
ClassCastException- as specified bysave()- See Also:
isManaged()
-
refresh
public final Binding.SyncFailure refresh()
Fetches the value of the source property for the source object and sets it as the value of the target property for the target object. First callsgetSourceValueForTarget(). If the return value from that method represents a failure, this method returns the failure. Otherwise, it callssetValueon the target property for the target object with the value obtained from the source.- Returns:
- the reason for failure if the binding could not be refreshed,
or
nullfor success - Throws:
UnsupportedOperationException- if theBindingis managedRuntimeException- if thrown bygetSourceValueForTarget()ClassCastException- if thrown bygetSourceValueForTarget()- See Also:
isManaged(),save()
-
refreshUnmanaged
protected final Binding.SyncFailure refreshUnmanaged()
A protected version ofrefresh()that allows managed subclasses to refresh without throwing an exception for being managed.- Returns:
- the reason for failure if the binding could not be refreshed,
or
nullfor success - Throws:
RuntimeException- if thrown bygetSourceValueForTarget()ClassCastException- if thrown bygetSourceValueForTarget()- See Also:
isManaged()
-
save
public final Binding.SyncFailure save()
Fetches the value of the target property for the target object and sets it as the value of the source property for the source object. First callsgetTargetValueForSource(). If the return value from that method represents a failure, this method returns the failure. Otherwise, it callssetValueon the source property for the source object with the value obtained from the target.- Returns:
- the reason for failure if the binding could not be saved,
or
nullfor success - Throws:
UnsupportedOperationException- if theBindingis managedClassCastException- if thrown bygetTargetValueForSource()- See Also:
isManaged(),refresh()
-
saveUnmanaged
protected final Binding.SyncFailure saveUnmanaged()
A protected version ofsave()that allows managed subclasses to save without throwing an exception for being managed.- Returns:
- the reason for failure if the binding could not be saved,
or
nullfor success - Throws:
ClassCastException- if thrown bygetTargetValueForSource()- See Also:
isManaged()
-
throwIfManaged
protected final void throwIfManaged()
Throws an UnsupportedOperationException if theBindingis managed. Useful for calling at the beginning of method implementations that shouldn't be called on managedBindings- Throws:
UnsupportedOperationException- if theBindingis managed- See Also:
isManaged()
-
throwIfBound
protected final void throwIfBound()
Throws an IllegalStateException if theBindingis bound. Useful for calling at the beginning of method implementations that shouldn't be called when theBindingis bound.- Throws:
IllegalStateException- if theBindingis bound.
-
throwIfUnbound
protected final void throwIfUnbound()
Throws an IllegalStateException if theBindingis unbound. Useful for calling at the beginning of method implementations that should only be called when theBindingis bound.- Throws:
IllegalStateException- if theBindingis unbound.
-
toString
public String toString()
Returns a string representation of theBinding. This method is intended to be used for debugging purposes only, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not benull.
-
paramString
protected String paramString()
Returns a string representing the internal state of theBinding. This method is intended to be used for debugging purposes only, and the content and format of the returned string may vary between implementations. The returned string may be empty but may not benull.- Returns:
- a string representing the state of the
Binding.
-
sourceChangedImpl
protected void sourceChangedImpl(PropertyStateEvent pse)
Called to indicate that the source property has fired aPropertyStateEventto indicate that its state has changed for the source object. Called after theBindinghas notified any property change listeners andBindingListenersthat the source value has been edited (only if thePropertyStateEventrepresents a value change). This method is useful for subclasses to detect source changes and perform syncing as appropriate.
-
targetChangedImpl
protected void targetChangedImpl(PropertyStateEvent pse)
Called to indicate that the target property has fired aPropertyStateEventto indicate that its state has changed for the target object. Called after theBindinghas notified any property change listeners andBindingListenersthat the target value has been edited (only if thePropertyStateEventrepresents a value change). This method is useful for subclasses to detect target changes and perform syncing as appropriate.
-
addPropertyChangeListener
public final void addPropertyChangeListener(PropertyChangeListener listener)
Adds aPropertyChangeListenerto be notified when any property of thisBindingchanges. 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.Bindingfires property change notification for the following properties:sourcePropertytargetPropertysourceObjecttargetObjectvalidatorconvertersourceNullValuetargetNullValuesourceUnreadableValueSetsourceUnreadableValuebound
For other types of
Bindingnotifications register aBindingListener.- Parameters:
listener- the listener to add- See Also:
addBindingListener(org.jdesktop.beansbinding.BindingListener)
-
addPropertyChangeListener
public final void addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
Adds aPropertyChangeListenerto be notified when the property identified by thepropertyNameargument changes on thisBinding. Does nothing if the property name or 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.Bindingfires property change notification for the following properties:sourcePropertytargetPropertysourceObjecttargetObjectvalidatorconvertersourceNullValuetargetNullValuesourceUnreadableValueSetsourceUnreadableValuebound
For other types of
Bindingnotifications register aBindingListener.- Parameters:
propertyName- the name of the property to listen for changes onlistener- the listener to add
-
removePropertyChangeListener
public final void removePropertyChangeListener(PropertyChangeListener listener)
Removes aPropertyChangeListenerfrom theBinding. Does nothing if the listener isnullor is not one of those registered. 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.- Parameters:
listener- the listener to remove- See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener)
-
removePropertyChangeListener
public final void removePropertyChangeListener(String propertyName, PropertyChangeListener listener)
Removes aPropertyChangeListenerfrom theBindingfor the given property name. Does nothing if the property name or listener isnullor the listener is not one of those registered. 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.- Parameters:
propertyName- the name of the property to remove the listener forlistener- the listener to remove- See Also:
addPropertyChangeListener(String, PropertyChangeListener)
-
getPropertyChangeListeners
public final PropertyChangeListener[] getPropertyChangeListeners()
Returns the list ofPropertyChangeListenersregistered on thisBinding. Order is undefined. Returns an empty array if there are no listeners.- Returns:
- the list of
PropertyChangeListenersregistered on thisBinding - See Also:
addPropertyChangeListener(java.beans.PropertyChangeListener)
-
getPropertyChangeListeners
public final PropertyChangeListener[] getPropertyChangeListeners(String propertyName)
Returns the list ofPropertyChangeListenersregistered on thisBindingfor the given property name. Order is undefined. Returns an empty array if there are no listeners registered for the property name.- Parameters:
propertyName- the property name to retrieve the listeners for- Returns:
- the list of
PropertyChangeListenersregistered on thisBindingfor the given property name - See Also:
addPropertyChangeListener(String, PropertyChangeListener)
-
firePropertyChange
protected final void firePropertyChange(String propertyName, Object oldValue, Object newValue)
Sends aPropertyChangeEventto thePropertyChangeListenersregistered on theBinding.- Parameters:
propertyName- the name of the property that's changedoldValue- the old value of the propertynewValue- the new value of the property
-
-