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

The following examples show how to use org.eclipse.swt.widgets.Table#getSortDirection() . 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 check out the related API usage on the sidebar.
Example 1
Source File: MonitorsViewTable.java    From neoscada with 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 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 2
Source File: EventViewTable.java    From neoscada with 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 3
Source File: TableViewerSorter.java    From elexis-3-core with Eclipse Public License 1.0 6 votes vote down vote up
@SuppressWarnings({
	"rawtypes", "unchecked"
})
private int compareElements(Object e1, Object e2){
	IColumnContentProvider columnValueProvider =
		(IColumnContentProvider) tableViewer.getContentProvider();
	
	Table table = tableViewer.getTable();
	
	int index = Arrays.asList(table.getColumns()).indexOf(table.getSortColumn());
	int result = 0;
	if (index != -1) {
		Comparable c1 = columnValueProvider.getValue(e1, index);
		Comparable c2 = columnValueProvider.getValue(e2, index);
		if (c1 instanceof String && c2 instanceof String) {
			String _c1 = (String) c1;
			String _c2 = (String) c2;
			result = _c1.compareToIgnoreCase(_c2);
		} else {
			result = c1.compareTo(c2);
		}
	}
	
	return table.getSortDirection() == SWT.UP ? result : -result;
}
 
Example 4
Source File: CoverageViewerComparator.java    From tlaplus with 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 5
Source File: NodeKindTableControl.java    From depan with 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 6
Source File: EdgeDisplayTableControl.java    From depan with 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 7
Source File: RelationDisplayTableControl.java    From depan with 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
Source File: RelationSetTableControl.java    From depan with 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 9
Source File: TableSorter.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
private int compareElements(Object e1, Object e2) {
	Table table = tableViewer.getTable();
	int index = Arrays.asList(table.getColumns()).indexOf(table.getSortColumn());
	int result = 0;
	if (index != -1) {
		Comparable c1 = ((TableLine)e1).getValueOf(index);
		Comparable c2 = ((TableLine)e2).getValueOf(index);
		result = c1.compareTo(c2);
	}
	return table.getSortDirection() == SWT.UP ? result : -result;
}
 
Example 10
Source File: NewCodewindProjectPage.java    From codewind-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
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);
}