List of usage examples for org.eclipse.swt.widgets Tree getSortColumn
public TreeColumn getSortColumn()
From source file:org.eclipse.swt.examples.controlexample.TreeTab.java
/** * Sets the initial sort indicator state and adds a listener * to cycle through sort states and columns. *//*from w ww .j ava 2 s . c o m*/ void initializeSortState(final Tree tree) { /* Reset to known state: 'down' on column 0. */ tree.setSortDirection(SWT.DOWN); TreeColumn[] columns = tree.getColumns(); for (int i = 0; i < columns.length; i++) { TreeColumn column = columns[i]; if (i == 0) tree.setSortColumn(column); SelectionListener listener = widgetSelectedAdapter(e -> { int sortDirection = SWT.DOWN; if (e.widget == tree.getSortColumn()) { /* If the sort column hasn't changed, cycle down -> up -> none. */ switch (tree.getSortDirection()) { case SWT.DOWN: sortDirection = SWT.UP; break; case SWT.UP: sortDirection = SWT.NONE; break; } } else { tree.setSortColumn((TreeColumn) e.widget); } tree.setSortDirection(sortDirection); }); column.addSelectionListener(listener); column.setData("SortListener", listener); //$NON-NLS-1$ } }