Skip to main content



      Home
Home » Eclipse Projects » NatTable » TreeGridWithCheckBoxFieldsExample Sortation Problem(TreeGridWithCheckBoxFieldsExample Sortation Problem when data of root set null)
TreeGridWithCheckBoxFieldsExample Sortation Problem [message #1745325] Fri, 07 October 2016 09:07 Go to next message
Eclipse UserFriend
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;
            }
        }
    }

}




Re: TreeGridWithCheckBoxFieldsExample Sortation Problem [message #1745490 is a reply to message #1745325] Tue, 11 October 2016 09:43 Go to previous messageGo to next message
Eclipse UserFriend
From testing this it looks ok. Feel free to create a ticket and provide a patch via Gerrit.
Re: TreeGridWithCheckBoxFieldsExample Sortation Problem [message #1746127 is a reply to message #1745490] Sat, 22 October 2016 15:42 Go to previous message
Eclipse UserFriend
https://bugs.eclipse.org/bugs/show_bug.cgi?id=506394
Previous Topic:[Help] Freeze Rows/Colums freezes all indexes down to 0
Next Topic:Traversal and MultiLineTextCellEditor
Goto Forum:
  


Current Time: Fri Jul 25 09:13:27 EDT 2025

Powered by FUDForum. Page generated in 0.04893 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top