cancel
Showing results for 
Search instead for 
Did you mean: 

Expanding and Collapsing All Nodes in a TreeByNestingTableColumn

Former Member
0 Kudos

Hi Experts,

I'm using NWDS 7.0.18.

I have a table with TreeByNestingTableColumn (master column).

The child nodes are recursive nodes and are loaded at runtime with an action onLoadChildren when clicking the master column. My question is, when the hierarchy is in its initial state, only the root node is loaded into the table. But I want to add functionality for expanding all nodes in the tree. Is there a way to achieve this, I'm a little confused because the Hierarchy children havent been loaded yet.

Any suggestion will greatly help.

Regards,

Kunal.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

As per the sample TreeByNestingTableColumn project given in sdn all the root nodes will be loaded at

the first time.

When we expand any root node - the action onActionLoadChildCatalogEntries will be invoked and this action will inturn invoke the method addCatalogEntries() by passing the recursive child node instance and parent id (root node selected). Then this addCatalogEntries() will load all the child entries of that root.

Note: As per this sample project only root nodes will be loaded initially.

To load all the childs initially at first time and to expand them -

1. No need of onActionLoadChildCatalogEntries() action .

2. In the same addCatalogEntries() in forloop add root nodes (as it is now) and childs also recursively.

add this three lines of code.

newCatalogEntriesElement.setChildrenLoaded(true);

newCatalogEntriesElement.setExpanded(true);

addCatalogEntries(newCatalogEntriesElement.nodeChildCatalogEntries(),newCatalogEntriesElement.getID());

It works. No doubt. I tested it.

If you need more info ask me.

Regards,

Charan

Edited by: SRI KRISHNA CHARAN on May 25, 2009 8:26 AM

Edited by: SRI KRISHNA CHARAN on May 25, 2009 8:27 AM

Edited by: SRI KRISHNA CHARAN on May 25, 2009 8:28 AM

Former Member
0 Kudos

Full code..of addCatalogEntries() method.

public void addCatalogEntries( com.sap.tut.wd.treetable.wdp.IPrivateTreeTableView.ICatalogEntriesNode node, java.lang.String parentId )

{

//@@begin addCatalogEntries()

IPrivateTreeTableView.ICatalogEntriesElement newCatalogEntriesElement;

for (int i = 0; i < Catalog.getLength(); i++) {

if (parentId.equals(Catalog.getParentId(i))) {

// create new context node element

newCatalogEntriesElement = node.createCatalogEntriesElement();

node.addElement(newCatalogEntriesElement);

// provide node elements with data

newCatalogEntriesElement.setID(Catalog.getCATALOGID(i));

newCatalogEntriesElement.setTITLE(Catalog.getTITLE(i));

newCatalogEntriesElement.setDESCRIPTION(Catalog.getDESCRIPTION(i));

newCatalogEntriesElement.setAMOUNT(Catalog.getAMOUNT(i));

//Newly added code added to identify the root elements in CatelogEntries node for

//CollapseAll/ExpandAll functionality.

if(parentId.equalsIgnoreCase("ROOT"))

{

newCatalogEntriesElement.setIsRoot(true);

}

if ("ARTICLE".equals(Catalog.getCATALOGTYPE(i))) {

// checkbox is visible by default

newCatalogEntriesElement.setPUBLISHED(Catalog.getPUBLISHED(i));

// third level is last level

newCatalogEntriesElement.setIsLeaf(true);

} else {

// a CATEGORY does not use the checkbox column

newCatalogEntriesElement.setUsageOfPublishedAttribute(WDVisibility.BLANK);

newCatalogEntriesElement.setIsLeaf(false);

}

newCatalogEntriesElement.setChildrenLoaded(true);

newCatalogEntriesElement.setExpanded(true);

addCatalogEntries(newCatalogEntriesElement.nodeChildCatalogEntries(),newCatalogEntriesElement.getID());

}

}

//@@end

}

Edited by: SRI KRISHNA CHARAN on May 25, 2009 9:15 AM

Former Member
0 Kudos

Hi,

For CollapseAll/ExpandAll functionality:

Carete new context attribute isRoot(boolean) in CatelogEntries node to identify the ROOT elements.

And modify the add addCatalogEntries() method as above (//Newly added code).

Provide two buttons "Collapse All" & "Expand All" and corresponding actions. And write the code as below in both the actions.

Regards,

Charan

Former Member
0 Kudos
public void onActionCollapseAll(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionCollapseAll(ServerEvent)
    
    
	for (int i = 0; i < wdContext.nodeCatalogEntries().size(); i++) {
		
	if(wdContext.nodeCatalogEntries().getCatalogEntriesElementAt(i).getIsRoot()==true)
	{
		wdContext.nodeCatalogEntries().getCatalogEntriesElementAt(i).setExpanded(false);
	}
		
	}
    
    //@@end
  }

  //@@begin javadoc:onActionExpandAll(ServerEvent)
  /** Declared validating event handler. */
  //@@end
  public void onActionExpandAll(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionExpandAll(ServerEvent)
	for (int i = 0; i < wdContext.nodeCatalogEntries().size(); i++) {
		
		if(wdContext.nodeCatalogEntries().getCatalogEntriesElementAt(i).getIsRoot()==true)
		{
			wdContext.nodeCatalogEntries().getCatalogEntriesElementAt(i).setExpanded(true);
		}
		
		}
		
    //@@end
  }
Former Member
0 Kudos

Hi Sri,

Thanks for the response. What I'm trying to achieve is to have two buttons, Expand All and Collapse All.

Your solution would work for the the master column click to expand all because the mappingOfOnLoadChildren has been done in wdDoModifyView. But it wont work for the buttons.

Please help me out with how to make it work with buttons.

Thanks

Former Member
0 Kudos

Hi Kunal,

Can you explian me clearly why it will not work.

100% it works. I did it.

The below code of mapping of MasterColumn UI element to CatelogEntriesNode element is not requried if you dont use "onActionLoadChildCatalogEntries" action. Because we are loading all the entries at one shot in addCatalogEntries() method.

if (firstTime) {
      IWDTreeByNestingTableColumn masterColumn =
        (IWDTreeByNestingTableColumn) view.getElement("MasterColumn1");
      masterColumn.mappingOfOnLoadChildren().addSourceMapping("path", "element");
    }

Even if this code exist in wdDoModifyView() method - It will not create any problem.

To acieve that Collapse All/ Expand All functionalality only I asked you to create a new context attribute under CatelogEntriesNode(main tree node). And add this below code in addCatalogEntries() method.

if(parentId.equalsIgnoreCase("ROOT"))
{
	newCatalogEntriesElement.setIsRoot(true);
}

This code is to identify the root nodes in CatelogEntriesNode.

After this create buttons and add the code i gave you as it is in corresponding actions.

It works.

Note: If you load all the data by using the recurive call as per the addCatalogEntries() method code i gave you, You can delete the code in wdDoModifyView() and the action onActionLoadChildCatalogEntries() also.

Actually the code in wdDoModifyView() is required to get the corresponding CatelogeEntriesNode element in to onActionLoadChildCatalogEntries() action to load the child nodes when user expands for the first time any parent node.

Regards,

Charan

Edited by: SRI KRISHNA CHARAN on May 25, 2009 9:57 AM

Former Member
0 Kudos

Hi Kunal,

Is your issue resolved??

Or still you are not able to Collapse/Expand All the tree structure through buttons??

Regards,

Charan

Former Member
0 Kudos

Hi Sri Charan,

Using the methods you provided, when the application loads the first time, when I click the Expand All button, ONLY the ROOT node is expanded and its children are displayed. In order to make all the subsequent children and leaf nodes to display, I have to manually open each one up. Then thereafter Expand All will display all the others after Collapsing first.

I still have a onActionLoadChildren method which is fired everytime the little triangle in the master column is clicked. But the code in that action is only one line:



element.setExpanded(true);

Also, all the elements load expanded as we've setExpanded to true when building the hierarchy. But if I close a few nodes by clicking the little triangle in the master column, then Expand All button will NOT open the ones I closed.

suggestions?

Kindest regards,

Kunal.

Former Member
0 Kudos

Hi Kunal,

I got your problem.

To expand & collpase all the child nodes please modify the code as below.

Create two methods exapndAll & collapseAll and call these two methods in existing button actions.

as below.

public void expandAll( com.sap.tut.wd.treetable.wdp.IPrivateTreeTableView.ICatalogEntriesNode node )
  {
    //@@begin expandAll()
  
  	for (int i = 0; i < node.size(); i++) {
		
	node.getCatalogEntriesElementAt(i).setExpanded(true);
	
	if(node.getCatalogEntriesElementAt(i).getIsLeaf()==false)
	{
		expandAll(node.getCatalogEntriesElementAt(i).nodeChildCatalogEntries());
	}
	}
    
    //@@end
  }

public void collapseAll( com.sap.tut.wd.treetable.wdp.IPrivateTreeTableView.ICatalogEntriesNode node )
  {
    //@@begin collapseAll()
    
	for (int i = 0; i < node.size(); i++) {
		
	node.getCatalogEntriesElementAt(i).setExpanded(false);
	
	if(node.getCatalogEntriesElementAt(i).getIsLeaf()==false)
	{
		expandAll(node.getCatalogEntriesElementAt(i).nodeChildCatalogEntries());
	}
	}
		
    //@@end
  }

public void onActionCollapseAll(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionCollapseAll(ServerEvent)
    
    collapseAll(wdContext.nodeCatalogEntries());

    //@@end
  }

public void onActionExpandAll(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent )
  {
    //@@begin onActionExpandAll(ServerEvent)
    
    expandAll(wdContext.nodeCatalogEntries());
    
    //@@end
  }

We are invoking the methods recursively to expand/collapse all the child nodes.

This works.

Regards,

Charan

Former Member
0 Kudos

Thanks Sri Charan,

That worked fine!

Answers (0)