Sorting TreeList

View: New views
6 Messages — Rating Filter:   Alert me  

Sorting TreeList

by dingwa :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

How is it possible to sort TreeLists?  When I add rows to the tree list they seem be be inserted into an arbitrary position.  I am wanting to control the position of any new rows that are inserted into the TreeList (i.e. at the top of the table)

Would I have either have to insert the row into the TreeList and then sort the list so the newly inserted row is at the top? Or is it even possible to insert the top level expandable row at a specified position?


Cheers!

Re: Sorting TreeList

by Ken Orr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

If you add a SortedList upstream of your TreeList, you'll get sorted output.

SortedList -> TreeList

dingwa wrote:
Hi,

How is it possible to sort TreeLists?  When I add rows to the tree list they seem be be inserted into an arbitrary position.  I am wanting to control the position of any new rows that are inserted into the TreeList (i.e. at the top of the table)

Would I have either have to insert the row into the TreeList and then sort the list so the newly inserted row is at the top? Or is it even possible to insert the top level expandable row at a specified position?


Cheers!

Re: Sorting TreeList

by dingwa :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Thanks for the quick reply!

With regards to the sort comparator used for the sorted list, would I use the same comparator *TreeFormat (in your example SimpleBeanTreeFormat)?

Also, if the chain of events is:
BasicEventList -> SortedList -> ObservableElementList -> TreeList

At which level would I apply the GlazedListsSwing.swingThreadProxyList() and the GlazedLists.threadSafeList()?  Should I be applying these at the lowest level (i.e. BasicEventList), or at the highest level (i.e TreeList)?

And one more point with regards to chaining Lists together, is there a standard way that one list must be chained to the next? Or is it a free-for-all in the order that you chain lists together?


Cheers!



If you add a SortedList upstream of your TreeList, you'll get sorted output.

SortedList -> TreeList

dingwa wrote:
Hi,

How is it possible to sort TreeLists?  When I add rows to the tree list they seem be be inserted into an arbitrary position.  I am wanting to control the position of any new rows that are inserted into the TreeList (i.e. at the top of the table)

Would I have either have to insert the row into the TreeList and then sort the list so the newly inserted row is at the top? Or is it even possible to insert the top level expandable row at a specified position?


Cheers!


Re: Sorting TreeList

by Ken Orr :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The comparator that you supply to your TreeFormat is used to group items together. That comparator should return "equal" if two items belong to the same parent.

Here's how you might setup your list pipeline without a sorted list (I'll reference what the output would be if you used my example here):

BasicEventList -> ThreadSafeList -> SwingThreadProxyList -> TreeList

+ Apple.txt
    - skin
    - stem
    - flesh
+ Frogs.txt
    - eyes
    - legs
    - sounds
    - feet

Note that the grouping nodes (Apple.txt and Frogs.txt) are in sorted order, but the "name" child items are not.

If we want to sort the elements within the TreeList, we can insert a SortedList that sorts the items ahead of time, and then feed that to the TreeList:

BasicEventList -> ThreadSafeList -> SortedList -> SwingThreadProxyList -> TreeList

Results in:

- flesh, Apple.txt
- skin, Apple.txt
- stem, Apple.txt
- eyes, Frogs.txt
- feet, Frogs.txt
- legs, Frogs.txt
- sounds, Frogs.txt

which is then turned into the following by TreeList:

+ Apple.txt
    - flesh
    - skin
    - stem
+ Frogs.txt
    - eyes
    - feet
    - legs
    - sounds

So the comparator to your SortedList would use sort on the name property whereas the TreeList was comparing against Files (in the strange example I provided).

As far as how to chain you lists, I try to do it in a computationally aware way. That is, filter before you sort, as it makes the sort operation simpler, though the GL guys may tell you this isn't necessary.

Good luck,
-Ken


Thanks for the quick reply!

With regards to the sort comparator used for the sorted list, would I use the same comparator *TreeFormat (in your example SimpleBeanTreeFormat)?

Also, if the chain of events is:
BasicEventList -> SortedList -> ObservableElementList -> TreeList

At which level would I apply the GlazedListsSwing.swingThreadProxyList() and the GlazedLists.threadSafeList()?  Should I be applying these at the lowest level (i.e. BasicEventList), or at the highest level (i.e TreeList)?

And one more point with regards to chaining Lists together, is there a standard way that one list must be chained to the next? Or is it a free-for-all in the order that you chain lists together?


Cheers!


Ken Orr wrote:
If you add a SortedList upstream of your TreeList, you'll get sorted output.

SortedList -> TreeList

dingwa wrote:
Hi,

How is it possible to sort TreeLists?  When I add rows to the tree list they seem be be inserted into an arbitrary position.  I am wanting to control the position of any new rows that are inserted into the TreeList (i.e. at the top of the table)

Would I have either have to insert the row into the TreeList and then sort the list so the newly inserted row is at the top? Or is it even possible to insert the top level expandable row at a specified position?


Cheers!

re[2]: Sorting TreeList

by Kevin Day-7 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Some parts of this message have been removed. Learn more about Nabble's security policy.
If your ObservableElementList is looking for changes that might change the sort order, then you need to have it come before the SortedList in the pipeline.
 
OEL fires change notifications downstream in the list.  If your OEL is after the SortedList, then no events fired by the OEL will ever hit the Sorted List.
 
 
In terms of where to put threadsafelist, etc... it really depends on the behavior you are trying for.  If you are inserting/editing elements in the BasicEventList directly, then you'd wrap that.  If you are inserting/editing elements in the TreeList, then you'd wrap that.
 
I'm also not entierly sure that you need to manually include the swingThreadProxyList in the chain - the table model does this automatically (I'm pretty sure on that).  If you *did* have to do it manually, you'd want to pick a point in the list where it makes sense for behavior to always be occuring on the EDT (this is generally right at the point where you tie the list chain to a tablemodel or listmodel - but there are certainly situations where different placement may be appropriate).
 
- K
 
----------------------- Original Message -----------------------
  
From: dingwa scott.sue@...
Cc: 
Date: Mon, 13 Oct 2008 05:24:49 -0700 (PDT)
Subject: Re: Sorting TreeList
  

Thanks for the quick reply!

With regards to the sort comparator used for the sorted list, would I use
the same comparator *TreeFormat (in your example SimpleBeanTreeFormat)?

Also, if the chain of events is:
BasicEventList -> SortedList -> ObservableElementList -> TreeList

At which level would I apply the GlazedListsSwing.swingThreadProxyList() and
the GlazedLists.threadSafeList()?  Should I be applying these at the lowest
level (i.e. BasicEventList), or at the highest level (i.e TreeList)?

And one more point with regards to chaining Lists together, is there a
standard way that one list must be chained to the next? Or is it a
free-for-all in the order that you chain lists together?


Cheers!



Ken Orr wrote:

>
> If you add a SortedList upstream of your TreeList, you'll get sorted
> output.
>
> SortedList -> TreeList
>
>
> dingwa wrot e:
>>
>> Hi,
>>
>> How is it possible to sort TreeLists?  When I add rows to the tree list
>> they seem be be inserted into an arbitrary position.  I am wanting to
>> control the position of any new rows that are inserted into the TreeList
>> (i.e. at the top of the table)
>>
>> Would I have either have to insert the row into the TreeList and then
>> sort the list so the newly inserted row is at the top? Or is it even
>> possible to insert the top level expandable row at a specified position?
>>
>>
>> Cheers!
>>
>
>

--
View this message in context: http://www.nabble.com/Sorting-TreeList-tp19919951p19953913.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@...


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

Re: Sorting TreeList

by kikonen :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Sorting TreeList appears to be slighly tricky,

After some trial and error:

http://kari.dy.fi/src/sample/foldertree.zip
(for compile needs
http://kari.dy.fi/tigtag/dist/kui.jar
http://kari.dy.fi/tigtag/dist/log4j-1.2.14.jar
)

Problem areas:
- Special hack is needed to pass Comparator from
  TableComparatorChooser to comparator of TreeFormat
- Refreshing model after comparator change is "unclean"
  * i.e. seemingly "clear/reinsert all" was needed to
    reset internally cached model state in TreeList
    ~ ExpansionModel must cache expansion states
      of nodes correctly
- TreeList updates block EDT thread
  * Doesn't scale to 10s of thousands of elements well

--
KI


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