2011-12-23 93 views
1

我想在匹配的编辑器被激活时选择treenode。Jface TreeViewer setSelection

这是代码:

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

    treeViewer.setSelection(selection, true); 
} 

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

回答

1

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

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