The invisible model
March 27th, 2008This is the second post in a series of posts that offer a preview of the new feature in the upcoming UltraLightClient ‘08 release. The first post was about forms. This post describes how to bind a collection of business objects to a table widget.
In 99% of the time, the data displayed in a table widget represents a collection of business objects, where each table row selects one business object out of the collection, and each table column represents one property of the selected business object. Until now, you are forced to implement a table model to define the data displayed in a table widget. And as these table models all represent a collection of business objects, you have to write the same boilerplate code over and over again. Moreover, some visual aspects of the table cannot be defined by the table model, e.g. the preferred column size.
But this will change with UltraLightClient ‘08! In UltraLightClient ‘08 this important use case will become an ultra easy implementation task. Instead of implementing a table model, you just bind business object properties to table columns. No need to implement table models anymore!
TableBinding tableBinding = TableBinding
.createTableBindingFromBeanList(persons, table, Person.class, false);
tableBinding.addColumnBinding("firstName")
.setColumnHeaderValue("First Name")
.setColumnPreferredWidth(150);
tableBinding.addColumnBinding("lastName")
.setColumnHeaderValue("Last Name")
.setColumnPreferredWidth(150);
tableBinding.addColumnBinding("vip")
.setColumnHeaderValue("VIP")
.setColumnPreferredWidth(50)
.setColumnType(Boolean.class);
The previous code snippet binds three properties of the person business object to table columns. With UltraLightClient ‘08 it is ultra easy to define the visual representation of the table columns. Just set corresponding properties on the column binding! In the previous snippet all three column bindings define the header value and the preferred width of the columns. In addition, the third binding defines the column type. This changes the look of the cells in the third table column to check boxes, as shown in the following screen shot:

In the screenshot you can see a sort indicator placed in the header of third column. Until now, implementing a sortable table required a decorating table model, an action listener on the table header, and a sorting algorithm. With UltraLightClient ‘08 the decorating table model has vanished as well, and implementing a sortable table is just a one liner!
table.setRowSorter(new TableRowSorter(table.getModel()));
Summary: With the new table binding offered in UltraLightClient ‘08, implementing tables is an ultra easy task. No need to write stupid boilerplate code again and again. You can concentrate on the essential parts. Plus UltraLightClient ‘08 enables sortable tables with just one line of code.
We plan to publish an UltraLightClient ‘08 milestone release in early April. Stay tuned!

Posted by Daniel




