Java Code Examples for org.eclipse.swt.widgets.Table#getSortColumn()

The following examples show how to use org.eclipse.swt.widgets.Table#getSortColumn() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * {@inheritDoc}
 */
@Override
public void widgetSelected(SelectionEvent e) {
	final TableColumn column = (TableColumn) e.widget;
	final TableViewerColumn viewerColumn = (TableViewerColumn) column.getData(COLUMN_VIEWER_KEY);
	final Table table = column.getParent();
	comparator.setColumn(table.indexOf(column));
	if (table.getSortColumn() == column) {
		table.setSortDirection(table.getSortDirection() == SWT.UP ? SWT.DOWN : SWT.UP);
	} else {
		table.setSortColumn(column);
		table.setSortDirection(SWT.DOWN);
	}
	viewerColumn.getViewer().refresh();
	configuration.setSortColumn(Column.valueForIndex(table.indexOf(column)));
	configuration.setSortDirection(table.getSortDirection());
}
 
Example 2
@Override
public void widgetSelected ( final SelectionEvent e )
{
    final Table table = this.tableViewer.getTable ();
    final TableColumn newColumn = (TableColumn)e.widget;
    final TableColumn currentColumn = table.getSortColumn ();

    final int currentDir = table.getSortDirection ();
    int newDir = SWT.UP;
    if ( newColumn == currentColumn )
    {
        newDir = currentDir == SWT.UP ? SWT.DOWN : SWT.UP;
    }
    else
    {
        table.setSortColumn ( newColumn );
    }
    table.setSortDirection ( newDir );
    this.tableViewer.setSorter ( new Sorter ( (Columns)newColumn.getData ( COLUMN_KEY ), newDir ) );
}
 
Example 3
Source Project: neoscada   File: EventViewTable.java    License: Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void widgetSelected ( final SelectionEvent e )
{
    final Table table = this.tableViewer.getTable ();
    final TableColumn newColumn = (TableColumn)e.widget;
    final TableColumn currentColumn = table.getSortColumn ();

    final EventTableColumn column = (EventTableColumn)newColumn.getData ( COLUMN_KEY );
    if ( column == EventTableColumn.reservedColumnSourceTimestamp || column == EventTableColumn.reservedColumnEntryTimestamp )
    {
        final int currentDir = table.getSortDirection ();
        int newDir = SWT.UP;
        if ( newColumn == currentColumn )
        {
            newDir = currentDir == SWT.UP ? SWT.DOWN : SWT.UP;
        }
        else
        {
            table.setSortColumn ( newColumn );
        }
        table.setSortDirection ( newDir );
        this.tableViewer.setSorter ( new EventTableSorter ( column, newDir ) );
    }
}
 
Example 4
@Override
public void widgetSelected(SelectionEvent e) {
    Table table = fTableViewer.getTable();
    TableColumn prevSortcolumn = table.getSortColumn();
    if (prevSortcolumn == fColumn) {
        flipSortDirection();
    }
    table.setSortDirection(fDirection);
    table.setSortColumn(fColumn);
    Comparator<T> comparator;
    if (fDirection == SWT.DOWN) {
        comparator = fComparator;
    } else {
        comparator = checkNotNull(Collections.reverseOrder(fComparator));
    }
    IContentProvider contentProvider = fTableViewer.getContentProvider();
    if (contentProvider instanceof DeferredContentProvider) {
        DeferredContentProvider deferredContentProvider = (DeferredContentProvider) contentProvider;
        deferredContentProvider.setSortOrder(comparator);
    } else if (contentProvider instanceof ISortingLazyContentProvider) {
        ISortingLazyContentProvider sortingLazyContentProvider = (ISortingLazyContentProvider) contentProvider;
        sortingLazyContentProvider.setSortOrder(comparator);
    } else {
        fTableViewer.setComparator(new ElementComparator<>(comparator));
    }
}
 
Example 5
Source Project: tlaplus   File: CoverageViewerComparator.java    License: MIT License 5 votes vote down vote up
@Override
public int compare(final Viewer viewer, final Object e1, final Object e2) {
	final ActionInformationItem a1 = (ActionInformationItem) e1;
	final ActionInformationItem a2 = (ActionInformationItem) e2;

	final Table table = (Table) viewer.getControl();
	final TableColumn sortColumn = table.getSortColumn();
	if (sortColumn == null) {
		// a) Compare by distinct states first (we want actions with zero distinct states
		// to appear at the top).
		if (Long.compare(a1.getUnseen(), a2.getUnseen()) == 0L) {
			// b) Compare by location
			return a1.getModuleLocation().compareTo(a2.getModuleLocation());
		} else {
			return Long.compare(a1.getUnseen(), a2.getUnseen());
		}
	} else {
		// User requested to sort a specific column up or down.
		@SuppressWarnings("unchecked")
		final Comparator<ActionInformationItem> comp = (Comparator<ActionInformationItem>) sortColumn
				.getData(CoverageLabelProvider.COVERAGE_COMPARATOR);
		if (table.getSortDirection() == SWT.UP) {
			return comp.compare(a2, a1);
		} else {
			return comp.compare(a1, a2);
		}
	}
}
 
Example 6
Source Project: depan   File: NodeKindTableControl.java    License: Apache License 2.0 5 votes vote down vote up
private int getSortDirection(TableColumn column) {
  Table tableControl = (Table) kindViewer.getControl();
  if (column != tableControl.getSortColumn()) {
    return SWT.DOWN;
  }
  // If it is unsorted (SWT.NONE), assume down sort
  return (SWT.DOWN == tableControl.getSortDirection())
      ? SWT.UP : SWT.DOWN;
}
 
Example 7
Source Project: depan   File: EdgeDisplayTableControl.java    License: Apache License 2.0 5 votes vote down vote up
private int getSortDirection(TableColumn column) {
  Table tableControl = (Table) propViewer.getControl();
  if (column != tableControl.getSortColumn()) {
    return SWT.DOWN;
  }
  // If it is unsorted (SWT.NONE), assume down sort
  return (SWT.DOWN == tableControl.getSortDirection())
      ? SWT.UP : SWT.DOWN;
}
 
Example 8
private int getSortDirection(TableColumn column) {
  Table tableControl = (Table) propViewer.getControl();
  if (column != tableControl.getSortColumn()) {
    return SWT.DOWN;
  }
  // If it is unsorted (SWT.NONE), assume down sort
  return (SWT.DOWN == tableControl.getSortDirection())
      ? SWT.UP : SWT.DOWN;
}
 
Example 9
Source Project: depan   File: RelationSetTableControl.java    License: Apache License 2.0 5 votes vote down vote up
private int getSortDirection(TableColumn column) {
  Table tableControl = (Table) relSetViewer.getControl();
  if (column != tableControl.getSortColumn()) {
    return SWT.DOWN;
  }
  // If it is unsorted (SWT.NONE), assume down sort
  return (SWT.DOWN == tableControl.getSortDirection())
      ? SWT.UP : SWT.DOWN;
}
 
Example 10
public static void sortTable(Table table, TableColumn column) {
	TableItem[] items = table.getItems();
	int rows = items.length;
	int dir = table.getSortDirection() == SWT.DOWN ? 1 : -1;
	TableColumn currentColumn = table.getSortColumn();
	int columnNum = 0;
	for (int j = 0; j < table.getColumnCount(); j++) {
		if (table.getColumn(j).equals(column)) {
			columnNum = j;
			break;
		}
	}
	if (column.equals(currentColumn))
		dir = -dir;
	else
		dir = 1;

	// sort an index map, then move the actual rows
	int[] map = new int[rows];
	for (int i = 0; i < rows; i++)
		map[i] = i;

	for (int i = 0; i < rows - 1; i++) {
		for (int j = i + 1; j < rows; j++) {
			TableItem a = items[map[i]];
			TableItem b = items[map[j]];
			if ((a.getText(columnNum).toLowerCase().compareTo(b.getText(columnNum).toLowerCase()) * dir > 0)) {
				int t = map[i];
				map[i] = map[j];
				map[j] = t;
			}
		}
	}

	// can't move existing items or delete first, so append new items to the end and then delete existing rows
	for (int i = 0; i < rows; i++) {
		int n = map[i];
		TableItem item = new TableItem(table, SWT.NONE);
		for (int j = 0; j < table.getColumnCount(); j++) {
			item.setText(j, items[n].getText(j));
		}
		item.setData(items[n].getData());
		items[n].dispose();
	}

	table.setSortDirection(dir == 1 ? SWT.DOWN : SWT.UP);
	table.setSortColumn(column);
}