3

Having a reference to a jface TreeViewer, how can you get a list of its columns, e.g. TreeViewerColumn objects? Something like:

TreeViewer treeViewer = (TreeViewer)viewer;
TreeViewerColumn[] treeViewerColumns = treeViewer.getColumns();

Is it just me or there isn't an obvious way to do this?

What I'm trying to do is to add editing support for items in Project Explorer. I have a reference to the Project Explorer's tree viewer, but I need to obtain its TreeViewerColumn and do:

column.setEditingSupport(...);
flavio.donze
  • 7,432
  • 9
  • 58
  • 91
pm_
  • 853
  • 6
  • 15

1 Answers1

3

A reference to the TreeViewerColumn is stored in the data of the TreeColumn. The following should give you a list of TreeViewerColumns:

List<TreeViewerColumn> treeViewerColumns = new ArrayList<TreeViewerColumn>();
TreeColumn[] columns = treeViewer.getTree().getColumns();
for (TreeColumn column : columns) {
    Object data = column.getData(Policy.JFACE + ".columnViewer");
    if (data instanceof TableViewerColumn) {
        TreeViewerColumn tvc = (TreeViewerColumn) data;
        treeViewerColumns.add(tvc);
    }
}
flavio.donze
  • 7,432
  • 9
  • 58
  • 91
Nick Wilson
  • 4,959
  • 29
  • 42
  • Thanks! The above snippet does exactly that, but the Project Explorer's tree viewer appears to have no explicitly added columns - treeViewer.getTree().getColumns() returns an empty array. Anyway, this is another question. – pm_ Jul 12 '13 at 06:13