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);
}
}
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);
}
Aggregations