Glazedlists and column based filtering

tablefilterWhile I was working on the BlastViewer, I thought filtering by table column would be a nice feature to get rid of all the cr**y results you are not interested in. Most of the tables we create in Epos are based on GlazedLists as table model and data container. GlazedLists come with pretty nice filtering features out of the box. Filtering for some strings is straight forward, but for this I wanted something slightly more complicated. I want to filter a user specified column using some comparator and a value. Another important thing was that the filter should be easy to use, without any configuration. Here is what we do for the BlastResult table:


...
// create the table
final AdvancedTableFormat hitFormat = new BlastHitFormat();
TableFilter tableFilter = new TableFilter(hitFormat);
FilterList columnFilteredHits = new FilterList(filteredHits, tableFilter);
JTable hitTable = new JTable(new EventTableModel(columnFilteredHits, hitFormat));
...
// create the filter view
hitTableFilterView = new TableFilterView(tableFilter);

Basically we create a new TableFilter. The TableFilter implements a GlazedLists MatcherEditor, so we can apply it on a FilteredList. The FilteredList serves as container for the final table. To create the UI, we use our TableFilterView. The view starts as an empty component but you can call the addFilter() method to create a new filter.

Note that the current TableFilter works only on AdvancedTableFormat. This is due to the fact that the filter needs to known the columns data type, so your AdvancedTableFormat implementation must return valid types.

The TableFilter implementation has no dependencies and can be used with any GlazedLists table, but the UI currently has some dependencies to the Epos Component factory and it used JGoodies Formlayout, though these two can be easily removed with some minor tweaks in the View classes.

If you want to take a look at the implementatin, check the svn.I thought about putting a jar file here, but this thing is still work in progress and you can not use the jar anyways, as it does not contain the dependencies.

If you are interested or you have any questions, just contact me.

One Comment

  1. johannes says:

    that’s awesome!

    i will try to include these neat filters to my upcoming plugin :)

Leave a Reply