org.eclipse.swt.widgets.Table#setSortColumn ( )源码实例Demo

下面列出了org.eclipse.swt.widgets.Table#setSortColumn ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

/**
 * {@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());
}
 
源代码2 项目: neoscada   文件: MonitorsViewTable.java
@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 ) );
}
 
源代码3 项目: neoscada   文件: EventViewTable.java
@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 ) );
    }
}
 
源代码4 项目: tracecompass   文件: TmfSimpleTableViewer.java
@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));
    }
}
 
源代码5 项目: depan   文件: NodeKindTableControl.java
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);
}
 
源代码6 项目: birt   文件: ElementNamesConfigurationBlock.java
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;
		}
	});
	
}
 
源代码7 项目: MergeProcessor   文件: Dashboard.java
/**
 * 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;
	}
}
 
源代码8 项目: nebula   文件: SortTableColumnSelectionListener.java
@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());
}
 
源代码9 项目: tm4e   文件: ColumnSelectionAdapter.java
@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();
}
 
源代码10 项目: tm4e   文件: ColumnSelectionAdapter.java
@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();
}
 
源代码11 项目: depan   文件: EdgeDisplayTableControl.java
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);
}
 
源代码12 项目: depan   文件: RelationDisplayTableControl.java
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);
}
 
源代码13 项目: depan   文件: RelationSetTableControl.java
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);
}
 
源代码14 项目: APICloud-Studio   文件: HistoryTableProvider.java
/**
 * 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;
}
 
源代码15 项目: Flashtool   文件: TableSorter.java
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();
}
 
源代码16 项目: elexis-3-core   文件: TableViewerSorter.java
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();
	
}
 
源代码17 项目: codewind-eclipse   文件: NewCodewindProjectPage.java
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);
}
 
源代码18 项目: spotbugs   文件: DetectorConfigurationTab.java
/**
 * 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;
}
 
源代码19 项目: bonita-studio   文件: TableColumnSorter.java
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);
}