Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Optimize TreeViewer refresh()
Optimize TreeViewer refresh() [message #557513] Tue, 07 September 2010 22:11 Go to next message
Nicolas  is currently offline Nicolas Friend
Messages: 6
Registered: August 2010
Junior Member
Hello All,

I have a JFace TreeViewer that displays a lot of elements (2000 or so) directly depending on the root. I want to be able to add a new child to the root, and move approximately 100 elements from the root to this new child. It takes several seconds for the treeViewer to refresh, using the refresh(false) method.

Is there an efficient way to refresh the tree using MVC or should I use the underlying SWT class? In this case, is it safe to make modifications mixing MVC mechanisms and direct accesses to the SWT class?

Any help would be nice.

Best,
Re: Optimize TreeViewer refresh() [message #628734 is a reply to message #557513] Thu, 23 September 2010 20:09 Go to previous messageGo to next message
Federico Gaule is currently offline Federico GauleFriend
Messages: 21
Registered: September 2010
Location: Buenos Aires, Argentina
Junior Member
Hi.

Take a look at TreeViewer#update(Object element, String[] properties) method. Where element is the parent of your new child, and properties are the names of the properties affected. i.e. this.treeViewer.update(rootNode, new String[]{"name"}) where "name" is used by the LabelProvider.

This method is much more efficient than the refresh.

Re: Optimize TreeViewer refresh() [message #628788 is a reply to message #557513] Fri, 24 September 2010 07:34 Go to previous messageGo to next message
Nicolas  is currently offline Nicolas Friend
Messages: 6
Registered: August 2010
Junior Member
Thank you, but the update method cannot handle structural changes, such as addition or removal of children.
Re: Optimize TreeViewer refresh() [message #628812 is a reply to message #557513] Fri, 24 September 2010 09:01 Go to previous messageGo to next message
Daniel Krügler is currently offline Daniel KrüglerFriend
Messages: 853
Registered: July 2009
Senior Member
On 08.09.2010 00:11, Nicolas wrote:
> Hello All,
>
> I have a JFace TreeViewer that displays a lot of elements (2000 or so)
> directly depending on the root. I want to be able to add a new child to
> the root, and move approximately 100 elements from the root to this new
> child. It takes several seconds for the treeViewer to refresh, using the
> refresh(false) method.
>
> Is there an efficient way to refresh the tree using MVC or should I use
> the underlying SWT class? In this case, is it safe to make modifications
> mixing MVC mechanisms and direct accesses to the SWT class?
>
> Any help would be nice.

It sounds as if you are modifying the tree via the Viewer operations, is
that correct? I would modify your model and would after the complete
change I would require a single viewer.refresh call.

If you need to perform some viewer-related actions within a single
block, you can optimize that by wrapping the code in a block sourrounded
with

getViewer().getControl().setRedraw(false);
try {
// Operations
} finally {
getViewer().getControl().setRedraw(true);
}

HTH & Greetings from Bremen,

Daniel Krügler
Re: Optimize TreeViewer refresh() [message #628885 is a reply to message #628788] Fri, 24 September 2010 15:26 Go to previous messageGo to next message
Federico Gaule is currently offline Federico GauleFriend
Messages: 21
Registered: September 2010
Location: Buenos Aires, Argentina
Junior Member
Using
IObservableFactory observableFactory = BeansObservables.setFactory(Realm.getDefault(), "children", TreeNode.class);
this.viewer.setContentProvider(new ObservableSetTreeContentProvider(observableFactory, null));

and firing "children" property, you will get the TreeViewer#add method called. There is where you can call the #update.
I use this approach in my Problem View and works perfectly.
Re: Optimize TreeViewer refresh() [message #628899 is a reply to message #557513] Fri, 24 September 2010 16:27 Go to previous messageGo to next message
Nicolas  is currently offline Nicolas Friend
Messages: 6
Registered: August 2010
Junior Member

Thank you for both answers: I will try and combine your advices.

Best,
Re: Optimize TreeViewer refresh() [message #629169 is a reply to message #557513] Mon, 27 September 2010 12:07 Go to previous messageGo to next message
Dani Megert is currently offline Dani MegertFriend
Messages: 3802
Registered: July 2009
Senior Member
Nicolas wrote:
> Hello All,
>
> I have a JFace TreeViewer that displays a lot of elements (2000 or so)
> directly depending on the root. I want to be able to add a new child
> to the root, and move approximately 100 elements from the root to this
> new child. It takes several seconds for the treeViewer to refresh,
> using the refresh(false) method.
>
> Is there an efficient way to refresh the tree using MVC or should I
> use the underlying SWT class? In this case, is it safe to make
> modifications mixing MVC mechanisms and direct accesses to the SWT class?
You should consider using a virtual tree, see org.eclipse.swt.SWT.VIRTUAL.

Dani
>
> Any help would be nice.
>
> Best,
Re: Optimize TreeViewer refresh() [message #629940 is a reply to message #629169] Thu, 30 September 2010 05:21 Go to previous message
Nicolas  is currently offline Nicolas Friend
Messages: 6
Registered: August 2010
Junior Member
Dani Megert wrote on Mon, 27 September 2010 08:07

You should consider using a virtual tree, see org.eclipse.swt.SWT.VIRTUAL.



It seems that I cannot: I need sorting capabilities and the virtual version of the treeviewer does not support them (I think)
Previous Topic:Context menu for table viewer
Next Topic:Job progress popup behavior change from eclipse 3.5 to 3.6 ?
Goto Forum:
  


Current Time: Wed Apr 24 21:59:23 GMT 2024

Powered by FUDForum. Page generated in 0.03559 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top