in my code I have a TreeViewer that is refreshed by periodically calling setInput() and passing the new input. Due to the complexity of the rest of the system I would prefer not to change the code to work with with add, remove and refresh. Unfortunately this means that the scrollbar jumps up to the top every second or so. Is there a way to preserve the scrollbar position and set it again after the refresh, even if no element is selected?
I already tried doing
int s = treeViewer.getTree().getVerticalBar().getSelection();
treeViewer.setInput(input);
treeViewer.getTree().getVerticalBar().setSelection(s);
But I guess that would only work if an item was selected.