/** * * @return the currently interactively sorted TableColumn or null if there * is not sorter active or if the sorted column index does not * correspond to any column in the TableColumnModel. */ public TableColumn getSortedColumn() { // bloody hack: get primary SortKey and // check if there's a column with it available SortController controller = getSortController(); if (controller != null) { SortKey sortKey = SortKey.getFirstSortingKey(controller .getSortKeys()); if (sortKey != null) { int sorterColumn = sortKey.getColumn(); List<TableColumn> columns = getColumns(true); for (Iterator<TableColumn> iter = columns.iterator(); iter .hasNext();) { TableColumn column = iter.next(); if (column.getModelIndex() == sorterColumn) { return column; } } } } return null; }
public void setSortKeys(List<? extends SortKey> keys) { if ((keys == null) || keys.isEmpty()) { setSorter(null); return; } SortKey sortKey = SortKey.getFirstSortingKey(keys); // only crappy unsorted... if (sortKey == null) return; Sorter sorter = getSorter(); if (sorter == null) { sorter = createDefaultSorter(); } sorter.setSortKey(sortKey); // technically, we could re-use the sorter // and only reset column, comparator and direction // need to detangle from TableColumn before going there... // so for now we only change the order if we have a sorter // for the given column, create a new default sorter if not // if ((currentSorter == null) || // (currentSorter.getColumnIndex() != sortKey.getColumn())) { // currentSorter = createDefaultSorter(sortKey); // } // if (currentSorter.isAscending() != sortKey.getSortOrder().isAscending()) { // currentSorter.setAscending(sortKey.getSortOrder().isAscending()); // } setSorter(sorter); }