Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

Tree Viewer

Tree Viewer


EP tree viewer represents data in a tree-table like structured way using the Eclipse's TreeViewer JFace component.

How to use it

Like all the other components it can be created through the IEpLayoutComposite instance or the EpControlFactory:

IEpTreeViewer addTreeViewer(boolean multiSelection, EpState epState, IEpLayoutData data)
IEpTreeViewer createTreeViewer(Composite parentComposite, boolean multiSelection, EpState epState)

There is possibility to add more than one columns which means that only the first column would be a tree and the rest would represent some other data for the tree nodes. This can be achieved by calling multiple times this method on IEpTreeViewer instance:

IEpTreeColumn addColumn(String headerText, int initialWidth)

The interface IEpTreeColumn allows setting label provider and editing supprot to the column.

The major difference with the table viewer is the content provider type. It has to be an instance of IStructuredContentProvider. This interface allows defining the tree and all its nodes. Implementing this interface and setting it to a tree viewer is followed by setting the input object. It has to be a collective object that will be able to return the root elements of the tree. This object is then passed to the structured content provider that has to cast the object and extract the root elements in getElements(Object inputObject) and return them as an array. In getChildren(Object treeNode) one should expect to receive the root elements returned on getElements(...) and all the children returned by previous calls to getChildren(...) method. That way all tree nodes should be visited and the tree created.


This example is an extract from RolePermissionsDualListbox. This class is responsible for the defining role permissions when creating a new role in Configuration activity (User Roles). Adding the tree and setting the content and label providers defines the tree view.

// Second Row
// List box
availableEpTreeViewer = controlPane.addTreeViewer(true, EpState.READ_ONLY, fillData);

availableEpTreeViewer.setContentProvider(new AvailablePermissionsContentProvider());
availableEpTreeViewer.setLabelProvider(new AvailablePermissionsLabelProvider());
availableEpTreeViewer.getSwtTreeViewer().setSorter(new PermissionsNodeSorter());

For populating the tree in populateControls we would call: