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(...);
有帮助吗?

解决方案

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);
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top