Sorting a tree table [message #1728355] |
Sun, 03 April 2016 08:10  |
Eclipse User |
|
|
|
Hi,
I have a tree table with a max depth of 1 (0 and 1).
The data structure is like that:
IPeak
\_ IIon
\_ IIon
\_ ...
IPeak extends IIon.
I use the following TreeFormat:
public class PeakTreeFormat implements TreeList.Format<IIon> {
@Override
public boolean allowsChildren(final IIon element) {
final boolean result = element instanceof IPeak;
return result;
}
@Override
public Comparator getComparator(final int depth) {
// path 0 is peak, path 1 ion
return (o1, o2) -> {
final IPeak i1 = (IPeak) o1;
final IPeak i2 = (IPeak) o2;
// TODO: I need to know on which column we are sorting
return 0;
};
// return null;
}
@Override
public void getPath(final List path, final IIon element) {
if (element instanceof IPeak) {
} else {
if (element.getPeak() != null) {
path.add(element.getPeak());
}
}
path.add(element);
}
}
Sorting is working in principle, but the problem is, that it is working only on path level 1, path level 0 is ignored.
All elements on path level 1 are sorted correctly, but they don't stay "together" with all the other elements that have the same parent.
for each element on path level 1, the corresponding element on level 0 is added, leading to duplicates and broken "element groups".
In the end, I "just" want to achive an ordering first on elements on level 0, then level 1.
How can I do that?
[Updated on: Sun, 03 April 2016 10:12] by Moderator
|
|
|
|
Re: Sorting a tree table [message #1728420 is a reply to message #1728393] |
Mon, 04 April 2016 05:50  |
Eclipse User |
|
|
|
Thanks for the hint!
I understand the problem is the custom comparator.
In your example, you use the GlazedLists.beanPropertyComparator , nevertheless I need to implement a custom one, since the sorting depends also on the type of element.
How can I tell the comparator on which column sorting is happening?
@Override
public Comparator getComparator(final int depth) {
// path 0 is peak, path 1 ion
return (o1, o2) -> {
final IIon i1 = (IIon) o1;
final IIon i2 = (IIon) o2;
if(i1 instanceof IPeak && i2 instanceof IPeak){
// sort on different property
}
// TODO: I need to know on which column we are sorting
return 0;
};
// return null;
}
EDIT:
Its working now, but I don't really understand why.
I use
GlazedLists.beanPropertyComparator(IIon.class, "mz");
as described in the TreeGridExample.
I pass only one valid String property, nevertheless sorting seems to work for all columns.
[Updated on: Mon, 04 April 2016 06:20] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.03910 seconds