All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.jdesktop.beansbinding.package.html Maven / Gradle / Ivy

The newest version!





    
        
    
    
        

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 {@link org.jdesktop.beansbinding.Property} class. This package provides two concrete {@code Property} implementations of interest: {@link org.jdesktop.beansbinding.BeanProperty} allows Java Bean properties to be addressed by providing their path as a String. {@link org.jdesktop.beansbinding.ELProperty} allows Java Bean properties to be addressed similarly and then be used in various ways in an EL expression. A simple {@code BeanProperty} that refers to a "firstName" Java Bean property, might look like:


    BeanProperty firstNameP = BeanProperty.create("firstName");
        

An {@code 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 {@code Property} instances, and the objects on which the {@code Property} objects should operate, by creating an instance of a concrete implementation of the {@code Binding} class. Once the binding is realized, by a call to the {@code bind} method, a {@code Binding} starts tracking changes to the properties on both ends, and a typical {@code Binding} implementation will sync the properties with each other based on on some defined strategy.

This package provides one concrete subclass of {@code Binding} called {@link org.jdesktop.beansbinding.AutoBinding} which syncs the properties based on a configurable update strategy. {@code AutoBindings} are created by calling one of the static {@code createAutoBinding} methods in the {@link org.jdesktop.beansbinding.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 {@link org.jdesktop.beansbinding.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 {@code Converter} and then through an optional {@link org.jdesktop.beansbinding.Validator}, which can reject invalid values.





© 2015 - 2025 Weber Informatics LLC | Privacy Policy