swt Table sortieren

Code:
public static void sortTable(Table table, int columnIndex){
if(table == null || table.getColumncount() <= 1)
return;
if(columnIndex < 0 || columnIndex >= table.getColumnCount())
throw new IllegalArgumentException("The specified column does not exits. ");

final int colIndex = columnIndex;
Comparator comparator = new Comparator(){
public int compare(Object o1, Object o2){
return ((TableItem)o1).getText(colIndex).compareTo(((TableItem)o2).getText(colIndex));
}

public boolean equals(Object obj){
return false;
}
};

TableItem[] tableItems = table.getItems();
Arrays.sort(tableItems, comparator);

for(int i = 0; i < tableItems.length; i++){
TableItem item = new TableItem(table, SWT.NULL);
for(int j = 0; j < table.getColumnCount(); j++){
item.setText(j, tableItems[i].getText(j));
item.setImage(j, tableItems[i].getImage(j));
}
tableItems[i].dispose();
}
}
 

Neue Beiträge

Zurück