Sortin’ Tables
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.

November 10th, 2005 at 10:24 pm
Have you tried using the open source package GlazedLists? I’ve used it before and I believe it provides you with those arrows and a framework to sort tables by column.
November 10th, 2005 at 11:37 pm
I ran their demo… no arrows. And the sorting is a little odd (i.e. at least one of the columns doesn’t seem to sort right).
November 19th, 2005 at 9:18 pm
Hey guys, I’m one of the Glazed Lists hackers and I saw your blog! We’ve since fixed the demo’s missing sort icons problem, it was a build.xml mistake. Check us out, especially the screencasts!
August 2nd, 2007 at 3:25 am
adult galleries mature women…
Eclipse hints, tips, and random musings » Blog Archive » Sortin…