List<SortKey> newSortKeys = new ArrayList<SortKey>(getSortKeys());
// see if we're already sorting with this column
SortOrder columnSortOrder = SortOrder.ASCENDING;
for(Iterator<? extends SortKey> s = newSortKeys.iterator(); s.hasNext(); ) {
SortKey sortKey = s.next();
if(sortKey.getSortOrder() == SortOrder.UNSORTED) continue;
if(sortKey.getColumn() == columnIndex) {
columnSortOrder = (sortKey.getSortOrder() == SortOrder.ASCENDING) ? SortOrder.DESCENDING : SortOrder.ASCENDING;
s.remove();
break;
}
}
// prepare the new sort order
if(!multipleColumnSort) newSortKeys.clear();
newSortKeys.add(new SortKey(columnSortOrder, columnIndex));
// kick off the sort
setSortKeys(newSortKeys);
}