Java Code Examples for org.eclipse.swt.widgets.TableColumn#equals()

The following examples show how to use org.eclipse.swt.widgets.TableColumn#equals() . 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: TableSorter.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
private void tableColumnClicked(TableColumn column) {
	Table table = column.getParent();
	if (column.equals(table.getSortColumn())) {
		table.setSortDirection(table.getSortDirection() == SWT.UP ? SWT.DOWN : SWT.UP);
	}
	else {
		table.setSortColumn(column);
		table.setSortDirection(SWT.UP);
	}
	tableViewer.refresh();
}
 
Example 2
Source File: TableViewerSorter.java    From elexis-3-core with Eclipse Public License 1.0 5 votes vote down vote up
private void tableColumnClicked(TableColumn column){
	Table table = column.getParent();
	if (column.equals(table.getSortColumn())) {
		table.setSortDirection(table.getSortDirection() == SWT.UP ? SWT.DOWN : SWT.UP);
	} else {
		table.setSortColumn(column);
		table.setSortDirection(SWT.UP);
	}
	
	tableViewer.refresh();
	
}
 
Example 3
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);
}