Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Update only visible items in JFace TreeViewer

Tags:

java

swt

jface

I implemented an Eclipse plugin that displays data in a 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.

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.

How can I accomplish this?

like image 296
Eldad Avatar asked Dec 04 '25 00:12

Eldad


1 Answers

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.

like image 101
Eldad Avatar answered Dec 06 '25 15:12

Eldad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!