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.

This entry was posted in Uncategorized. Bookmark the permalink.

4 Responses to Sortin’ Tables

  1. Sarit says:

    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.

  2. Wayne says:

    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).

  3. swankjesse says:

    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!

  4. Pingback: adult galleries mature women

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s