[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform] Re: Does jface databinding support treeviewer?

hao wrote:
The input is contentProvider.getKnownElements().
I do not see the elements returned by contentProvider.getKnownElements() are used in the implementation of PersonGroupLabelProvider. It looks like the PersonGroupLabelProvider has not relation with the content provider at all.

contentProvider.getKnownElements is passed to the ListeningLabelProvider constructor. If you look at the code in that constructor, you will see that it is calling addListenerTo for each element in the set. It also adds an ISetChangeListener to the set so that future additions / removals in the set will result in a call to addListenerTo() / removeListenerFrom(), respectively.


This is useful because the set of known elements tells the label provider exactly what elements are in the viewer. The label provider in turn adds property change listeners (in the case of beans) to every element in the set, so that when those properties change it can update the labels in the viewer. This is the point of the known elements set.

You need to implement ITableLabelProvider so that the tree viewer will
recognize that your label provider supports columns.
Why does PersonGroupLabelProvider need to extends ListeneingLabelProvider? Is only implementing ITableLabelProvider enough?


Your explanation is very helpful. Thanks a lot.

Hao


The DataBinding label providers automatically take care of updating labels in the viewer when the underlying model changes. You could certainly implement ITableLabelProvider directly, but then you have to take care of all these details manually. In this case, subclassing ListeningLabelProvider is convenient because there is already API for monitoring the known elements set and there is a clear way to be notified of added and removed elements (addListenerTo / removeListenerFrom).


Matthew