TreeGridWithCheckBoxFieldsExample Sortation Problem [message #1745325] |
Fri, 07 October 2016 09:07  |
Eclipse User |
|
|
|
Hi,
The sortation that in TreeGridWithCheckBoxFieldsExample is working normally. But When changed data of root elements to null(It is below), sortation is not working correctly.
(createDatum(null, "root", false, null);
......
createDatum(null, "root2", false, null);
....
For this problem, we are add "comparators.add(treeComparator);" before "return new ComparatorChain<T>(comparators).compare(o1, o2);" line in SortableTreeComparator.java. I see it is working correctly. Is it a bug?.Can you check it is ok.
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import org.eclipse.nebula.widgets.nattable.sort.ISortModel;
import org.eclipse.nebula.widgets.nattable.sort.SortDirectionEnum;
import org.eclipse.nebula.widgets.nattable.util.ComparatorChain;
public class SortableTreeComparator<T> implements Comparator<T> {
private final Comparator<T> treeComparator;
private final ISortModel sortModel;
public SortableTreeComparator(Comparator<T> treeComparator, ISortModel sortModel) {
this.treeComparator = treeComparator;
this.sortModel = sortModel;
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public int compare(T o1, T o2) {
int treeComparatorResult = this.treeComparator.compare(o1, o2);
if (treeComparatorResult == 0) {
return 0;
} else {
List<Integer> sortedColumnIndexes = this.sortModel.getSortedColumnIndexes();
if (sortedColumnIndexes != null && sortedColumnIndexes.size() > 0) {
List<Comparator<T>> comparators = new ArrayList<Comparator<T>>();
for (int sortedColumnIndex : sortedColumnIndexes) {
// get comparator for column index... somehow
List<Comparator> columnComparators =
this.sortModel.getComparatorsForColumnIndex(sortedColumnIndex);
if (columnComparators != null) {
SortDirectionEnum sortDirection = this.sortModel.getSortDirection(sortedColumnIndex);
for (Comparator columnComparator : columnComparators) {
switch (sortDirection) {
case ASC:
comparators.add(columnComparator);
break;
case DESC:
comparators.add(Collections.reverseOrder(columnComparator));
break;
}
}
}
}
//*******added line
comparators.add(treeComparato)
return new ComparatorChain<T>(comparators).compare(o1, o2);
} else {
return treeComparatorResult;
}
}
}
}
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.04893 seconds