SortDelegate example?

18 views
Skip to first unread message

Val

unread,
Aug 13, 2009, 12:56:12 AM8/13/09
to Mac Widgets for Java
Dear everyone,
I am wondering if anyone would be willing to provide a working
SortDelegate example.
As it stands now, it is really unclear to me how this method should
work.
Thanks in advance!

Ken Orr

unread,
Aug 13, 2009, 5:08:52 AM8/13/09
to mac-widget...@googlegroups.com
Hi Val,

The SortDelegate should simply trigger your sorting code. For example if you were using Glazed Lists, then your SortDelegate would install a new Comparator with the sort criteria on your SortedList.

In that case the delegate might look something like this:

TableUtils.SortDelegate sortDelegate = new TableUtils.SortDelegate() {
       
public void sort(int columnModelIndex, TableUtils.SortDirection sortDirection) {
           
mySortedList.setComparator(...);
       
}
   
};

See this example as well:
-Ken

Thasso Griebel

unread,
Aug 13, 2009, 6:06:28 AM8/13/09
to mac-widget...@googlegroups.com
Hi,

for GalzedLists and the ITunes Table, I find something like this quiet usefull:

TableUtils.makeSortable(table, new TableUtils.SortDelegate() {
    public void sort(int i, TableUtils.SortDirection sortDirection) {
        if(sortDirection == TableUtils.SortDirection.DESCENDING){
            sorted.setComparator(new InverseComparator(new TableColumnComparator(format, i)));                  
        }else{
            sorted.setComparator(new TableColumnComparator(format, i));
        }       
    }
});

TableColumnComparator is ca.odell.glazedlists.impl.sort.TableColumnComparator. This way I can use the ITunes table the same way I use any other table based on an EventTableModel, and custom comparators can be installed on the TableFormat.

-thasso

2009/8/13 Ken Orr <kenne...@gmail.com>



--
--
Dipl. Inf. Thasso Griebel-------------------Lehrstuhl fuer Bioinformatik
Office 3426--http://bio.informatik.uni-jena.de--Institut fuer Informatik
Phone +49 (0)3641 9-46454-----------Friedrich-Schiller-Universitaet Jena
Fax +49 (0)3641 9-46452----------Ernst-Abbe-Platz 2, 07743 Jena, Germany
Reply all
Reply to author
Forward
0 new messages