Search in sources :

Example 1 with ColumnSort

use of org.apache.tapestry5.grid.ColumnSort in project tapestry-5 by apache.

the class CollectionGridDataSource method prepare.

public void prepare(int startIndex, int endIndex, List<SortConstraint> sortConstraints) {
    for (SortConstraint constraint : sortConstraints) {
        final ColumnSort sort = constraint.getColumnSort();
        if (sort == ColumnSort.UNSORTED)
            continue;
        final PropertyConduit conduit = constraint.getPropertyModel().getConduit();
        final Comparator valueComparator = new Comparator<Comparable>() {

            public int compare(Comparable o1, Comparable o2) {
                if (o1 == o2)
                    return 0;
                if (o2 == null)
                    return 1;
                if (o1 == null)
                    return -1;
                return o1.compareTo(o2);
            }
        };
        final Comparator rowComparator = new Comparator() {

            public int compare(Object row1, Object row2) {
                Comparable value1 = (Comparable) conduit.get(row1);
                Comparable value2 = (Comparable) conduit.get(row2);
                return valueComparator.compare(value1, value2);
            }
        };
        final Comparator reverseComparator = new Comparator() {

            public int compare(Object o1, Object o2) {
                int modifier = sort == ColumnSort.ASCENDING ? 1 : -1;
                return modifier * rowComparator.compare(o1, o2);
            }
        };
        // We can freely sort this list because its just a copy.
        Collections.sort(list, reverseComparator);
    }
}
Also used : SortConstraint(org.apache.tapestry5.grid.SortConstraint) ColumnSort(org.apache.tapestry5.grid.ColumnSort) PropertyConduit(org.apache.tapestry5.beanmodel.PropertyConduit) SortConstraint(org.apache.tapestry5.grid.SortConstraint) Comparator(java.util.Comparator)

Example 2 with ColumnSort

use of org.apache.tapestry5.grid.ColumnSort in project tapestry-5 by apache.

the class GridColumns method getSortForColumn.

private ColumnSort getSortForColumn() {
    GridSortModel sortModel = gridModel.getSortModel();
    String columnId = columnModel.getId();
    return sortModel.getColumnSort(columnId);
}
Also used : GridSortModel(org.apache.tapestry5.grid.GridSortModel)

Aggregations

Comparator (java.util.Comparator)1 PropertyConduit (org.apache.tapestry5.beanmodel.PropertyConduit)1 ColumnSort (org.apache.tapestry5.grid.ColumnSort)1 GridSortModel (org.apache.tapestry5.grid.GridSortModel)1 SortConstraint (org.apache.tapestry5.grid.SortConstraint)1