Skip to main content

Bound Gooey Beans

Posted by evanx on February 5, 2007 at 6:07 AM EST
Bound Gooey Beans

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.


Code Snippet

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


Related Topics >>