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); } });
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 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 ); } } ); }
@Override protected void addAncillaryColumns(ColumnPicker<InboxPageRow> columnPicker, SortableHeaderGroup<InboxPageRow> sortableHeaderGroup) { // Include general "Inbox" columns super.addAncillaryColumns(columnPicker, sortableHeaderGroup); Column<InboxPageRow, String> fromColumn = new TextColumn<InboxPageRow>() { public String getValue(InboxPageRow row) { return ((InboxIncomingPageRow) row).getFrom(); } }; columnPicker.addColumn(fromColumn, new SortableHeader<InboxPageRow, String>( sortableHeaderGroup, "From", fromColumn), true); }
new SortableHeader<InboxPageRow, ComparableImageResource>( sortableHeaderGroup, "Format", new SortableHeader<InboxPageRow, String>( sortableHeaderGroup, "Name", new SortableHeader<InboxPageRow, Date>( sortableHeaderGroup, "Created Date",
new SortableHeader<JarListPageRow, String>( sortableHeaderGroup, "Name", new SortableHeader<JarListPageRow, String>( sortableHeaderGroup, "Path", new SortableHeader<JarListPageRow, Date>(sortableHeaderGroup, "LastModified", lastModifiedColumn),
new SortableHeader<T, String>( sortableHeaderGroup, TableConstants.INSTANCE.fileURI(),