Eldad
Eldad

Reputation: 1059

Update only visible items in JFace TreeViewer

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?

Upvotes: 3

Views: 1574

Answers (1)

Eldad
Eldad

Reputation: 1059

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.

Upvotes: 1

Related Questions