cancel
Showing results for 
Search instead for 
Did you mean: 

Load entire tree (ie. not recursively)

Former Member
0 Kudos

Hi

I have already implemented a tree which loads recursively when the arrow is selected.

However, I want the entire tree to load on the page when the page loads (the user can then recursively collapse the branches).

I am trying trying to loop through my previous recursive action as follows, but isn't working.

Any ideas?

for (int i = 0; i < wdContext.nodeAppraisal_Data().size(); i++)

{

addCatalogueEntries(newCatalogEntriesElement.nodeChildCatalogueEntries().nodeChildCatalogueEntries(i), wdContext.nodeAppraisal_Data().getAppraisal_DataElementAt(i).getCounter());

newCatalogEntriesElement.setChildrenLoaded(true);

}

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Anton,

As you metioned, you call the LoadChildren event for any tree node when you click on the arrow button on the node,

You need to call the Load event for the Child nodes in wdDoInit method, rather than at the click of the parent node,

So do following for each node,

1) call the event LoadChildren [To Populate all the child elements]

2) set IsExpanded = true [ To expand the node containing data]

So when the page renders you will have all the nodes populated & expanded with their children,

look here,

loadChildren(rootElement);
rootElement.setIsExpanded(true);

where rootElement is the node which will get assigned the child nodes by LoadChildren method

and once it is populated, it will expanded by 2nd line of code.

Hope its clear,

revert if u find any problem.

Deepak

Former Member
0 Kudos

Hi Deepak

I understand what you are telling me, but how do I loop through the nodes?

if I simply do the following,

onActionLoadChildCatalogueEntries(wdEvent, newCatalogEntriesElement);

newCatalogEntriesElement.setExpanded(true);

won't only the first node be populated and expanded?

thanks

Anton

abhijeet_mukkawar
Active Contributor
0 Kudos

Anton,

just got through this link, it will help you out with some code :

http://help.sap.com/saphelp_nw04/helpdata/en/c2/abfceffbacd24185ec7af8a3a2e76a/content.htm

hope it helps

regards

Former Member
0 Kudos

thanks Abhijeet

I need something more dynamic than that.

I think i need to loop through each node.

abhijeet_mukkawar
Active Contributor
0 Kudos

Anton,

if your cotnext structure represents a hierarchy, like,

parent

-


child1

--va1

-


child2

--va2

etc, then for loading the tree before view renders you should write the code in WdDoInit(), and need to loop through each node , e.g, for 1 value of parent the child will execute 'n' times (where n is requirement of no of children)

hope it helps

regards

Former Member
0 Kudos

How do I loop through each node?

abhijeet_mukkawar
Active Contributor
0 Kudos

Hi,

you first need to define a context hierarcy for the tree, then by looping into the model nodes you can add those elements to cotnext node.

for (int i = 0; i < wdContext.nodeAppraisal_Data().size(); i++)
//considering Appraisal_Data is parent model node now if this has any child , then 
//another loop need to be written for that
//create one element of parent(from context) here and add to the context node 
//which will represent the tree nodetype. this newly created context node will
//get values from parent model node 
{
   for (int i = 0; i < wdContext.<node child>().size(); i++)
   {
     //create the child elements according to the no of elements in model's child 
    //node, add all of them to the context's child node.

   //here all of these children will be considered as a children
   //of the created parent node just before the loop, so when
   //next time the parent loop gets executed 2nd times again 
  //new parent element is created and corrsponding children are created
   }
//if you have more children to Appraisal_Date then other loop will go here 
} 

//if child has child then code for that will go in inner loop, so for each child we will 
//run that loop, creating its children

hope it helps

regards

Former Member
0 Kudos

Hi Abhijeet

I already have a tree on the page which loads recursively.

this works 100%, however I need the tree to load entirely when the page loads.

When I call the following function, the initial node appears expanded showing its child nodes and elements, however these child nodes are not expanded to show theirs. and so on.

how can can loop through what I already have, to expand the entire tree?

onActionLoadChildCatalogueEntries(wdEvent, newCatalogEntriesElement);

newCatalogEntriesElement.setExpanded(true);

abhijeet_mukkawar
Active Contributor
0 Kudos

Anton,

take a look at this code: (do something like this in your code )

(In your action you are not adding child nodes. You can do it as:)

for (int i = 0; i < rootNode.size(); i++){
IPrivateTreeView.ITreeNodeElement element = (IPrivateTreeView.ITreeNodeElement)rootNode.
getElementAt(i);
element.setIsExpanded(true);

IPrivateTreeView.ITreeNodeNode subNode = element.nodeChildNode();
if (!subNode.isEmpty()){
for(int n = 0; n < subNode.size(); n++){
IPrivateTreeView.ITreeNodeElement element1 = (IPrivateTreeView.ITreeNodeElement)subNode.getElementAt(n);
//if (element1 != null){
element1.setIsExpanded(true);
//}
}
}
}

take a look at this ex also:

https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webdynpro/construc...

hope it helps

regards

Former Member
0 Kudos

Anton,

what do you mean by saying I already have tree on the page which loads recursively?

I think the event handler

onActionLoadChildCatalogueEntries(wdEvent, newCatalogEntriesElement);

would contain the code for creating that tree structure from some data source(may be any node or any resource bundle)......Am I right?

If this is so, then u need to go to that event handler's code and do the changes,

you need to add a line of code like

element_name.setCtx_va_expanded(true);

wherever you are adding any tree node to some parent node.

If I am not right...then probably u need to explain ur problem in some detail.

also there is no way to loop for the node already added in the tree structure, because u add a node & forget it, only while adding the node, u can set its properties the way u like.

I hope the above will help you,

Regards,

Deeapk

Former Member
0 Kudos

thanks for al the help guys.

I managed to get it right by looping through the recursive node. My code is below for future reference. Only problem is that this only caters for a tree of up to 3 branches deep. If I want more, then I have to add another loop.

onActionLoadChildCatalogueEntries(wdEvent, newCatalogEntriesElement);

newCatalogEntriesElement.setExpanded(true);

for (int i = 0; i < wdContext.nodeCatalogEntries().nodeChildCatalogueEntries().size(); i++)

{

onActionLoadChildCatalogueEntries(wdEvent, newCatalogEntriesElement.getChildCatalogueEntriesElementAt(i));

newCatalogEntriesElement.getChildCatalogueEntriesElementAt(i).setExpanded(true);

for (int j = 0; j < wdContext.nodeCatalogEntries().nodeChildCatalogueEntries().nodeChildCatalogueEntries().size(); j++)

{

onActionLoadChildCatalogueEntries(wdEvent, newCatalogEntriesElement.nodeChildCatalogueEntries().getCatalogEntriesElementAt(i).getChildCatalogueEntriesElementAt(j));

newCatalogEntriesElement.nodeChildCatalogueEntries().getCatalogEntriesElementAt(i).getChildCatalogueEntriesElementAt(j).setExpanded(true);

}

}

Former Member
0 Kudos

Anton,

Could you please post signature and inner code of onActionLoadChildCatalogueEntries method? Just for future reference...

VS

Former Member
0 Kudos

public void onActionLoadChildCatalogueEntries(com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent, com.sanlam.managelist.wdp.IPrivateSanlam360ManageView.ICatalogEntriesElement element )
  {
    //@@begin onActionLoadChildCatalogueEntries(ServerEvent)
	addCatalogueEntries(element.nodeChildCatalogueEntries(), element.getID());
	element.setChildrenLoaded(true);
    //@@end
  }

public void addCatalogueEntries( com.sanlam.managelist.wdp.IPrivateSanlam360ManageView.ICatalogEntriesNode node, java.lang.String ParentID )
  {
    //@@begin addCatalogueEntries()
	IPrivateSanlam360ManageView.ICatalogEntriesElement newCatalogEntriesElement;
	
	for (int i = 0; i < wdContext.nodeAppraisal_Data().size(); i++) {
		
		if (ParentID.equals(wdContext.nodeAppraisal_Data().getAppraisal_DataElementAt(i).getParent())) {
//	   create new context node element
		newCatalogEntriesElement = node.createCatalogEntriesElement();
		node.addElement(newCatalogEntriesElement);
//	   provide node elements with data
		newCatalogEntriesElement.setID(wdContext.nodeAppraisal_Data().getAppraisal_DataElementAt(i).getCounter());
		newCatalogEntriesElement.setTITLE(wdContext.nodeAppraisal_Data().getAppraisal_DataElementAt(i).getElement_Id());
//		newCatalogEntriesElement.setDESCRIPTION(wdContext.nodeAppraisal_Data().getAppraisal_DataElementAt(i).getElement_Text());
		newCatalogEntriesElement.setWEIGHT(wdContext.nodeAppraisal_Data().getAppraisal_DataElementAt(i).getWeighting());
//	change row colour	
		newCatalogEntriesElement.setRowColor(WDTableCellDesign.POSITIVE);
//	   check visibility and enabled properties
		if ("BK".equals(wdContext.nodeAppraisal_Data().getAppraisal_DataElementAt(i).getElement_Type())) {
//	   third level is last level
			newCatalogEntriesElement.setIsLeaf(true);
			newCatalogEntriesElement.setUsageOfPublishedAttribute(WDVisibility.VISIBLE);
			newCatalogEntriesElement.setUsageOfPublishedNote(WDVisibility.BLANK);
			} 
		else {
			newCatalogEntriesElement.setUsageOfPublishedAttribute(WDVisibility.BLANK);
			newCatalogEntriesElement.setUsageOfPublishedNote(WDVisibility.BLANK);
			newCatalogEntriesElement.setIsLeaf(false);
			}
			
		}
			
	    }
		
	}
    //@@end
  }
Former Member
0 Kudos

Anton,

Ok, I still can't understand how you are populating root level, but nevertheless.

Let us assume that you have populated root level in wdDoInit.

Then add the following block to wdDoInit instead of your semi-recursive calls:


   final IPrivateSanlam360ManageView.ICatalogEntriesNode root
     = wdContext.nodeCatalogEntries();
   for (int i = 0, size = root.size(); i < size; i++) {
       final IPrivateSanlam360ManageView.ICatalogEntries el
         = root.getCatalogEntriesElementAt(i);
       addCatalogueEntries(
         el.nodeChildCatalogueEntries(), el.getID(), true /* recursive */
       );
       el.setChildrenLoaded(true);
       // Probably this is necessary as well
       // as far as this is parent
       // el.setUsageOfPublishedAttribute(WDVisibility.BLANK);
       // el.setUsageOfPublishedNote(WDVisibility.BLANK);
       el.setIsLeaf(false);
   }

Next, modify onActionLoadChildCatalogueEntries and addCatalogueEntries as shown below. Notice that you have to add parameter "recursive" of type boolean to addCatalogueEntries via IDE action editor:


public void onActionLoadChildCatalogueEntries(
  com.sap.tc.webdynpro.progmodel.api.IWDCustomEvent wdEvent,
  com.sanlam.managelist.wdp.IPrivateSanlam360ManageView.ICatalogEntriesElement element ) {
  //@@begin onActionLoadChildCatalogueEntries(ServerEvent)
  addCatalogueEntries(element.nodeChildCatalogueEntries(), element.getID(), false);
  element.setChildrenLoaded(true);
  //@@end
}

public void addCatalogueEntries(
  com.sanlam.managelist.wdp.IPrivateSanlam360ManageView.ICatalogEntriesNode node,
  java.lang.String ParentID
  boolean recursive) {
  //@@begin addCatalogueEntries()

  // Lookup source by ParentID in Appraisal_Data
  final IPrivateSanlam360ManageView.IAppraisal_DataNode nAppraisal
    = wdContext.nodeAppraisal_Data();
  IPrivateSanlam360ManageView.IAppraisal_DataElement elAppraisal = null;
  for (int i = 0, size = nAppraisal.size(); i < size; i++) {
    final IPrivateSanlam360ManageView.IAppraisal_DataElement elCandidate
      =  nAppraisal.getAppraisal_DataElementAt(i);
    if ( ParentID.equals( elCandidate.getParent()) ) {
        elAppraisal = elCandidate; break;
    }
  }

  if (null == elAppraisal) return; // Source not found


  // create new context node element
  final IPrivateSanlam360ManageView.ICatalogEntriesElement newCatalogEntriesElement;
    = node.createCatalogEntriesElement();
  node.addElement(newCatalogEntriesElement);
  // provide node elements with data
  newCatalogEntriesElement.setID(elAppraisal.getCounter());
  newCatalogEntriesElement.setTITLE(elAppraisal.getElement_Id());
  // newCatalogEntriesElement.setDESCRIPTION(elAppraisal.getElement_Text());
  newCatalogEntriesElement.setWEIGHT(elAppraisal.getWeighting());
  // change row colour
  // newCatalogEntriesElement.setRowColor(WDTableCellDesign.POSITIVE);
  // check visibility and enabled properties
  if ( "BK".equals(elAppraisal.getElement_Type()) ) {
    // third level is last level
    newCatalogEntriesElement.setIsLeaf(true);
    newCatalogEntriesElement.setUsageOfPublishedAttribute(WDVisibility.VISIBLE);
    newCatalogEntriesElement.setUsageOfPublishedNote(WDVisibility.BLANK);
  } else {
    newCatalogEntriesElement.setUsageOfPublishedAttribute(WDVisibility.BLANK);
    newCatalogEntriesElement.setUsageOfPublishedNote(WDVisibility.BLANK);
    newCatalogEntriesElement.setIsLeaf(false);
  }

  // Now expand all child elements recursively if specified
  if ( recursive ) {
   addCatalogueEntries(
     newCatalogEntriesElement.nodeChildCatalogueEntries(),
     newCatalogEntriesElement.getID(),
     recursive
   );
   newCatalogEntriesElement.setChildrenLoaded(true);
  }
  //@@end
}

What's changed? addCatalogueEntries now may be invoked with recursive=true and this will force recursive load of all levels via depth-first tree traversal. This way you may support as many levels as necessary.

Notice that code in wdDoInit uses recursive=true but action handler uses recursive=false. This way if you comment out my code in wdDoInit you will have 'old behavior' -- level-by-level loading of data. With code in wdDoInit enabled you will have eager loading of data (btw, you may left action handler assigned -- it will have no effect since childrenLoaded property is set correctly in every case).

Valery Silaev

SaM Solutions

http://www.sam-solutions.net

Former Member
0 Kudos

Great Thanks!

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi ,

If the property of the node is singleton , only one instance i.e the current selection or the lead selected would only be loaded.

[i assume the solution you are looking for a fully loaded tree then an on demand load.. !]

If you want to load the entire tree ,fully open .. you have to make it non-singleton.. and load the tree contents..

You might have tweak your recursive function accordingly.. Instead , you can also use the non recursive tree loading link as given by Abhijeet for reference.

Hope this helps.

Regards

Bharathwaj..