TreeTable: sorting leaf nodes via TableComparatorChooser

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

TreeTable: sorting leaf nodes via TableComparatorChooser

Holger
Hey James and Jesse,

I was thinking about the following case:

You've setup a TreeTable with a default sorting
for each depth via appropriate comparators
returned by the TreeList.Format.
Now suppose you'd want to change the sorting
of the current leaf nodes based on "selected"
column(s), e.g. you want to click on a column header
and *resort the current leaf nodes only* according to
the values of that column.

Is that achievable right now?
If yes, how?

Thanks,
Holger





__________________________________________________________________________
Verschicken Sie SMS direkt vom Postfach aus - in alle deutschen und viele
ausländische Netze zum gleichen Preis!
https://produkte.web.de/webde_sms/sms




---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: TreeTable: sorting leaf nodes via TableComparatorChooser

Jesse Wilson
On Sun, May 10, 2009 at 4:26 AM, Holger Brands <[hidden email]> wrote:
You've setup a TreeTable with a default sorting
for each depth via appropriate comparators
returned by the TreeList.Format.
Now suppose you'd want to change the sorting
of the current leaf nodes based on "selected"
column(s), e.g. you want to click on a column header
and *resort the current leaf nodes only* according to
the values of that column.


Yeah, you'll need to create a TreeFormat whose Comparator knows about the TableFormat and the selected columns.

Whenever you need to sort 'leaves only' it's necessary to differentiate between leaves and non-leaves. Therefore that sorting mode isn't really appropriate for "variable depth" trees like file browsers.
Reply | Threaded
Open this post in threaded view
|

Re: TreeTable: sorting leaf nodes via TableComparatorChooser

Holger
In reply to this post by Holger
>
> Yeah, you'll need to create a TreeFormat whose Comparator knows about
> the TableFormat and the selected columns.
>
> Whenever you need to sort 'leaves only' it's necessary to differentiate
>  between leaves and non-leaves. Therefore that sorting mode isn't
> really appropriate for "variable depth" trees like file browsers.

Yes, but in the case I had in mind we have a fixed depth.

Hmm, I was thinking about a TableComparatorChooser implementation that
instead of setting the built comparator on a SortedList just fires a
property change with the new comparator.
This way, we could build and get at the required comparator for sorting
the leave nodes.

But how to tell TreeList/TreeFormat about the changed comparator, e.g. how to
trigger the resort of the nodes at depth x?

BTW,  shouldn't
public Comparator<? extends E> getComparator(int depth);
be
public Comparator<? super E> getComparator(int depth);
in interface TreeList.Format<E>?

Thanks,
Holger

______________________________________________________
GRATIS für alle WEB.DE-Nutzer: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://movieflat.web.de


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|

Re: TreeTable: sorting leaf nodes via TableComparatorChooser

Brian Merrill
Holger Brands wrote:
Yeah, you'll need to create a TreeFormat whose Comparator knows about 
the TableFormat and the selected columns.

Whenever you need to sort 'leaves only' it's necessary to differentiate
 between leaves and non-leaves. Therefore that sorting mode isn't 
really appropriate for "variable depth" trees like file browsers.
    

Yes, but in the case I had in mind we have a fixed depth.

Hmm, I was thinking about a TableComparatorChooser implementation that
instead of setting the built comparator on a SortedList just fires a
property change with the new comparator.
This way, we could build and get at the required comparator for sorting
the leave nodes.

But how to tell TreeList/TreeFormat about the changed comparator, e.g. how to
trigger the resort of the nodes at depth x?

BTW,  shouldn't
public Comparator<? extends E> getComparator(int depth);
be
public Comparator<? super E> getComparator(int depth);
in interface TreeList.Format<E>?

Thanks,
Holger
  
I've tried to accomplish this in the past without much luck.  Ideally, I would like to sort the top level nodes based on the selected column sorting and then treat each subsequent level in the tree as a sort down to the leaf level.

I wrote and have attached a sample application to try do this for a two level tree.  In TradeTreeFormat, the getComparator returns a sortComparator object that stores the state information of the TableComparatorChooser for the given column.  Right now it only sorts on the top level parent, but I think the solution extends to any tree depth whether parent, leaf, or something in between.

@Override
    public Comparator<? extends Trade> getComparator(int depth)
    {
        if (tcc != null)
        {
            final List <SortCriterion> sortCriteria = new ArrayList<SortCriterion>();
            final List <Integer> sortedColumns = tcc.getSortingColumns();
           
            for (Integer column : sortedColumns)
            {
                sortCriteria.add(new SortCriterion(column, tcc.isColumnReverse(column)));
            }
            sortComparator.setCriteria(sortCriteria);
            return sortComparator;
        }
        return new SymbolComparator();
    }

Unfortunately, I keep running into a problem where at times, when a new item is inserted into the flat list, TreeList will fail to insert it into the correct, sorted parent which results in "duplicate" parent nodes being visible until the column is manually re-sorted. 

If you run the attached treecolsort.jar file (i.e., java -jar treecolsort.jar) the data is added in such a way as to produce the duplicate parent node.  Clicking on the "Quantity" column will clean up the duplicate.

I haven't been able to figure out a solution yet, but would love some new ideas on the topic.


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

treecolsort.jar (1M) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: TreeTable: sorting leaf nodes via TableComparatorChooser

kikonen
In reply to this post by Holger