隐藏空父母 - JFace的TreeViewer [英] Hiding empty parents - JFace's TreeViewer

查看:215
本文介绍了隐藏空父母 - JFace的TreeViewer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在JFace中创建了一个树查看器,并且我想实现一些东西。

我使用过滤器。过滤器运作良好,但并不完美。当我使用 filter.expandAll()方法时,过滤器会过滤所有树的项目,但是真的很烦人。虽然它过滤了所有树的项目,但它并不隐藏项目父项,现在变成空的。



例子:



正如你所看到的,只有一个项目匹配过滤器:常规/地图/新建。但是现在所有的父母都显示出来了,但他们实际上并没有包含任何孩子。



我的过滤器的部分代码:

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

return false;

正如你所看到的,我允许所有的孩子的父母。但也许有一些automagic方式隐藏空父母?



我有一些想法。在将其重定向到树查看器之前进行过滤,并创建具有允许项目及其父项的ArrayList,或者向每个项目和每个父项添加布尔值显示; ,并通过过滤器返回它,但这些方法都不能令我满意。他们恕我直言有点太复杂这个任务。

所以,我的问题是:是否有任何简单的方法来实现我想要的?



问候。

解决方案

看看这个。它可能会帮助你:
Vogella博客:我喜欢我的树过滤( Eclipse FilteredTree)


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.

解决方案

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

这篇关于隐藏空父母 - JFace的TreeViewer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆