Example 10: Tree

If you can't play the video, make sure that you are logged in at Wex Solutions.

This example showcases how to implement Tree-based entities in the Windchill UI.

You can find the code for the example in our GitHub repository.

Implementation

This example adds a standard JCA Windchill Tree with a Data Utility. The result looks like this:

1623876321721

The implementation consists of the following classes:

Class Extends Annotation Description
WexTreeBuilder AbstractConfigurableTableBuilder WexBean, WexComponent, ComponentBuilder This is the builder that constructs the table. It must be annotated so that it becomes visible as a Feature outside the extension.
WexTreeRow NmObject The is a POJO that is interrogated by reflection to create a row. The NmObject gives the table row a unique id
WexExampleTreeHandler TreeHandlerAdapter The data provider that will populate the tree
ExampleDataUtil AbstractDataUtility WexDataUtility The code that populates a cell in the tree. Can be text of a graphical element such as an Icon

The WexTreeBuilder implementation has a ComponentBuilder annotation:

@WexBean("com.wincomplm.wex-example-tree.wextree")
@WexComponent(uid = "com.wincomplm.wex-example-tree.wextree", description = "Wex Example Tree")
@ComponentBuilder("com.wincomplm.wex-example-tree.wextree")
public class WexTreeBuilder extends AbstractConfigurableTableBuilder {

The Builder is implemented as follows:

@Override
public ComponentConfig buildComponentConfig(ComponentParams cp) throws WTException {
    logger.trace("=>buildComponentConfig {0}", cp);
    ComponentConfigFactory factory = getComponentConfigFactory();
    TreeConfig tree = factory.newTreeConfig();
    tree.setLabel("Example Tree");
    ColumnConfig col = factory.newColumnConfig("wex-example-tree-data", true);
    col.setLabel("Data");
    tree.addComponent(col);
    tree.setFindInTableMode(FindInTableMode.CLIENT_ONLY);
    ((JcaTreeConfig) tree).setExpansionLevel(TableTreeProperties.ONE_EXPAND);
    tree.setShowTreeLines(true);
    tree.setShowCustomViewLink(false);
    logger.trace("<=buildComponentConfig");
    return tree;
}//buildComponentConfig

@Override
public Object buildComponentData(ComponentConfig cc, ComponentParams cp) throws Exception {
    logger.trace("=>buildComponentData {0} {1}", cc, cp);
    WexExampleTreeHandler handler =  WexExampleTreeHandler.newWexExampleTreeHandler();
    logger.trace("<=buildComponentData");
    return handler;
}//buildComponentData

This class uses wex-example-tree-data ID for the data utility, implemented by the class:

@WexDataUtility("wex-example-tree-data")
@WexComponent(uid = "wex-example-tree-data", description = "Data")
public class ExampleDataUtil extends AbstractDataUtility {
    @Override
    public Object getDataValue(String string, Object o, ModelContext mc) throws WTException {
        if (!(o instanceof WexTreeRow)) {
            return null;
        }
        return ((WexTreeRow) o).getData();
    }
}

Like we saw in the Table example, the WexTreeRow implementation has a POJO with getters:

public String getData() 

As a table requires a unique ID for each element, the row must implement NmObject and this will be returned in the Component Builder. These methods can also return objects that inherit from com.ptc.core.components.rendering.guicomponents.HTMLGuiComponent

Execution

Access the new entry in the Quick Links menu:

1623875572026

The Tree will appear as follows:

1623876321721