Java Code Examples for org.eclipse.swt.widgets.Table#setSortColumn()
The following examples show how to use
org.eclipse.swt.widgets.Table#setSortColumn() .
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: MergeProcessorColumnSelectionListener.java From MergeProcessor with Apache License 2.0 | 6 votes |
/** * {@inheritDoc} */ @Override public void widgetSelected(SelectionEvent e) { final TableColumn column = (TableColumn) e.widget; final TableViewerColumn viewerColumn = (TableViewerColumn) column.getData(COLUMN_VIEWER_KEY); final Table table = column.getParent(); comparator.setColumn(table.indexOf(column)); if (table.getSortColumn() == column) { table.setSortDirection(table.getSortDirection() == SWT.UP ? SWT.DOWN : SWT.UP); } else { table.setSortColumn(column); table.setSortDirection(SWT.DOWN); } viewerColumn.getViewer().refresh(); configuration.setSortColumn(Column.valueForIndex(table.indexOf(column))); configuration.setSortDirection(table.getSortDirection()); }
Example 2
Source File: ElementNamesConfigurationBlock.java From birt with Eclipse Public License 1.0 | 6 votes |
private void sortTable(final TableColumn column, final boolean asc) { Table table = tableViewer.getTable(); table.setSortColumn(column); table.setSortDirection(asc? SWT.UP : SWT.DOWN); tableViewer.setSorter(new ViewerSorter() { public int compare(Viewer viewer, Object o1, Object o2) { int result; switch(tableViewer.getTable().indexOf(column)) { case 0: default: result = ( (ItemContent) o1 ).getDisplayName().compareTo(( (ItemContent) o2 ).getDisplayName()); break; case 1: result = ( (ItemContent) o1 ).getCustomName().compareTo(( (ItemContent) o2 ).getCustomName()); break; case 2: result = ( (ItemContent) o1 ).getDescription().compareTo(( (ItemContent) o2 ).getDescription()); break; } return asc? result : result * -1; } }); }
Example 3
Source File: NodeKindTableControl.java From depan with Apache License 2.0 | 6 votes |
private void setSortColumn( TableColumn column, int colIndex, int direction) { ITableLabelProvider labelProvider = (ITableLabelProvider) kindViewer.getLabelProvider(); ViewerComparator sorter = new AlphabeticSorter( new LabelProviderToString(labelProvider, colIndex)); if (SWT.UP == direction) { sorter = new InverseSorter(sorter); } Table tableControl = (Table) kindViewer.getControl(); kindViewer.setComparator(sorter); tableControl.setSortColumn(column); tableControl.setSortDirection(direction); }
Example 4
Source File: TmfSimpleTableViewer.java From tracecompass with Eclipse Public License 2.0 | 6 votes |
@Override public void widgetSelected(SelectionEvent e) { Table table = fTableViewer.getTable(); TableColumn prevSortcolumn = table.getSortColumn(); if (prevSortcolumn == fColumn) { flipSortDirection(); } table.setSortDirection(fDirection); table.setSortColumn(fColumn); Comparator<T> comparator; if (fDirection == SWT.DOWN) { comparator = fComparator; } else { comparator = checkNotNull(Collections.reverseOrder(fComparator)); } IContentProvider contentProvider = fTableViewer.getContentProvider(); if (contentProvider instanceof DeferredContentProvider) { DeferredContentProvider deferredContentProvider = (DeferredContentProvider) contentProvider; deferredContentProvider.setSortOrder(comparator); } else if (contentProvider instanceof ISortingLazyContentProvider) { ISortingLazyContentProvider sortingLazyContentProvider = (ISortingLazyContentProvider) contentProvider; sortingLazyContentProvider.setSortOrder(comparator); } else { fTableViewer.setComparator(new ElementComparator<>(comparator)); } }
Example 5
Source File: EventViewTable.java From neoscada with Eclipse Public License 1.0 | 6 votes |
@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 6
Source File: MonitorsViewTable.java From neoscada with Eclipse Public License 1.0 | 6 votes |
@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 7
Source File: ColumnSelectionAdapter.java From tm4e with Eclipse Public License 1.0 | 5 votes |
@Override public void widgetSelected(SelectionEvent e) { viewerComparator.setColumn(fColumnIndex); int dir = viewerComparator.getDirection(); Table table = tableViewer.getTable(); table.setSortDirection(dir); table.setSortColumn(fTableColumn); tableViewer.refresh(); }
Example 8
Source File: ColumnSelectionAdapter.java From tm4e with Eclipse Public License 1.0 | 5 votes |
@Override public void widgetSelected(SelectionEvent e) { viewerComparator.setColumn(fColumnIndex); int dir = viewerComparator.getDirection(); Table table = tableViewer.getTable(); table.setSortDirection(dir); table.setSortColumn(fTableColumn); tableViewer.refresh(); }
Example 9
Source File: SortTableColumnSelectionListener.java From nebula with Eclipse Public License 2.0 | 5 votes |
@Override protected void sort(SelectionEvent e) { // 1) Get table column which fire this selection event TableColumn tableColumn = (TableColumn) e.getSource(); // 2) Get the owner table Table table = tableColumn.getParent(); // 3) Modify the SWT Table sort table.setSortColumn(tableColumn); table.setSortDirection(getSortDirection()); }
Example 10
Source File: EdgeDisplayTableControl.java From depan with Apache License 2.0 | 5 votes |
private void setSortColumn( TableColumn column, int colIndex, int direction) { ViewerComparator sorter = buildColumnSorter(colIndex); if (SWT.UP == direction) { sorter = new InverseSorter(sorter); } Table tableControl = (Table) propViewer.getControl(); propViewer.setComparator(sorter); tableControl.setSortColumn(column); tableControl.setSortDirection(direction); }
Example 11
Source File: RelationDisplayTableControl.java From depan with Apache License 2.0 | 5 votes |
private void setSortColumn( TableColumn column, int colIndex, int direction) { ViewerComparator sorter = buildColumnSorter(colIndex); if (SWT.UP == direction) { sorter = new InverseSorter(sorter); } Table tableControl = (Table) propViewer.getControl(); propViewer.setComparator(sorter); tableControl.setSortColumn(column); tableControl.setSortDirection(direction); }
Example 12
Source File: RelationSetTableControl.java From depan with Apache License 2.0 | 5 votes |
private void setSortColumn( TableColumn column, int colIndex, int direction) { ViewerComparator sorter = buildColumnSorter(colIndex); if (SWT.UP == direction) { sorter = new InverseSorter(sorter); } Table tableControl = (Table) relSetViewer.getControl(); relSetViewer.setComparator(sorter); tableControl.setSortColumn(column); tableControl.setSortDirection(direction); }
Example 13
Source File: HistoryTableProvider.java From APICloud-Studio with GNU General Public License v3.0 | 5 votes |
/** * Create a TableViewer that can be used to display a list of ILogEntry instances. * Ths method provides the labels and sorter but does not provide a content provider * * @param parent * @return TableViewer */ public TableViewer createTable(Composite parent) { Table table = new Table(parent, style); table.setHeaderVisible(true); table.setLinesVisible(true); GridData data = new GridData(GridData.FILL_BOTH); data.horizontalIndent = 0; data.verticalIndent = 0; table.setLayoutData(data); TableLayout layout = new TableLayout(); table.setLayout(layout); TableViewer viewer = new TableViewer(table); createColumns(table, layout, viewer); viewer.setLabelProvider(new HistoryLabelProvider()); HistorySorter sorter = new HistorySorter(COL_REVISION); viewer.setSorter(sorter); table.setSortDirection(SWT.DOWN); table.setSortColumn(table.getColumn(0)); table.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { if(currentRevisionFont != null) { currentRevisionFont.dispose(); } } }); this.viewer = viewer; return viewer; }
Example 14
Source File: TableSorter.java From Flashtool with GNU General Public License v3.0 | 5 votes |
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 15
Source File: Dashboard.java From MergeProcessor with Apache License 2.0 | 5 votes |
/** * Handles the given {@link PropertyChangeEvent}. * * @param event the event to handle */ private void handlePropertyChange(PropertyChangeEvent event) { switch (event.getProperty()) { case WorkbenchPreferencePage.WINDOW_SIZE: LogUtil.getLogger().fine("Setting new window size."); //$NON-NLS-1$ shell.setSize(Configuration.getWindowSize()); break; case WorkbenchPreferencePage.WINDOW_LOCATION: LogUtil.getLogger().fine("Setting new window location."); //$NON-NLS-1$ shell.setLocation(Configuration.getWindowLocation()); break; case WorkbenchPreferencePage.SORT_COLUMN: LogUtil.getLogger().fine("Setting new sort column."); //$NON-NLS-1$ final int columnIndex1 = Column.indexForValue(configuration.getSortColumn()); final Table table1 = view.getTableViewer().getTable(); comparator.setColumn(columnIndex1); table1.setSortColumn(table1.getColumn(columnIndex1)); view.getTableViewer().refresh(); break; case WorkbenchPreferencePage.SORT_DIRECTION: LogUtil.getLogger().fine("Setting new sort direction."); //$NON-NLS-1$ final int columnIndex = comparator.getColumn(); final Table table = view.getTableViewer().getTable(); comparator.setColumn(columnIndex); table.setSortColumn(table.getColumn(columnIndex)); table.setSortDirection(configuration.getSortDirection()); view.getTableViewer().refresh(); break; default: break; } }
Example 16
Source File: TableViewerSorter.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
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 17
Source File: DetectorConfigurationTab.java From spotbugs with GNU Lesser General Public License v2.1 | 4 votes |
/** * Build rule table viewer */ private Table createDetectorsTableViewer(Composite parent, IProject project) { final BugPatternTableSorter sorter = new BugPatternTableSorter(this); int tableStyle = SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL | SWT.SINGLE | SWT.FULL_SELECTION | SWT.CHECK; availableFactoriesTableViewer = CheckboxTableViewer.newCheckList(parent, tableStyle); availableFactoriesTableViewer.addCheckStateListener(new ICheckStateListener() { @Override public void checkStateChanged(CheckStateChangedEvent event) { syncUserPreferencesWithTable(); } }); int currentColumnIdx = 0; Table factoriesTable = availableFactoriesTableViewer.getTable(); TableColumn factoryNameColumn = createColumn(currentColumnIdx, factoriesTable, getMessage("property.detectorName"), 230, COLUMN.DETECTOR_NAME); addColumnSelectionListener(sorter, factoryNameColumn, COLUMN.DETECTOR_NAME); currentColumnIdx++; TableColumn bugsAbbrevColumn = createColumn(currentColumnIdx, factoriesTable, getMessage("property.bugCodes"), 75, COLUMN.BUG_CODES); addColumnSelectionListener(sorter, bugsAbbrevColumn, COLUMN.BUG_CODES); currentColumnIdx++; TableColumn speedColumn = createColumn(currentColumnIdx, factoriesTable, getMessage("property.speed"), 70, COLUMN.DETECTOR_SPEED); addColumnSelectionListener(sorter, speedColumn, COLUMN.DETECTOR_SPEED); currentColumnIdx++; TableColumn pluginColumn = createColumn(currentColumnIdx, factoriesTable, getMessage("property.provider"), 100, COLUMN.PLUGIN); addColumnSelectionListener(sorter, pluginColumn, COLUMN.PLUGIN); currentColumnIdx++; TableColumn categoryColumn = createColumn(currentColumnIdx, factoriesTable, getMessage("property.category"), 75, COLUMN.BUG_CATEGORIES); addColumnSelectionListener(sorter, categoryColumn, COLUMN.BUG_CATEGORIES); factoriesTable.setLinesVisible(true); factoriesTable.setHeaderVisible(true); // initial sort indicator factoriesTable.setSortDirection(sorter.revertOrder ? SWT.UP : SWT.DOWN); factoriesTable.setSortColumn(factoryNameColumn); sorter.setSortColumnIndex(COLUMN.DETECTOR_NAME); availableFactoriesTableViewer.setContentProvider(new DetectorFactoriesContentProvider()); availableFactoriesTableViewer.setLabelProvider(new DetectorFactoryLabelProvider(this)); availableFactoriesTableViewer.setSorter(sorter); populateAvailableRulesTable(project); factoriesTable.setEnabled(true); return factoriesTable; }
Example 18
Source File: NewCodewindProjectPage.java From codewind-eclipse with Eclipse Public License 2.0 | 4 votes |
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); }
Example 19
Source File: TableColumnSorter.java From bonita-studio with GNU General Public License v2.0 | 4 votes |
public void setColumn(TableColumn selectedColumn) { if (column == selectedColumn) { switch (direction) { case ASC: direction = DESC; break; case DESC: direction = ASC; break; default: direction = ASC; break; } } else { this.column = selectedColumn; this.direction = ASC; } Table table = viewer.getTable(); switch (direction) { case ASC: table.setSortColumn(selectedColumn); table.setSortDirection(SWT.UP); break; case DESC: table.setSortColumn(selectedColumn); table.setSortDirection(SWT.DOWN); break; default: table.setSortColumn(null); table.setSortDirection(SWT.NONE); break; } TableColumn[] columns = table.getColumns(); for (int i = 0; i < columns.length; i++) { TableColumn theColumn = columns[i]; if (theColumn == this.column) columnIndex = i; } viewer.setComparator(null); viewer.setComparator(this); }