简体   繁体   中英

Jface TreeViewer setSelection

I am trying to select a treenode when a matched editor is activated.

this is the code:

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

   treeViewer.setSelection(selection, true); 
}

But nothing is selected, what am I missing?

The obvious answer is that input is not in your tree. Perhaps you have files in your tree and you want to do something like:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM