Skip to main content

Bound Gooey Beans

Posted by evanx on February 5, 2007 at 3:07 AM PST

In the Gooey Beans Info prequel, we explicitly declare properties. Now we allow a bean info instance to be bound to a specific bean, in order to support bound properties ie. firing PropertyChangeEvent's.

Bound Gooey Beans: A part of "Gooey Beans, a trilogy in 42 parts"

In our bean, we instantiate a bound bean info class with PropertyChangeSupport as follows.

public class BakedBean {
    public final BakedBeanInfo info = new BakedBeanInfo(this);
   
    private BigInteger barcode;
    private String label;
    private Integer bakingTemparature;
    private BigDecimal medianLength;
    ...  
    public BakedBean() {
    }
    ...
    public void setBarcode(BigInteger barcode) {
        this.barcode = barcode;
        info.barcode.firePropertyChanged(barcode);
    }
}

where we use property "literals" from our bean info to firePropertyChanged().

We can add PropertyChangeListener's as follows.

public class BakedBeanDemo implements PropertyChangeListener, Runnable {
    BakedBean bean = new BakedBean();
    ...
    public BakedBeanDemo() {
        ...
        bean.info.getPropertyChangeSupport().addPropertyChangeListener(this);
    }
    ...   
}

bakedBeansDemo

Resources

https://code.google.com/p/vellum/ - where i will collate these articles and their code.

Related Topics >>