Start of Content Area

Object documentation TreeNodeType API  Locate the document in its SAP Library structure

Definition

The TreeNodeType object describes a tree node type that, unlike the TreeItemType object, can contain additional tree nodes. They represent the nodes of the tree.

Description of Properties

·        expanded
Specifies whether or not a tree node can be collapsed or expanded. The binding of this property is not mandatory, however, we recommend the binding of the property to a context attribute. In this case, this context attribute must be contained in a context node to which the datasource property is bound. You can now specify the initial expansion status of the tree node.

·        hasChildren
Specifies whether or not a tree node has children. If you define an onLoadChildren event handler, the corresponding tree element is displayed as a tree node by default – that is, the tree element has an expansion symbol that can be used to expand or collapse the tree. If you know beforehand or during the LoadOnDemand that a tree element does not contain children, you can set the hasChildren property to false. The default value of this property is true. The tree element is then displayed as a leave without expansion symbol.

Note

The hasChildren property is only evaluated if no data for children of the corresponding tree element is available. Tree elements are always displayed as tree nodes if data for their children is available.

Overview of Inherited and Additional Properties

Name

Interface

Type

Initial Value

Bindable

Value Required

dataSource

IWDAbstractTreeNodeType

Object

 

bindable_mandatory

No

design

IWDAbstractTreeNodeType

WDTreeNodeDesign

standard

bindable

No

expanded

IWDTreeNodeType

boolean

false

bindable

No

hasChildren

IWDTreeNodeType

boolean

true

bindable

No

iconAlt

IWDAbstractTreeNodeType

String (TranslatableText)

 

bindable

No

iconSource

IWDAbstractTreeNodeType

String

 

bindable

No

ignoreAction

IWDAbstractTreeNodeType

boolean

false

bindable

No

text

IWDAbstractTreeNodeType

String (TranslatableText)

 

bindable

No

tooltip

IWDAbstractTreeNodeType

String (TranslatableText)

 

bindable

No

Events

·        onAction (String path)
Specifies the action that is executed when the user selects a node of this type.

·        onLoadChildren (String path)
Specifies the action that is executed when the data for a compressed tree node that initially has no children is read from the back end only if required. This requires the implementation of a corresponding event handler. At runtime, this event handler is called when a tree node without data for its children is expanded. The Web Dynpro application can use the event handler to read data for the children of the expanded tree node and add this data to the tree. The node element that corresponds to the expanded tree node is passed as an event parameter in the event handler to the Web Dynpro application. This requires a parameter mapping, so the Web Dynpro framework can execute the automatic type conversion from the type of the event parameter to the type of the event handler parameter. See Event Parameters and Parameter Mapping.

Note

The event handler of the event onLoadChildren is only triggered during the expansion if no data for the children of the expanded node exists. If the application adds data during the expansion, the event is not triggered when the tree node is opened again.

Parameter

Type

Description

path

String

Path of the context element to which the tree node that triggered this event corresponds.

Example of parameter mapping for the onLoadChildren event that passes the parameter element to the application:

Implementation of the view controller, context element, and parameter-mapping
The Web Dynpro application creates a parameter of the type of the node element whose context node is bound to the tree node. If the context node is, for example,
TreeLevel1 in the SAP NetWeaver Developer Studio, the Web Dynpro application chooses ITreeLevel1Element as the type of the parameter. This means that the ITreeLevel1Element represents an interface that extends IWDNodeElement.

This parameter can only be filled by the Web Dynpro framework if the application creates another parameter mapping. Since the parameter mapping is defined at UI element event level, the parameter mapping must be implemented in the doModifyView method of the controller implementation of the view. See the following code example:

//@@end

  public static void wdDoModifyView(IPrivateTreeView wdThis, IPrivateTreeView.IContextNode wdContext, com.sap.tc.webdynpro.progmodel.api.IWDView view, boolean firstTime)

  {

    //@@begin wdDoModifyView

    if(firstTime)

    {

      IWDTreeNodeType nodeType = (IWDTreeNodeType )view.getElement("NodeTypes_1");

      nodeType.mappingOfOnLoadChildren().addSourceMapping("path","element");

nodeType.mappingOfOnAction().addSourceMapping("path","selectedElement");

    }

    //@@end

  }

 

 

Caution

The name of the event parameter to which is mapped must correspond to the parameter of the event handler. In this example, the parameter is called element.

Implementation of the event handler onActionLoadChildren

The corresponding event handler of the onActionLoadChildren event has the following source code:

//@@begin javadoc:onActionLoadChildren(ServerEvent)

  /** declared validating event handler */

  //@@end

  public void onActionLoadChildren(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, com.sap.test.wdp.IPrivateTreeView.ITreeLevel1Element element )

  {

    //@@begin onActionLoadChildren(ServerEvent)

    int level = element.getLevel();

    if (level < 6){

       level++;

       for (int i = 0; i < 4; i++) {

         IPrivateTreeView.ITreeLevel1Element el = element.nodeRecNode().createTreeLevel1Element();

         el.setText("New Node on Level "+ level);

         el.setLevel(level);

         if (level == 6)

            el.setHasChildren(true);

          else

            el.setHasChildren(true);  

         element.nodeRecNode().addElement(el);

      }

    }

    //@@end

  }

 

 

Note

The same applies to the event onAction. Again, the application can define a parameter in the event handler that corresponds to the selected context element. A parameter mapping is also required (see above).

 

End of Content Area