簡體   English   中英

Jface TreeViewer setSelection

[英]Jface TreeViewer setSelection

匹配的編輯器激活時,我試圖選擇一個treenode。

這是代碼:

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

   treeViewer.setSelection(selection, true); 
}

但是什么也沒選擇,我想念什么?

顯而易見的答案是input不在您的樹中。 也許您的樹中有文件,並且您想要執行以下操作:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM