cancel
Showing results for 
Search instead for 
Did you mean: 

Multiselection in Tree by nesting table column

Former Member
0 Kudos

Hello!

I use the tutorial Tree by nesting table column posted on the Tutorial and Sample code section of SAP.

I try to do multiselection of multiple row in the tree table but it is not successful. I try to change the selectionMode attribute of the table to be multi but it is not working still. I also have try to change the selection attribute of the context and it is not working either. It is a bug when you use the TreeTable UI that you can't have multiselection? Does anyone have a solution for this? Please let me know. Point will be reward.

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

Hello! Bertrams

1)What actions in the UI should be assigned to call the onActionMultiSelect(). Or how should i use this function or call this function.

2)What is setSelectedLines() in your code does? is it a context attribute of the wdContext node?

3)Let say i can get the list of all the selected element, how do i highlight or indicate that row in the table is selected. It is like in the normal multiselection row in normal table. When you select multiple row, those row get highlighted. How i do that in the Tree table.

4)When you are doing multiselection on the table. you have to click ctrl+ the checkbox on the the 1st column of the table. How do we capture that action so that we can set selected attribute in the table for that.

Please let me know. Thank you very much.

Message was edited by: Khanh Nguyen

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hallo Khanh,

1.) To trigger multi selection on the UI I just added a Button to the table toolbar and bound it to the Action MultiSelect. This action event is than handled within onActionMultiSelect().

2.) setSelectedLines() is a context attribute setter which writes the return value of the private helper method selectedElementsToString() to a context attribute with name SelectedLines. I just did it to "see" the multi-selected lines as text on the UI. I bound a TextViewUIElement to the context attribute SelectedLines.

3. and 4.) Sorry, but I cannt really understand your problem here.

Set the table's <i>selectionMode</i>-property to <i>auto</i>.

Then you can mark multiple lines as multi-selected by just pressing the selection buttons within the first table column while pressing the STRG-key.

Afterwards you trigger a server roundtrip by pressing a table toolbar button (see my first point).

You can then retreive the selected node elements by implementing my sample code within the previous post.

Regards, Bertram

BeGanz
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hallo Khanh,

multi-selection of table lines based on the TreeByNestingTableColumn UI element is only supported in NW 04s. But even in this minor release there is no simple generic API to directly get the list of all multi-selected table lines. You know that these lines correspond to the related node element objects within a recursive context tree strcture.

As the Web Dynpro context API does not provide a simple method to get this list you have to implement your own custom coding.

A solution for this problem which is based on the tutorial sample application https://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/38650ecd-0401-0010-10a0-f9d8fd37edee could look like this:

<b>Action Event handler:</b>

//@@begin javadoc:onActionMultiSelect(ServerEvent)
  /** Declared validating event handler. */
  //@@end
  public void onActionMultiSelect(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionMultiSelect(ServerEvent)

    Collection list =
      TreeInTableHelper.getMultiSelectedElements(
        wdContext.nodeCatalogEntries(),
        wdContext.nodeCatalogEntries().nodeChildCatalogEntries(0),
        IPrivateTreeTableView.ICatalogEntriesElement.EXPANDED);

    wdContext.currentContextElement().setSelectedLines(this.selectedElementsToString(list));

    //@@end
  }

<b>Own Helper class TreeInTableHelper.java:</b>

package com.sap.tut.wd.treetable.util;
import java.util.ArrayList;
import java.util.Collection;
import com.sap.tc.webdynpro.progmodel.api.IWDAttributeInfo;
import com.sap.tc.webdynpro.progmodel.api.IWDNode;
import com.sap.tc.webdynpro.progmodel.api.IWDNodeElement;

/**
 * Helper class that returns a list of all selected lines within a TreeByNestingTableColumn.
 */
public final class TreeInTableHelper {

  /**
   * This method must be called from the event handler of this table sorter's
   * sort action. It performs the actual sort operation.
   */
  public static Collection getMultiSelectedElements(
    IWDNode dataNode,
    IWDNode childNode,
    String isExpandedAttributeName) {

    isExpandedAttrName = isExpandedAttributeName;
    selectionList = new ArrayList();
    if (dataNode.isEmpty())
      return null;
    dataNodeName = dataNode.getNodeInfo().getName();
    childNodeName = childNode.getNodeInfo().getName();
    traverseRecursiveNode(dataNode);
    return selectionList;
  }

  /**
   * Recursively traverse the context tree under the given node.
   * All multiselected elements are added to a ArrayList. 
   */
  private static void traverseRecursiveNode(IWDNode node) {
    for (int i = 0; i < node.size(); i++) {
      nodeElement = node.getElementAt(i);
      if (node.isMultiSelected(i))
        selectionList.add(nodeElement);

      // only traverse recursive node, this means go into the the non-singleton child node
      // of the current node element, in case this node element is expanded. 
      if (Boolean.TRUE.equals(nodeElement.getAttributeValue(isExpandedAttrName)))
        traverseRecursiveNode(node.getChildNode(childNodeName, i));
    }
    return;
  }

  /**
   * Name of the attribute used for comparisons.
   */
  private static Collection selectionList;

  /**
   * Member variable for a node element within a recursive context tree
   */
  private static IWDNodeElement nodeElement;

  /**
   * Name of the the context node, the recursive node points to (data source)
   */
  private static String dataNodeName;

  /**
   * Name of the the recursive child node
   */
  private static String childNodeName;

  /**
   * Name of the context attribute storing the isExpanded state
   * of a line within the TreeByNestingTableColumn
   */
  private static String isExpandedAttrName;

}

Iterating the names of all multi-selected catalog entries could look like this

  //@@begin others

  private String selectedElementsToString(Collection list) {
    String text = new String();
    for (Iterator iter = list.iterator(); iter.hasNext();) {
      IWDNodeElement element = (IWDNodeElement) iter.next();
      text += element.getAttributeAsText(IPrivateTreeTableView.ICatalogEntriesElement.TITLE) + "n";
    }
    return text;
  }

  //@@end

This code was not intensively tested. It just demonstrates how this issue could be solved. Feel free to modify or extend it so that it satisfies your own needs.

Regards, Bertram