Skip to main content



      Home
Home » Eclipse Projects » JFace » Observe elements to update labels in TreeViewer
Observe elements to update labels in TreeViewer [message #5050] Thu, 14 May 2009 10:55 Go to next message
Eclipse UserFriend
Originally posted by: gaston.tonietti.teracode.com

Hi all,

I'm using a TreeViewer to show my model in an hierarchical way. Every object in my model is a Java Bean, so they all implement
PropertyChangeSupport.

My question is:
How can I hook the proper listeners for changes in certain properties of my model objects in the way it triggers a label update in the
tree for modified elements?

I know it can be addressed with ViewerSupport but I cannot use it as I'm already using Workbench content and label providers this way:

this.viewer = new TreeViewer(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL);

this.viewer.setContentProvider(new BaseWorkbenchContentProvider());

ILabelProvider labelProvider = WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider() ;
this.viewer.setLabelProvider(labelProvider);

this.viewer.setInput(myModelRoot);

I've noticed that a listener for the label provider is already registered but I cannot make the label provider to fire the event when a
property changes in any of the shown elements. I tried with isLabelProperty(..) method but it didn't work.


Thanks a lot!
Gaston.
Re: Observe elements to update labels in TreeViewer [message #6110 is a reply to message #5050] Fri, 15 May 2009 13:37 Go to previous message
Eclipse UserFriend
Hi Gaston,

There is no easy way to do this - you will have to hook listeners yourself,
for example from a subclass of WorkbenchLabelProvider, and call its
fireLabelProviderChanged method when labels need to be updated. This will
notify the viewer about label changes to the elements referenced from the
LabelProviderChangedEvent you pass in. The challenge will be to know which
bean objects to attach listeners to (and when to de-attach listeners) - this
is much easier with a content provider from the data binding framework
because it can tell you which elements are materialized in the viewer - see
for example ObservableListContentProvider.getKnownElements().

Boris

"Gaston M. Tonietti" <gaston.tonietti@teracode.com> wrote in message
news:guhbc6$g28$1@build.eclipse.org...
> Hi all,
>
> I'm using a TreeViewer to show my model in an hierarchical way. Every
> object in my model is a Java Bean, so they all implement
> PropertyChangeSupport.
>
> My question is:
> How can I hook the proper listeners for changes in certain properties of
> my model objects in the way it triggers a label update in the
> tree for modified elements?
>
> I know it can be addressed with ViewerSupport but I cannot use it as I'm
> already using Workbench content and label providers this way:
>
> this.viewer = new TreeViewer(parent, SWT.BORDER | SWT.MULTI | SWT.H_SCROLL
> | SWT.V_SCROLL);
>
> this.viewer.setContentProvider(new BaseWorkbenchContentProvider());
>
> ILabelProvider labelProvider =
> WorkbenchLabelProvider.getDecoratingWorkbenchLabelProvider() ;
> this.viewer.setLabelProvider(labelProvider);
>
> this.viewer.setInput(myModelRoot);
>
> I've noticed that a listener for the label provider is already registered
> but I cannot make the label provider to fire the event when a
> property changes in any of the shown elements. I tried with
> isLabelProperty(..) method but it didn't work.
>
>
> Thanks a lot!
> Gaston.
>
Previous Topic:Form.setMessage question
Next Topic:problem creating tableviewer on the wizardpage
Goto Forum:
  


Current Time: Wed May 07 17:18:33 EDT 2025

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

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

Back to the top