for (final TableColumn column : columns) {
column.addSelectionListener(new SelectionAdapter() {
@SuppressWarnings("unchecked")
@Override
public void widgetSelected(SelectionEvent e) {
Columns oldSortBy = fNewsSorter.getSortBy();
Columns newSortBy = (Columns) column.getData(COL_ID);
boolean defaultAscending = newSortBy.prefersAscending();
boolean ascending = (oldSortBy != newSortBy) ? defaultAscending : !fNewsSorter.isAscending();
fNewsSorter.setSortBy(newSortBy);
fNewsSorter.setAscending(ascending);
/* Indicate Sort-Column in UI for Columns that have a certain width */
if (newSortBy.showSortIndicator()) {
fResultViewer.getTable().setSortColumn(column);
fResultViewer.getTable().setSortDirection(ascending ? SWT.UP : SWT.DOWN);
} else {
fResultViewer.getTable().setSortColumn(null);
}