use of com.cubrid.common.ui.query.control.ColumnComparator in project cubrid-manager by CUBRID.
the class QueryRecordListComparator method createResultColumn.
private void createResultColumn(final TableViewer tableViewer, final QueryRecord queryRecord) {
if (queryRecord != null) {
TableColumn[] tblColumn = new TableColumn[(queryRecord.getColumnInfoList() == null ? 0 : queryRecord.getColumnInfoList().size()) + 1];
tblColumn[0] = new TableColumn(tableViewer.getTable(), SWT.NONE);
tblColumn[0].setText("NO");
tblColumn[0].setWidth(40);
if (queryRecord.getColumnInfoList() == null) {
return;
}
final Map<String, ColumnComparator> colComparatorMap = new HashMap<String, ColumnComparator>();
for (int j = 0; j < queryRecord.getColumnInfoList().size(); j++) {
tblColumn[j + 1] = new TableColumn(tableViewer.getTable(), SWT.NONE);
ColumnInfo columnInfo = (ColumnInfo) queryRecord.getColumnInfoList().get(j);
String name = columnInfo.getName();
String type = columnInfo.getType();
tblColumn[j + 1].setText(name);
tblColumn[j + 1].setToolTipText(columnInfo.getComleteType());
tblColumn[j + 1].setData(columnInfo);
tblColumn[j + 1].pack();
ColumnComparator comparator = new ColumnComparator(columnInfo.getIndex(), type, true);
if (colComparatorMap != null) {
colComparatorMap.put(columnInfo.getIndex(), comparator);
}
tblColumn[j + 1].addSelectionListener(new SelectionListener() {
@SuppressWarnings("unchecked")
public void widgetSelected(SelectionEvent event) {
TableColumn column = (TableColumn) event.widget;
if (column == null || column.getText() == null || column.getText().trim().length() == 0) {
return;
}
TableColumn sortedColumn = tableViewer.getTable().getSortColumn();
int width = column.getWidth();
ColumnInfo columnInfo = (ColumnInfo) column.getData();
ColumnComparator comparator = colComparatorMap.get(columnInfo.getIndex());
tableViewer.getTable().setSortColumn(column);
tableViewer.getTable().setSortDirection(comparator.isAsc() ? SWT.UP : SWT.DOWN);
Collections.sort(queryRecord.getPageData(), comparator);
comparator.setAsc(!comparator.isAsc());
column.pack();
if (column.equals(sortedColumn)) {
column.setWidth(width);
} else {
column.setWidth(width + 25);
}
tableViewer.refresh();
}
public void widgetDefaultSelected(SelectionEvent event) {
}
});
}
}
}
Aggregations