如何让 SWT 中的 TreeViewer 正确刷新?

发布于 2024-12-07 19:53:30 字数 456 浏览 2 评论 0原文

我有一个使用 JFace TreeViewer 的应用程序。我将它连接到 ContentProvider。大多数情况下,它效果很好。但是,对于某些操作,例如在节点列表中间添加节点或更改应更改节点标签的值,refresh() 调用不起作用。我尝试过包括父节点,对标签更新说“true”。没有什么是始终有效的。

我已经看到,如果我关闭可折叠节点并添加然后展开,则会显示添加的节点。但如果它已经扩展,则不会显示任何变化。如果我将树信息保存到磁盘并查看,就会发生更改。只是 TreeViewer 刷新不起作用。

我查看了 ContentProvider 中的 inputChanged 方法,但它仅在应用程序执行的开始和结束时调用。

有人可以帮忙吗?我已经阅读了所有甚至暗示答案的网页,但没有任何效果。

I have an app that uses a JFace TreeViewer. I have it hooked up to a ContentProvider. Mostly, it works great. However, for some actions, like adding a Node in the middle of a list of Nodes or changing a value which should change the label for a Node, the refresh() call doesn't work. I've tried including the parent Node, say "true" for label update. Nothing works all the time.

I have seen that if I leave a collapsible Node closed and add and then expand, the added Node is shown. But if it's already expanded, no change is shown. If I save my tree info to disk and look, the change is made. It's just the TreeViewer refresh that is not working.

I looked at the inputChanged method in my ContentProvider, but it is only called at the beginning and end of my app execution.

Can anyone help? I've read all the web pages that even hint at an answer and nothing has worked.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

掐死时间 2024-12-14 19:53:30

inputChanged()(如果在refresh()期间不应调用contentprovider) - 仅当对树查看器进行setInput()调用时才调用它。

在最坏的情况下,您可以使用原始输入调用 setInput() 来刷新元素,但这对于您的应用程序来说可能太慢了。

基本上,当您在组中间添加新节点时,必须刷新父节点(使用 getChildren() 调用返回添加元素的节点)或其父节点之一。基本上,由于这个原因,调用不带任何参数的刷新()可能会起作用。

因此,为了进行测试,我建议您应该在不带任何参数的情况下调用refresh(),尝试一下它是否有效,如果有效,则尝试找出适合您的应用程序的最具体的节点。

The inputChanged() if the contentprovider shouldn't be called during refresh() - it is only called when a setInput() call is made to the tree viewer.

In worst case you could call setInput() with the original input to make your elements refreshed, but it can be too slow for your application.

Basically, when you add a new Node in the middle of the group, you have to refresh the parent node (the node who returns the added element using the getChildren() call), or one of its parents. Basically calling refresh() without any parameters might work for this reason.

So for testing, I suggest that you should call refresh() without any parameters, try, whether it works or not, and if it works, then try to figure out the most specific node that works with your application.

原野 2024-12-14 19:53:30

也许这对您来说是显而易见的,但是您是从 UI 线程调用刷新吗?具体尝试以下方法:

Display.getCurrent().asyncExec(new Runnable() {
    @Override
    public void run() {
      // TODO Call refresh() here
    }
});

还有一个syncExec()方法。

希望这有帮助!

Maybe this is obvious to you, but are you calling the refresh from the UI thread? Specifically try the following:

Display.getCurrent().asyncExec(new Runnable() {
    @Override
    public void run() {
      // TODO Call refresh() here
    }
});

There is also a syncExec() method.

Hope this helps!

默嘫て 2024-12-14 19:53:30

您是否在 TreeViewer 中应用了标签装饰器?

我刚刚在 TreeViewer 中编辑了一个条目,而没有之前应用的 LabelDecorator,并且 update(selectedItem, null) 实际上应用了更新(之前什么也没做)。

也许这是一个 jface 错误?

[编辑]似乎你必须使用 updateLabel()

Did you apply a label decorator to your TreeViewer?

I just edited an entry in my TreeViewer without the LabelDecorator I applied before and update(selectedItem, null) actually applied the update (it did nothing before).

Perhaps it's a jface bug?

[edit] seems you have to use updateLabel() from your DecoratingLabelProvider object.

無處可尋 2024-12-14 19:53:30

不幸的是,我找不到任何解决这个问题的方法。我最终关闭了文件并重新打开它以强制“刷新/更新”。谢谢大家的建议。

Unfortunately, nothing I could find resolved this. I ended up closing the file and reopening it to force a "refresh/update". Thanks all for the advice.

星星的軌跡 2024-12-14 19:53:30

对我来说,add()、update() 或remove() 函数工作得相当不错,当然手动这样做很烦人……但是如果你在更改时从模型中调用它们,它应该工作得很好。

For me the add(), update() or remove() functions worked pretty decent, of course it is annoying to do so manualy... but if you call them from your model on a change it should just work fine.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文