Package org.jdesktop.beansbinding
Provides support for defining properties and creating bindings between sets of two properties.
Properties
A property is defined by creating an instance of a concrete implementation
of the Property class. This package
provides two concrete Property implementations of interest:
BeanProperty allows Java Bean properties
to be addressed by providing their path as a String.
ELProperty allows Java Bean properties
to be addressed similarly and then be used in various ways in an EL expression.
A simple BeanProperty that refers to a "firstName" Java Bean property,
might look like:
BeanProperty firstNameP = BeanProperty.create("firstName");
An ELProperty to combine the "firstName" and "lastName"
properties of a Java Bean into a full name, might look like:
ELProperty fullNameP = ELProperty.create("${firstName} ${lastName}");
These property objects can then be used to operate on a Java Bean having the properties of interest. For example:
// prints the first name on the person object
System.out.println(firstNameP.getValue(person));
// prints the full name of the person object
System.out.println(fullNameP.getValue(person));
// sets the first name of the person object to "Duke"
firstNameP.setValue(person, "Duke");
// listen for changes to the person's full name
fullNameP.addPropertyStateListener(person, listener);
Both of these property implementations are designed to work with bean properties that follow the Java Beans specification. Sometimes, however, a property of interest on a bean outside of your control may not be exposed in the correct way, and you want to adapt it for use in binding. Other times you may want to extend the set of properties that a bean exposes, simply for use in binding. These cases are provided for by the org.jdesktop.beansbinding.ext package.
Bindings
A binding is created between two Property instances, and the objects
on which the Property objects should operate, by creating an instance
of a concrete implementation of the Binding class. Once the binding is
realized, by a call to the bind method, a Binding starts
tracking changes to the properties on both ends, and a typical Binding
implementation will sync the properties with each other based on on some defined
strategy.
Binding called
AutoBinding which syncs the properties based
on a configurable update strategy. AutoBindings are created by
calling one of the static createAutoBinding methods in the
Bindings class. For example:
BeanProperty firstNameP = BeanProperty.create("firstName");
BeanProperty textP = BeanProperty.create("text");
Binding binding = Bindings.createAutoBinding(READ_WRITE, person, firstNameP, jTextField, textP);
binding.bind();
Before a value from a source property is set on a target property, it passes
through an optional Converter to convert
it between the source type and target type. Before a value passed from a
target property back to a source property, it passes first through the
optional Converter and then through an optional
Validator, which can reject invalid values.
-
ClassDescriptionAn abstract subclass of
BindingListenerthat simplifies writingBindingListenersby allowing you to extend this class and re-implement only the methods you care about.AutoBinding<SS,SV, TS, TV> An implementation ofBindingthat automatically syncs the source and target by refreshing and saving according to one of three update strategies.An enumeration representing the possible update strategies of anAutoBinding.BeanProperty<S,V> An implementation ofPropertythat uses a simple dot-separated path syntax to address Java Beans properties of source objects.Binding<SS,SV, TS, TV> 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.SyncFailurerepresents a failure to sync (saveorrefresh) aBinding.An enumeration representing the reasons a sync (saveorrefresh) can fail on aBinding.Encapsulates the result from callingBinding.getSourceValueForTarget()orBinding.getTargetValueForSource(), which can either be a successful value or a failure.BindingGroupallows you to create a group ofBindingsand operate on and/or track state changes to theBindingsas a group.BindingListenersare registered onBindingsorBindingGroupsto listen for changes to the state ofBindingsA factory class for creating instances of the concreteBindingimplementations provided by this package.Converter<S,T> Converteris responsible for converting a value from one type to another.ELProperty<S,V> An implementation ofPropertythat allows Java Beans properties of source objects to be addressed using a simple dot-separated path syntax within an EL expression.An immutable, read-only,Propertyimplementation whosegetValuemethod returns the source object that it is given.Property<S,V> Propertydefines a uniform way to access the value of a property.PropertyHelper<S,V> An abstract subclass ofPropertythat helps with the management ofPropertyStateListenersby implementing the methods for adding, removing, and getting listeners.PropertyResolutionExceptionscan be thrown at various points in the life cycle of aProperty.An event characterizing a change in aProperty'sstate for a particular source object.PropertyStateListenersare registerd onPropertyinstances, to be notified when the state of the property changes.Validator<T>Validatoris responsible for validating the value from the target of aBinding.