下面列出了org.eclipse.swt.widgets.Tree#getColumn ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
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();
}
});
}
}
}
private void applyViewContext() {
ViewContext viewContext = fViewContext.remove(fTrace);
applyExpandedStateContext(viewContext);
if (fColumnComparators != null) {
final Tree tree = fTimeGraphViewer.getTree();
final TreeColumn column = tree.getColumn(fCurrentSortColumn);
tree.setSortDirection(fSortDirection);
tree.setSortColumn(column);
}
// restore and reveal selection
if ((viewContext != null) && (viewContext.getSelection() != null)) {
fTimeGraphViewer.setSelection(viewContext.getSelection(), true);
}
}
public void updateTree(Tree tree, List<String[]> listed) {
TreeColumn column = tree.getColumn(0);
column.setText("Library (" + getPackageManagerName() + " | " + listed.size() + " found)");
for (String[] s : listed) {
TreeItem item = new TreeItem(tree, SWT.None);
item.setText(s);
}
}
private static void copyHeaders(Tree tree, int levels, StringBuilder text) {
int cols = tree.getColumnCount();
if (cols < 1)
return;
text.append(tree.getColumn(0).getText());
for (int level = 0; level < levels; level++)
text.append('\t');
for (int col = 1; col < cols; col++) {
TreeColumn column = tree.getColumn(col);
text.append(column.getText());
if (col != (cols - 1))
text.append('\t');
}
text.append('\n');
}