Label and Content Providers for JFace TreeViewer

Label and Content Providers for JFace TreeViewer

The JFace library offers some widgets, called viewers, that can represent a data model. What are they for? Let’s suppose you want to show a table, a tree or a combo in order to visualize a list of objects or a hierarchical structure 클로버 다운로드. You could certainly make use of basic widgets like Table, Tree or Combo, but they are usually not a good choice 굿바이평양 다운로드.
Imagine you while filling a table, row by row, starting from a list of Orders and your focus is doing some action with the Order that the user selected vmware 14 pro.
With a Table widget you have to find a trick like counting on a key value on a certain column, or keep an Order list with the same sequence showed on the table and extract by index on a positional basis from the index of selected row Three Kingdoms 10pk.
Further, just populating the table would be quite a heavy task.

Thanks to JFace viewers, it is possible to set up some sort of “binding” between the widget and the model itself 포토샵 도형 다운로드. This allows, for instance, retrieving directly the selected Order object (instead of the index of selected row). This binding is performed by using a couple of providers :

– Label provider and
– Content provider

Here are some notes about the usage of these providers with JFace Viewers Three Kingdoms 13 Hangul Patch. In particular we’ll focus on TreeViewer.
The Model is made of Company entity, which owns a collection of Departments, which in turn owns a collection of Employees php sftp file.
The goal is to obtain this

The Viewer will receive a list of Company objects ez spc 다운로드. The code that set up the input and that set the providers is the following:

Let’s examine now these providers role:

  • LabelProvider: it is invoked to determine what to show (text and image) for each node that come into view macbook iCloud photos. The method getText() receives the examined object and must return the text to show. The optional method getImage() can be used to supply an image Iris 2. Here is a possible implementation for our use-case:

  • ContentProvider: it handles the content of the widget. In particular it provides the implementation of the methods that are called when:
    1. when the tree viewer is first shown (with first-level nodes not expanded) (getElements)
    2. when it is required to decide if expansion symbol has to be shown (hasChildren)
    3. when the user choose to expand a node and its children has to be shown (getChildren)

Please note that hasChildren, but also especially getChildren, gets called with a lazy mechanism, that is only when that’s required. As a result, the Employee list of a given Department gets loaded just when the user choose to expand that Department node, not before, with a clear good impact on performances.

The tree shows then all three object’s level (Company, Deparment, Employee)


Note: should the viewer be fed with a single Company object instead of a list, the getElements() method has to be changed like this:

In this case the tree will not show the Company object; instead it will show its children Department (at first level) and the Employee objects (at second level).



By |2012-06-08T11:51:48+00:00August 7th, 2011|


  1. Ram Friday October 12th, 2012 at 05:40 AM - Reply

    Please I Implemented TreeViewer in my application but 3 views are not visible. Juno ide,eclipse rcp.

  2. vivek Monday November 25th, 2013 at 03:58 AM - Reply

    Nice article. I have also written one article on Jface Treee Viewer –

  3. sushma Monday June 1st, 2020 at 04:49 AM - Reply

    Good article. Really helpful

Leave A Comment