Java Code Examples for org.eclipse.swt.widgets.TreeColumn#addSelectionListener()

The following examples show how to use org.eclipse.swt.widgets.TreeColumn#addSelectionListener() . 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: AbstractTimeGraphView.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private void createColumnSelectionListener(Tree tree) {
    for (int i = 0; i < fColumnComparators.length; i++) {
        final int index = i;
        final Comparator<ITimeGraphEntry> comp = fColumnComparators[index];
        final TreeColumn column = tree.getColumn(i);

        if (comp != null) {
            column.addSelectionListener(new SelectionAdapter() {
                @Override
                public void widgetSelected(SelectionEvent e) {
                    TreeColumn prevSortcolumn = tree.getSortColumn();
                    int direction = tree.getSortDirection();
                    if (prevSortcolumn == column) {
                        direction = (direction == SWT.DOWN) ? SWT.UP : SWT.DOWN;
                    } else {
                        direction = SWT.DOWN;
                    }
                    tree.setSortColumn(column);
                    tree.setSortDirection(direction);
                    fSortDirection = direction;
                    fCurrentSortColumn = index;
                    Comparator<ITimeGraphEntry> comparator = comp;

                    if (comparator instanceof ITimeGraphEntryComparator) {
                        ((ITimeGraphEntryComparator) comparator).setDirection(direction);
                    }
                    if (direction != SWT.DOWN) {
                        comparator = checkNotNull(Collections.reverseOrder(comparator));
                    }
                    setEntryComparator(comparator);
                    fIsRevealSelection = true;
                    fTimeGraphViewer.getControl().setFocus();
                    refresh();
                }
            });
        }
    }
}
 
Example 2
Source File: NodeStatsTableControl.java    From depan with Apache License 2.0 5 votes vote down vote up
private void configSorters(Tree tree) {
  int index = 0;
  for (TreeColumn column : tree.getColumns()) {
    final int colIndex = index++;

    column.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent event) {
        updateSortColumn((TreeColumn) event.widget, colIndex);
      }
    });
  }
}
 
Example 3
Source File: NodeDisplayTableControl.java    From depan with Apache License 2.0 5 votes vote down vote up
private void configSorters(Tree tree) {
  int index = 0;
  for (TreeColumn column : tree.getColumns()) {
    final int colIndex = index++;

    column.addSelectionListener(new SelectionAdapter() {
      @Override
      public void widgetSelected(SelectionEvent event) {
        updateSortColumn((TreeColumn) event.widget, colIndex);
      }
    });
  }
}
 
Example 4
Source File: GenerericTreeViewer.java    From offspring with MIT License 4 votes vote down vote up
private void createColumns() {
  GC gc = new GC(getTree().getParent());

  List<Integer> widths = new ArrayList<Integer>();

  for (final IGenericTableColumn c : table.getColumns()) {
    TreeViewerColumn viewerColumn = new TreeViewerColumn(this, SWT.NONE);

    viewerColumn.setLabelProvider(new GenericLabelProvider(c
        .getDataProvider()));

    if (c.getEditable()) {
      viewerColumn.setEditingSupport(c.getEditingSupport(this));
    }

    TreeColumn column = viewerColumn.getColumn();

    if (c.getSortable() && comparator != null) {
      column.addSelectionListener(getSelectionAdapter(column, c));
    }
    column.setText(c.getLabel());
    column.setAlignment(c.getAlignMent());

    int width;
    if (c.getWidth() != -1) {
      width = c.getWidth();
    }
    else if (c.getTextExtent() != null
        && c.getLabel().length() < c.getTextExtent().length()) {
      width = gc.textExtent(c.getTextExtent()).x + 2;
    }
    else {
      width = gc.textExtent(c.getLabel()).x + 2;
    }

    widths.add(width);
    column.setWidth(width);
    column.setResizable(c.getResizable());
  }
  gc.dispose();

  // /* All columns have their prefered width set now calculate percentages */
  // TreeColumnLayout layout = new TreeColumnLayout();
  // for (int i = 0; i < widths.size(); i++) {
  // layout.setColumnData(getTree().getColumns()[i], new ColumnWeightData(
  // widths.get(i), widths.get(i), true));
  // }
  // getTree().getParent().setLayout(layout);
}