« Return to Thread: I don't understand how SortedList and TableComparatorChooser work together

Re: I don't understand how SortedList and TableComparatorChooser work together

by James Lemieux :: Rate this Message:

Reply to Author | View in Thread

Nick,

"The TableComparatorChooser isn't swapping out the Comparator on my
SortedList, it is using the Comparator of whatever my TableFormat returns
for that column."

This is a false statement. The Comparator of whatever your TableFormat returns for a column is set as the Comparator of the SortedList. It may be combined with other Comparators (for multi column sorting) and it may be wrapped to reverse its natural sort direction, but ultimately your column Comparators are used as the Comparator on your SortedList. If you're still unconvinced, look at AbstractTableComparatorChooser.rebuildComparator():

    protected void rebuildComparator() {
        final Comparator<E> rebuiltComparator = sortingState.buildComparator();

        // select the new comparator
        sortedList.getReadWriteLock().writeLock().lock();
        try {
            sortedListComparator = rebuiltComparator;
            sortedList.setComparator(rebuiltComparator);
        } finally {
            sortedList.getReadWriteLock().writeLock().unlock();
        }
    }

If you still have questions at this point, post them back and I'll answer them.

James

On Fri, May 1, 2009 at 12:32 AM, Boomah <nickdarcy@...> wrote:

Thanks for the answers but I'm still unsure (this is my fault for not
explaining properly). Let me try again:

The TableComparatorChooser isn't swapping out the Comparator on my
SortedList, it is using the Comparator of whatever my TableFormat returns
for that column. This is a field in an object contained in my SortedList. So
as soon as I click on a column to sort, the SortedList is no longer used,
and could just as easily be replaced by an EventList.

I agree with point c) mentioned below. After I had clicked on a column, I
might want to revert back to the order that the SortedList says the table
should display data in. I can't figure out how to do this though. It doesn't
seem I can deselected a column sorting. Is this possible?

So my main point is this: Why does the method TableComparatorChooser.install
take a SortedList when it seems to me that taking an EventList would be just
as legitimate.

Thanks for any clarification,

Nick.




James Lemieux wrote:
>
> Kevin is correct.
>
> SortedList is a transformation used to create an ordered *view* of any
> EventList.
>
> TableComparatorChooser is simply a big fancy way to interpret mouse clicks
> on a column header as a change in the Comparator of a SortedList.
>
> If the original question posed in this Thread is essentially "why don't
> you
> just sort data in place, why do you have sorted "views" at all?" that's a
> really long winded explanation. Some quick but obvious reasons include:
>
> a) what if I want 2 different sorted views of the same data?
> b) what if the original order has special meaning to my app, and shouldn't
> be disturbed?
> c) how can I return to the original order after it has been disturbed?
>
> etc.
>
> James
>
> On Thu, Apr 30, 2009 at 11:00 AM, Kevin Day <kevin@...> wrote:
>
>>  I'm pretty sure that TableComparitorChooser is actually swapping out the
>> comparator on your sorted list.
>>
>> - K
>>
>>
>>  ----------------------- *Original Message* -----------------------
>>
>> *From:* Boomah <nickdarcy@...> <nickdarcy@...>
>> *To:* users@...
>> *Cc:*
>> *Date:* Thu, 30 Apr 2009 10:41:56 -0700 (PDT)
>> *Subject: I don't understand how SortedList and TableComparatorChooser
>> work together*
>>
>>
>> Hi people. I don't understand how SortedList and TableComparatorChooser
>> work
>> together.
>>
>> I have objects that get added to a SortedList that represent (via my
>> TableFormat) a row in a table. The SortedList uses this object to sort,
>> and
>> if I just use a standard JTable, whenever an object is added to my list,
>> it
>> gets added to my table in the appropriate position. Everything works
>> exactly
>> as I would expect.
>>
>> Now I install a TableComparatorChooser on my JTable. If I start my
>> application, I see items being added to the table in the correct position
>> given my SortedList as before. However, if I now click on one of the
>> columns, it sorts not using my SortedList but by using the objects in the
>> column I clicked on. In my case they are all strings and so get sorted
>> using
>> the standard string comparator.
>>
>> I don't understand why the TableComparatorChooser requires a SortedList
>> if
>> once the user clicks on a column, it gets sorted by th e objects it
>> contains.
>> Why isn't it possible to use an EventList?
>>
>> It feels like I'm missing something obvious, but I think that SortedList
>> and
>> TableComparatorChooser completely work against each other and should be
>> separated.
>>
>> Have I completely missed the point?
>>
>> Thanks, Nick.
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/I-don%27t-understand-how-SortedList-and-TableComparatorChooser-work-together-tp23321078p23321078.html
>> Sent from the GlazedLists - User mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@...
>> For additional commands, e-ma il: users-help@...
>>
>>
>> --------------------------------------------------------------------- To
>> unsubscribe, e-mail: users-unsubscribe@... For
>> additional commands, e-mail: users-help@...
>
>

--
View this message in context: http://www.nabble.com/I-don%27t-understand-how-SortedList-and-TableComparatorChooser-work-together-tp23321078p23329393.html
Sent from the GlazedLists - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@...
For additional commands, e-mail: users-help@...


 « Return to Thread: I don't understand how SortedList and TableComparatorChooser work together