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:
dev-unsubscribe@...
For additional commands, e-mail:
dev-help@...