只更新JFace TreeViewer中的可见项

时间:2022-07-12 22:22:53

I implemented an Eclipse plugin that displays data in a TreeViewer.

我实现了一个Eclipse插件,它在TreeViewer中显示数据。

The tree structure is read on initialization and will not change in runtime. A LabelProvider is used to set the data to display for each item. This object does this by reading from our hardware. Reading a value can take up some time (~0.5sec). Updating values is done every time the debugger pauses and every time the user clicks a designated 'refresh' button.

树结构在初始化时读取,在运行时不会改变。标签提供程序用于设置显示每个条目的数据。这个对象通过读取我们的硬件来实现这一点。读取一个值可以花费一些时间(~0.5秒)。每次调试器暂停和每次用户单击指定的“refresh”按钮时都要更新值。

I have many items and sub items so reading all of the values at once is too time consuming. Therefore, I only want to read the data of items that are visible to the user.

我有很多项和子项,所以一次读取所有的值太浪费时间了。因此,我只想读取用户可见的项目的数据。

I tried using ILazyTreeContentProvider but this only saves time when the tree loads: After scrolling or expanding a TreeItem, the visible items are added to the list of items to update instead of replacing the invisible nodes.

我尝试使用ILazyTreeContentProvider,但这只在树加载时节省了时间:在滚动或扩展TreeItem之后,可以将可见项添加到要更新的项目列表中,而不是替换看不到的节点。

How can I accomplish this?

我怎样才能做到这一点呢?

1 个解决方案

#1


1  

Found it!

发现它!

I'm still using the ILazyTreeContentProvider. Every time the debugger stops or the refresh button is clicked, instead of checking which element to refresh, I simply delete all of the elements using tree.clearAll(true). The deletion will call the ILazyTreeContentProviderto do its job again only on the visible items.

我还在使用ILazyTreeContentProvider。每次调试器停止或刷新按钮被单击时,我不是检查要刷新的元素,而是使用tree.clearAll(true)删除所有元素。删除将调用ilazytreecontentderto只在可见项目上再次执行它的工作。

#1


1  

Found it!

发现它!

I'm still using the ILazyTreeContentProvider. Every time the debugger stops or the refresh button is clicked, instead of checking which element to refresh, I simply delete all of the elements using tree.clearAll(true). The deletion will call the ILazyTreeContentProviderto do its job again only on the visible items.

我还在使用ILazyTreeContentProvider。每次调试器停止或刷新按钮被单击时,我不是检查要刷新的元素,而是使用tree.clearAll(true)删除所有元素。删除将调用ilazytreecontentderto只在可见项目上再次执行它的工作。