The Source for Java Technology Collaboration
User: Password:



Evan Summers

Evan Summers's Blog

Gooey Table Model

Posted by evanx on October 02, 2007 at 06:33 AM | Comments (0)

We introduce a generic table model supporting a list of backing beans, with simplistic "beans binding" facilitated by java.beans.PropertyDescriptor.


Demo

The following demo exercises our table models (and forms).

divvy.png

Launch   (PirateWarez, 150k/500k, unsandboxed, Java6)

Incidently, notice how the selection works, eg. click on the search icon to select the person, and enter a blank product ID to select some booty! ;) Later in this series, we'll look at a popup finder for entities.


Code Snippet

We implement a table model in our application as follows.

public class ProductMovementDetailTableModel extends GTableModel<ProductMovementDetail> {
    ProductMovementDetailInfo info = new ProductMovementDetailInfo();
    
    GTableColumn productId = createColumn(info.productId);
    GTableColumn label = createColumn(info.label);
    GTableColumn productUnit = createColumn(info.productUnit);
    GTableColumn unitCost = createColumn(info.unitCost);
    GTableColumn quantity = createColumn(info.quantity);
    GTableColumn amount = createColumn(info.amount);
    
    public ProductMovementDetailTableModel() {
        super(ProductMovementDetail.class);
        ... // setEditable() on column objects
    }    
}

where we create column objects to contain metadata eg. column headings, types, et cetera.

Each row of the table has a backing bean, eg. ProductMovementDetail in the above example. As presented in the Gooey Beans Info prequel, we define metadata for the bean's properties in a "bean info" object, eg. ProductMovementDetailInfo. The column objects wrap "property info" objects which are created in the bean info class.

A controller is implemented to handle events from the table component, eg. row selection and cell editing. The beans and column objects are used in these event handlers to reference rows and columns.

Disclaimer: This design predates JSR 295 (Beans Binding), which is the future, and so will be presented in future, in this series' 2nd Edition ;)

Incidently, the days of my publishing an article every month in this Foundation series seem to have come to an end, because i've been travelling. Right now i'm in Germany, and from next week i'll be cycling across southern France and northern Spain (woohoo!) without a computer, so um, zero productivity...



Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment





Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds