I came across SWT Snippet192 today which shows some cool new features that are being added to Eclipse 3.2.
I have a table in my application that I want to sort. Sorting is pretty easy to make work in table, but there’s one thing missing: the sort indicator. That is, there is no way in Eclipse 3.1 to indicate which column the table is sorted on or in what direction. As I mentioned in the first sentence above, this has been fixed in Eclipse 3.2.
However, I’m still doing work with Eclipse 3.1, so I need a solution. I’ve built a TableSorter class that takes care of all things to do with sorting tables. You just have to register each “sortable” column and provide a java.util.Comparable that describes what it means for that column to be sorted in ascending order (for my purposes, it was easy enough to derive the descending sorter). The TableSorter takes care of keeping track of the current sort column and the direction of the sort.
To provide a visual cue to the user, I’m simply changing the icon on the column header to indicate direction. It feels a little clunky (as it causes the column header text to move around), but I’m considering it a temporary workaround that I’ll fix when I move the application to 3.2.