Search in sources :

Example 1 with ColumnComparator

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) {
                }
            });
        }
    }
}
Also used : HashMap(java.util.HashMap) ColumnComparator(com.cubrid.common.ui.query.control.ColumnComparator) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ColumnInfo(com.cubrid.common.ui.query.control.ColumnInfo) TableColumn(org.eclipse.swt.widgets.TableColumn) SelectionListener(org.eclipse.swt.events.SelectionListener)

Aggregations

ColumnComparator (com.cubrid.common.ui.query.control.ColumnComparator)1 ColumnInfo (com.cubrid.common.ui.query.control.ColumnInfo)1 HashMap (java.util.HashMap)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 SelectionListener (org.eclipse.swt.events.SelectionListener)1 TableColumn (org.eclipse.swt.widgets.TableColumn)1