Hiding empty parents - JFace's TreeViewer

时光毁灭记忆、已成空白 提交于 2019-12-10 18:34:41

问题


I'm creating a tree viewer in JFace and I want to achieve something.

I use filter in it. The filter works well, but not perfectly. When I use filter.expandAll() method, the filter filters all of the tree's items, but there's something really annoying. Although it filters all of the tree's items, it doesn't hide item parents, that become now empty.

Example:


As you can see, there's only one item that matches the filter: "General/Map/New". But all of the parents are now shown although that they actually doesn't contain any children.

Part of the code of my filter:

if (element instanceof HotkeyCategory) {
    return true;
} else if (element instanceof HotkeyItem) {
    return ((HotkeyItem) element).getLabel().toLowerCase()
            .matches(searchString.toLowerCase());
}

return false;

As you can see above, I permit all of the childrens' parents. But maybe there's some automagic way of hiding empty parents?

I had some ideas. Do the filtering before redirecting it to tree viewer and create ArrayList with permitted items and their parents OR adding boolean show; to every item and every parent and return it by the filter, but none of these methods satisify me. They're IMHO a bit too complicated for this task.

So, my question is: is there any simple way to achieve what I want?

Regards.


回答1:


Take a look at this. It might help you: Vogella Blog: I like my trees filtered (Eclipse FilteredTree)



来源:https://stackoverflow.com/questions/16985470/hiding-empty-parents-jfaces-treeviewer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!