开发者

Jface's CheckboxTreeViewer how to set initial selection

This question may sounds trivial, but i am struggling with the issue, so, please help if u can. So, here it is : i 开发者_JAVA百科am using a CheckboxTreeViewer for some good reasons. I've google-it for some class usages, and i am currently able to check/uncheck all the childrens of a selected node, and to preserve the selection after a live search with a custom implementation of the StyledCellLabelProvider provider. All good so far. However, so far i am unable to programatically select one or more elements of the tree viewer after i display the widget and call the setInput() method of the viewer.

So, let's assume for instance that the tree will have 10 main nodes, and 5 leafs on node 6. My question is how do i set the checked state of the 3rd leaf?

Thank u.


You should be using an ICheckedStateProvider for the tree viewer. For instance:

checkboxTreeViewer.setCheckStateProvider(new TreeCheckedStatedProvider());

private class TreeCheckedStatedProvider implements ICheckStateProvider {

    @Override
    public boolean isChecked(Object element) {
        return false;
    }

    @Override
    public boolean isGrayed(Object element) {
        return false;
    }

}


Take a look at this: http://akravets.blogspot.com/2009/08/disabling-nodes-in-checkboxtreeviewer.html, might be of some help. It might not be 100% solution to what you are looking for, but I explain how to skip some nodes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜