Griffon and table data binding

Recently i have been working on small application in Griffon framewrok. This is MVC framework for desktop applications writed in Groovy  - new cool kid in Java World. My first impression was - WOW. Swing builder is my favorite feature immediately after mvc group.

But nothing lasts forever and after few days of work I entered into world of pain. There is no documentation, best practices, or any thing like that. All java developers that were coddled by IDE's like Eclipse will suffer lots of pains because there is no rational support for Groovy. Of course you can hack Netbeans Grails (cousin of Griffon for web applications) plug-in, but after one hour of fight I stayed with my project in Eclipse.

But the hardest thing for me was to menage how to bind data to table. I thinked that there MUST be way to do that by bind statement, but after several hours of searching, I find that there is no such way.

So,  how to do it? Use Glazed list.

There is simple example how to use glazed list. This is View from MVC group where we have helper method that create table model. Next we use this method for table creation. In this example model.tableData is instance of ca.odell.glazedlists.BasicEventList.

  1. def createTableModel() {
  2. def columnNames = ['col 1', 'col 2', 'col 3', 'col 4', 'col 5']
  3. def variableNames = ['var1', 'var2', 'var3', 'var4', 'var5']
  4. new EventTableModel(model.tableData,
  5. [getColumnCount: { columnNames.size() },
  6. getColumnName: { index -> columnNames[index] },
  7. getColumnValue: {object, index -> object."${variableNames[index]}"}] as TableFormat)
  8. }
  9.  
  10. panel {
  11. borderLayout()
  12. scrollPane {
  13. table(id:'myTable',
  14. selectionMode: ListSelectionModel.SINGLE_SELECTION,
  15. autoCreateRowSorter:true,
  16. model: createTableModel()) {
  17. current.tableHeader.reorderingAllowed = false
  18. }
  19. }
  20. }

If you still looking for more info, check this example for more details.

Powered by WordPress with GimpStyle Theme design by Horacio Bella.
Entries and comments feeds. Valid XHTML and CSS.