Jface TreeViewer setSelection

时间:2011-12-23 10:21:09

标签: java treeview jface

我正在尝试在激活匹配的编辑器时选择treenode。

这是代码:

private void selectNodeInTree(IEditorPart activatedEditor) {
   IEditorInput input = activatedEditor.getEditorInput();
   StructuredSelection selection = new StructuredSelection(input); //Selection is not null!

   treeViewer.setSelection(selection, true); 
}

但没有选择,我缺少什么?

1 个答案:

答案 0 :(得分:1)

显而易见的答案是input不在您的树中。也许你的树中有文件,你想做类似的事情:

IFile file = (IFile) input.getAdapter(IFile.class);
StructuredSelection selection = new StructuredSelection(file);