Example usage for org.eclipse.swt.widgets Tree getSortDirection

List of usage examples for org.eclipse.swt.widgets Tree getSortDirection

Introduction

In this page you can find the example usage for org.eclipse.swt.widgets Tree getSortDirection.

Prototype

public int getSortDirection() 

Source Link

Document

Returns the direction of the sort indicator for the receiver.

Usage

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.
 *//*w ww.  j  a v  a2 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$
    }
}