Load On Demand and JViews TGO Tree Component

The tree component is one of the four graphic components supplied with ILOG JViews TGO. It provides a hierarchical view of the data contained in a data source. A tree has one or more root nodes, from which all the other nodes descend.

JViews TGO Tree Component Each tree node is associated with a business object (for example, a managed object, an alarm, or a service). The tree component is connected to a data source, from which it retrieves the business objects to be displayed. By default, the tree displays all the objects contained in the data source.

However, it is possible to restrict the contents displayed by:

  • selecting the root nodes to be shown,
  • specifying whether certain child objects should be visible or not,
  • applying a filter.

Objects that do not have a parent are displayed as root nodes, while the others are displayed under their parent.

The example below illustrates how you create and connect a data source to a tree component:

IlpTree treeComponent = new IlpTree();
IltDefaultDataSource dataSource = new IltDefaultDataSource();
treeComponent.setDataSource(dataSource);

Load on Demand at View level

The tree component supports load on demand for the business objects to be displayed. This means that the graphic representation of a given business object is only created when its parent object is expanded through the API or through user interaction. By default, load on demand is customized through the CSS property expansion, which should be applied to the tree configuration. The extract below illustrates how you can specify whether the objects of a certain business class should be handled when they are expanded:

object."ilog.tgo.model.IltCard" {
  expansion: NO_EXPANSION;
}

The following extract illustrates the same feature for a single business object:

Subobject#NE2 {
  expansion: IN_PLACE_MINIMAL_LOADING;
}

The expansion property may have 3 different values in the Tree component:

  • NO_EXPANSION: the children objects will not be considered by the tree component, therefore they will not be visible.
  • IN_PLACE_MINIMAL_LOADING: Loads the child objects on demand, as the user expands the parent object. All nodes with this expansion strategy are considered as possible parent nodes, and therefore are represented with an expansion icon. If a tree node does not contain child objects, the expansion icon disappears when the expansion is executed the first time.
  • IN_PLACE: Loads the child objects automatically in the graphic component. The child objects are loaded on demand, as the user expands the parent node.

The Tree adapter is the component that is responsible for understanding and handling the expansion mechanism in the Tree component. Modifying the expansion configuration can be achieved through API or using cascading style sheets.

IlpAbstractTreeAdapter adapter = treeComponent.getAdapter();
adapter.setStyleSheets(1, "adapterConfiguration.css");

or

adapter.setExpansionType(businessObject, IlpExpansionType.NO_EXPANSION);

The preferred mechanism to implement load on demand at the Tree component is to specify the tree node configuration with expansion type as IN_PLACE_MINIMAL_LOADING. With this configuration the object is displayed in the tree as a possible parent, with the expansion icon visible. When the user clicks the node to expand it, the information about its children objects is queried at the data source level. If there are children objects available, they will be created and displayed to the user. Otherwise, the expansion icon is made invisible to indicate that there are no children objects to be displayed.

Once this type of expansion is configured at the Tree component level, a second level of load on demand can be implemented at Data Source level. In this case, the objects are only added to the data source when they are queried for the first time.

Load on Demand at Data Source level

In order to implement load on demand at data source level, you will have to subclass the data source implementation to specify your own container and child interfaces that are used to create the parent-children relationship among the objects.

In ILOG JViews TGO distribution, sample ILOG JViews TGO Sample: Data Source - Custom Business Classes is provided to illustrate how to implement load on demand at data source level.

In a nutshell, you will have to subclass IltDefaultDataSource and specify your own implementation of methods:

  • IlpContainer getContainerInterface(Object idOrIlpObject)
  • IlpChild getChildInterface(Object idOrIlpObject)

Interface IlpContainer specifies how an object retrieves the list of children objects. IlpChild specifies how an object retrieve its parent object. Together these interfaces are used to establish the parent-child relationship needed to display the hierarchical structure in the Tree component. When implementing load on demand at data source level, these interfaces should be implemented in such a way that the children objects are only loaded at the data source, when method Collection getChildren(IlpObject object) is called.

By specifying the expansion configuration at the Tree adapter component and implementing load on demand at the data source level, you are configuring your tree component in such a way that the objects are only loaded in the data source and in the view, when first queried by the user through a tree node expansion.

Releasing Objects from the Tree

Once all nodes have been expanded and loaded into the component, it is also possible to release the nodes which are no longer needed. The JViews TGO Tree component already provides all the elements to support this feature. You will only need to indicate to the tree component when the tree node children can be released.

The example below illustrates how you can release children objects when a certain tree node is collapsed by the user. In this case, the children objects are released when the tree node is at the third level or below in the tree hierarchy. Other strategies can be implemented according to your application needs.

treeComponent.getView().addTreeExpansionListener(new TreeExpansionListener() {
  /**
   * Called whenever an item in the tree has been expanded.
   */
  public void treeExpanded(TreeExpansionEvent event) {
    // Do nothing
  }

  /**
   * Called whenever an item in the tree has been collapsed.
   */
  public void treeCollapsed(TreeExpansionEvent event) {
    TreePath path = event.getPath();
    Object pathElement =  path.getLastPathComponent();
    if (pathElement instanceof IlpTreeNode) {
      if (path.getPathCount() >= 2) {
        IlpTreeNode treeNode = (IlpTreeNode)pathElement;
        IlpExpansionStrategy strategy = treeNode.getExpansionStrategy();
        strategy.releaseChildren(treeNode);
      }
    }
  }
});

In this post, you have been introduced to the load on demand techniques available for the JViews TGO Tree component. An equivalent feature exists on the Network and Equipment components, which display topological views for network and equipment configurations.

Share and Enjoy: These icons link to social bookmarking sites where readers can share and discover new web pages.
  • Digg
  • del.icio.us
  • Netvouz
  • DZone
  • ThisNext
  • MisterWong
  • Wists

Tags: , ,

Leave a Reply