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

Overview

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)

If you add more than one column to table, only the first column will be a tree. The rest will represent other data for the tree nodes. This is achieved by calling the addColumn() method as many times as required:

IEpTreeColumn addColumn(String headerText, int initialWidth)

The interface IEpTreeColumn allows for setting the label provider and editing support 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.

Example

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

            com.elasticpath.cmclient.admin.users/src/main/java/com/elasticpath/cmclient/admin/users/wizards/RolePermissionsDualListbox.java
//
// 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, call setInput() as follows:

availableEpTreeViewer.setInput(getAvailable());