private void updateSortOrder(SortableHeader<T, ?> header) { int index = sortOrderList.indexOf(header); if (index == 0) { if (header.getSortDirection() != SortDirection.ASCENDING) { header.setSortDirection(SortDirection.ASCENDING); } else { header.setSortDirection(SortDirection.DESCENDING); } } else { // Remove it if it's already sorted on this header later if (index > 0) { sortOrderList.remove(index); } header.setSortDirection(SortDirection.ASCENDING); // Bring this header to front // Deque.addFirst(sortableHeader) sortOrderList.add(0, header); // Update sortIndexes int sortIndex = 0; for (SortableHeader<T, ?> sortableHeader : sortOrderList) { sortableHeader.setSortIndex(sortIndex); sortIndex++; } } }
public int compare(T leftRow, T rightRow) { for (SortableHeader<T, ?> sortableHeader : sortOrderList) { Comparable leftColumnValue = sortableHeader.getColumn().getValue(leftRow); Comparable rightColumnValue = sortableHeader.getColumn().getValue(rightRow); int comparison = (leftColumnValue == rightColumnValue) ? 0 : (leftColumnValue == null) ? -1 : (rightColumnValue == null) ? 1 : leftColumnValue.compareTo(rightColumnValue); if (comparison != 0) { switch (sortableHeader.getSortDirection()) { case ASCENDING: break; case DESCENDING: comparison = -comparison; break; default: throw new IllegalStateException("Sorting can only be enabled for ASCENDING or" + " DESCENDING, not sortDirection (" + sortableHeader.getSortDirection() + ") ."); } return comparison; } } return leftRow.compareTo(rightRow); } });
public SortableHeader(SortableHeaderGroup sortableHeaderGroup, String text, Column<T, C> column) { super(new ClickableTextCell()); this.sortableHeaderGroup = sortableHeaderGroup; this.text = text; this.column = column; setUpdater(new ValueUpdater<String>() { public void update(String s) { SortableHeader.this.sortableHeaderGroup.headerClicked(SortableHeader.this); } }); }
public int compare(T leftRow, T rightRow) { for (SortableHeader<T, ?> sortableHeader : sortOrderList) { Comparable leftColumnValue = sortableHeader.getColumn().getValue(leftRow); Comparable rightColumnValue = sortableHeader.getColumn().getValue(rightRow); int comparison = (leftColumnValue == rightColumnValue) ? 0 : (leftColumnValue == null) ? -1 : (rightColumnValue == null) ? 1 : leftColumnValue.compareTo(rightColumnValue); if (comparison != 0) { switch (sortableHeader.getSortDirection()) { case ASCENDING: break; case DESCENDING: comparison = -comparison; break; default: throw new IllegalStateException("Sorting can only be enabled for ASCENDING or" + " DESCENDING, not sortDirection (" + sortableHeader.getSortDirection() + ") ."); } return comparison; } } return leftRow.compareTo(rightRow); } });
public SortableHeader(SortableHeaderGroup sortableHeaderGroup, String text, Column<T, C> column) { super(new ClickableTextCell()); this.sortableHeaderGroup = sortableHeaderGroup; this.text = text; this.column = column; setUpdater(new ValueUpdater<String>() { public void update(String s) { SortableHeader.this.sortableHeaderGroup.headerClicked(SortableHeader.this); } }); }
private void updateSortOrder(SortableHeader<T, ?> header) { int index = sortOrderList.indexOf(header); if (index == 0) { if (header.getSortDirection() != SortDirection.ASCENDING) { header.setSortDirection(SortDirection.ASCENDING); } else { header.setSortDirection(SortDirection.DESCENDING); } } else { // Remove it if it's already sorted on this header later if (index > 0) { sortOrderList.remove(index); } header.setSortDirection(SortDirection.ASCENDING); // Bring this header to front // Deque.addFirst(sortableHeader) sortOrderList.add(0, header); // Update sortIndexes int sortIndex = 0; for (SortableHeader<T, ?> sortableHeader : sortOrderList) { sortableHeader.setSortIndex(sortIndex); sortIndex++; } } }