| java.lang.Object com.jgoodies.binding.beans.PropertyConnector
PropertyConnector | final public class PropertyConnector (Code) | | Keeps two Java Bean properties in synch. This connector supports bound and
unbound, read-only and read-write properties. Write-only properties are
not supported; connecting two read-only properties won't work;
connecting two unbound properties doesn't make sense.
If one of the bean properties fires a property change, this connector
will set the other to the same value. If a bean property is read-only,
the PropertyConnector will not listen to the other bean's property and so
won't update the read-only property. And if a bean does not provide support
for bound properties, it won't be observed.
The properties must be single value bean properties as described by the
Java
Bean Secification.
Constraints: the properties must be type compatible,
i. e. values returned by one reader must be accepted by the other's writer,
and vice versa.
Examples:
// Connects a ValueModel and a JFormattedTextField
JFormattedTextField textField = new JFormattedTextField();
textField.setEditable(editable);
PropertyConnector connector =
new PropertyConnector(valueModel, "value", textField, "value");
connector.updateProperty2();
// Connects the boolean property "selectable" with a component enablement
JComboBox comboBox = new JComboBox();
...
new PropertyConnector(mainModel, "selectable", comboBox, "enabled");
author: Karsten Lentzsch version: $Revision: 1.16 $ See Also: PropertyChangeEvent See Also: PropertyChangeListener See Also: PropertyDescriptor |
Method Summary | |
public static PropertyConnector | connect(Object bean1, String property1Name, Object bean2, String property2Name) Synchronizes the two bound bean properties as specified
by the given pairs of bean and associated property name. | public static void | connectAndUpdate(ValueModel valueModel, Object bean2, String property2Name) Synchronizes the ValueModel with the specified bound bean property,
and updates the bean immediately.
If the ValueModel changes, it updates Bean2#property2Name
and vice versa. | public Object | getBean1() Returns the Java Bean that holds the first property. | public Object | getBean2() Returns the Java Bean that holds the first property. | public String | getProperty1Name() Returns the name of the first Java Bean property. | public String | getProperty2Name() Returns the name of the second Java Bean property. | public void | release() Removes the PropertyChangeHandler from the observed bean,
if the bean is not null and if property changes are not observed. | public void | updateProperty1() Reads the value of the second bean property and sets it as new
value of the first bean property. | public void | updateProperty2() Reads the value of the first bean property and sets it as new
value of the second bean property. |
connect | public static PropertyConnector connect(Object bean1, String property1Name, Object bean2, String property2Name)(Code) | | Synchronizes the two bound bean properties as specified
by the given pairs of bean and associated property name.
If Bean1#property1Name changes it updates
Bean2#property2Name and vice versa.
If a bean does not provide support for bound properties,
changes will not be observed.
If a bean property is read-only, this connector won't listen to
the other bean's property and so won't update the read-only property.
Returns the PropertyConnector that is required if one or the other
property shall be updated.
Parameters: bean1 - the bean that owns the first property Parameters: property1Name - the name of the first property Parameters: bean2 - the bean that owns the second property Parameters: property2Name - the name of the second property the PropertyConnector used to synchronize the properties,required if property1 or property2 shall be updated throws: NullPointerException - if a bean or property name is null throws: IllegalArgumentException - if the beans are identical andthe property name are equal |
connectAndUpdate | public static void connectAndUpdate(ValueModel valueModel, Object bean2, String property2Name)(Code) | | Synchronizes the ValueModel with the specified bound bean property,
and updates the bean immediately.
If the ValueModel changes, it updates Bean2#property2Name
and vice versa. If the bean doesn't provide support for bound properties,
changes will not be observed.
If the bean property is read-only, this connector will not listen
to the ValueModel and so won't update the read-only property.
Parameters: valueModel - the ValueModel that provides a bound value Parameters: bean2 - the bean that owns the second property Parameters: property2Name - the name of the second property throws: NullPointerException - if the ValueModel, bean or property name is null throws: IllegalArgumentException - if the bean is the ValueModeland the property name is "value" since: 2.0 |
getBean1 | public Object getBean1()(Code) | | Returns the Java Bean that holds the first property.
the Bean that holds the first property |
getBean2 | public Object getBean2()(Code) | | Returns the Java Bean that holds the first property.
the Bean that holds the first property |
getProperty1Name | public String getProperty1Name()(Code) | | Returns the name of the first Java Bean property.
the name of the first property |
getProperty2Name | public String getProperty2Name()(Code) | | Returns the name of the second Java Bean property.
the name of the second property |
release | public void release()(Code) | | Removes the PropertyChangeHandler from the observed bean,
if the bean is not null and if property changes are not observed.
This connector must not be used after calling #release .
To avoid memory leaks it is recommended to invoke this method,
if the connected beans live much longer than this connector.
As an alternative you may use event listener lists in the connected
beans that are implemented using WeakReference .
See Also: java.lang.ref.WeakReference |
|
|