Control : Tree
The Tree control enables you to display data in a hierarchical way.

Contents |
Overview
The most common use of the Tree control is to display as elements in a tree, objects with fields that are themselves collections of other objects. A common practice is to bind the Tree control to the this field of the object containing the form in which the Tree control appears. This has the effect of making that object the top level object in the tree. The top level object can be used as a parent node in the Tree control if that object contains a collection field. (The Show Root property on the Styles tab of the Property Editor controls whether or not the top node in the Tree control or just its children are initially visible.) Child object items within the collection field can also become parents if they themselves contain a collection field that you want to represent inside the Tree control.
You can present any number of kinds of types within the tree. It is important to note that you must implement a TreeElementAdapter on every type you intend to be displayed in the Tree control. The TreeElementAdapter contains many fields that allow you to control the look and feel of the tree at every level. For example, you can implement a TreeElementAdapter on a particular object type so that the children of that object type are actually computed during the element adapter invocation (along with sorting, web service calls, computed objects, etc.). In addition, the expand feature on each node is also controlled by the TreeElementAdapter. There are many control mechanisms that allow you to greatly customize the control's interaction. These mechanisms are shown in the examples below, as well as in the details of the TreeElementAdapter documentation.
Capabilities
Use the Tree control to:
-
Display a hierarchy of objects in an expandable tree (Example 1)
-
Enable editing of items in a tree (Example 2)
Limitations
- Cannot display primitive items in a tree, unless the items are a collection of primitive items
Requirements
The Tree control requires you to use both interfaces and adapters. Two interfaces (TreeInterface and TreeElementInterface) are provided by default through the properties available on the Interface tab of the Property Editor. You add adapters to classes in your project as needed.
In order to make the Tree control functional on the most basic level, you must:
- Add a TreeElementAdapter to each of the types you want to display as elements within the tree.
- Use the TreeAdapterto enable control over the selection of items displayed in a Tree control. You use a TreeAdapter to set initial selection in the control, as well as to respond to end-user selection of items in a tree.
To see how to use the control, import Tree control (under controls) into the Builder and inspect the various types in the project. You should then be able to see the types of things you need to do in your own solution to achieve the various functionalities available with this control.
Examples
The following examples are intended to be used with sample code that you can import into your Bungee Builder workspace from the Start Page. Each example is intended to build upon the previous example to provide you with a complete understanding of how to use this control.
Example 1: Various Objects in a Tree Control (Ex1_Industry)
You can have various types of objects represented in a tree control. This example shows how each of the several types (Industry, Company, Department, and Employee) must have a "hasa" relationship of a collection of the next lower type in the hierarchy in order for the Tree control to be able to expand to the depth of each succeeding level in the Tree. In addition, each object in the hierarchy must implement a TreeElementAdapter to control how each element in the tree gets displayed. Because the Tree control is bound to the this field of the Ex1_Industry class, Ex1_Industry must also implement its own TreeElementAdapter.
Example 2: Editing in a Tree Control (Ex2_EditIndustry)
You can add the ability to edit within the Tree control. This example adds buttons for removing, adding, and showing elements in the tree. All the elements inherit from Item, which defines the common operations. However, completely different and unrelated types can exist in a tree, in which case, each item would need to handle its own operations, like remove, inspect, new, etc.
Example Helper Classes
Item
Contains five functions:
- addNew
- addNewToCollection
- remove
- removeSelected
- showDetail
Also contains two forms:
- ParentToolbar
- Toolbar
Industry
"Isa" Item, "Hasa" collection of Company (companies). Contains a string name, and two overridden functions: addNew, remove. Also implements a TreeElementAdapter.
Company
"Isa" Item, "Hasa" collection of Department (departments). Contains a string name, and two overridden functions: addNew, remove. Also implements a TreeElementAdapter.
Department
"Isa" Item, "Hasa" collection of Employee (employees). Contains a string name, and two overridden functions: addNew, remove. Also implements a TreeElementAdapter.
Employee
"Isa" Item, contains three strings:
- firstName
- lastName
- title
Also contains two forms:
- Detail
- Toolbar
and implements a TreeElementAdapter.
Reference
Supported Types (Control Interface)
| Type | Summary |
|---|---|
| Object | Any object defined in Bungee Connect can be tied to the Tree control. |
Default Interfaces
| Type | Summary |
|---|---|
| TreeInterface | Provides selection control for the Tree. Enables the Tree control to respond to selection by end-users as well as providing a way to set initial selection when bound to an application object. |
| TreeElementInterface | Used to set the label for each item in the Tree. |
Adapters
| Type | Summary |
|---|---|
| TreeAdapter | Enables control over the selection of items displayed in a Tree control. You use a TreeAdapter to set initial selection in the control, as well as to respond to end-user selection of items in a tree. |
| TreeElementAdapter | Provides the text that appears as a label for each item in a Tree control you have bound to a collection. You add the adapter by clicking Bind Label on the Tree control. This binds the label that appears in the Tree control to the application object that is the type of the items stored in the collection. |
Associated Properties
Specialized Properties
- Allow Remove
- Close On Double Click
- Delimiter
- Drop On Node Only
- Element
- Expand On Double Click
- Expand State
- Fire Double Click
- Icon Height
- Icon Width
- Label As Path
- Remove
- Select On Expand
- Show Expand
- Show Lines
- Show Root
- Use Collection for Select
- Use Parent For Right Click
Unique Properties
- None



