cancel
Showing results for 
Search instead for 
Did you mean: 

How do you get the child node of a selected node in TreeByNestingTablColum?

Former Member
0 Kudos

Hello,

I have a call to getTreeSelection() to get the current selected node in a TreeByNestingTableColumn table.

I now want to check if the current IWDNodeElement I just retrieved has another node as its child or is it a leaf?

For retrieving the current selected element in the tree I can do this:


IPrivate(n).I(n)Element selectedElem = wdContext.node(n).getTreeSelection();

Now this only retireves one element into selectedElem.

I cannot use currentChild(n)Element because that returns the lead select element, and in a TreeByNestingTableColumn this is not a unique value depending on where you are in the tree structure.

So my question is, how can I retrieve the current selected element in the tree and its child? I dont need all its children, just the first child is enough to get the info I need.

Please help.

Regards

Marshall.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

IPrivate(n).I(n)Element selectedElem = wdContext.node(n).getTreeSelection();
if ( selectedElem.node<RecursiveChildNode>().size() > 0 )
{
  /* there are children */
}

Armin

Former Member
0 Kudos

Hi,

Yes what Armin has said would work only if the loadchildren event has been called at least once on the selected node i.e. you have expanded the selected node at least once before trying to figure out whether that's a leaf or not.

Regards,

Satyajit

Former Member
0 Kudos

Hi Armin,

Thanks for the response.

I don't want to know if the current selected node has children or not.

I want to actually get the first child and check its isLeaf property.

In the case where you are doing the test, selectedElem.node<RecursiveChildNode>().size() will always return 0. This is because you are taking one single element and storing it in selectedElem. Therefore selectedElem.node<RecursiveChildNode>() is always == null.

Satyajit,

Thats what I thought too, but I don't think thats true because getTreeSelection() only returns a single IWDNodeElement. Then we store that single IWDNodeElement in selectedElem. Then doing selectedElem.node<RecursiveChildNode>.anything() returns null.

Marshall.

Former Member
0 Kudos

Hi,

Actually this code works for me:


IPrivateSecondView.ICatalogEntriesElement ele;

ele = (IPrivateSecondView.ICatalogEntriesElement)wdContext
                                                .nodeCatalogEntries()
                                                .getTreeSelection();

//This correctly returns the size of the child node if it has been loaded
wdComponentAPI.getMessageManager().reportSuccess
                                                (
                                                String.valueOf
                                                (ele
                                                 .nodeChildCatalogEntries()
                                                 .size())
                                                );

Are you trying the same thing and it's not working for you?

Regards,

Satyajit

Former Member
0 Kudos

This is what I'm doing after loading the children. But I'm still getting null for the child.


I(n)Element selectedElem = (I(n)Element) wdContext.node(n)().getTreeSelection();
I(n)Element child = selectedElem.nodeChild(n)().current(n)Element();

if( null == child)
{
   //comes here because evaluates to true
}

Where nodeChild(n) is the recursive node for node(n).

current(n)Element should give me the first child node in the collection right?

What am I doing wrong?

Marshall.

Former Member
0 Kudos

Hi,

The problem is with this line:

I(n)Element child = selectedElem.nodeChild(n)().current(n)Element();

The child node of the selected node has no selection and hence currentElement is null. You should try:


//ele is the selected element from getTreeSelection()
ele.nodeChildCatalogEntries().getCatalogEntriesElementAt(0).getIsLeaf()

Regards,

Satyajit

Former Member
0 Kudos

Hi Satyajit,

That fixed it!! Thanks.

Can you tell me how I can load the child entries in the onLeadSelect of the table instead of clicking the masterColumn? If the user tries to insert without loading the children then it will return null.

Therefore I think it would be better if the children are loaded onLeadSelect.

I don't know how to addSourceMapping for the onLeadSelect action for the table.

Please help.

Marshall.

Former Member
0 Kudos

Hi,

Assuming you are using the childrenLoaded property of the MasterColumn and the elements of your value node has an attribute called ChildrenLoaded of type boolean, you can call the same method which is called on loadChildren event handler. Something like this:


IPrivateSecondView.ICatalogEntriesElement ele;
try {
ele = (IPrivateSecondView.ICatalogEntriesElement)wdContext
                                             .nodeCatalogEntries()
                                             .getTreeSelection();
if(!ele.getChildrenLoaded()) {
   //this method is also called by the loadChildren event handler method
   addCatalogEntries(ele.nodeChildCatalogEntries(), ele.getID());
   ele.setChildrenLoaded(Boolean.TRUE);
}
} catch (WDContextException e) {
logException(e}

Regards,

Satyajit

Former Member
0 Kudos

Hi Satyajit,

That code didnt work out so well.

When I click a particular node, it does load the children, however, the node deselects itself when that happens, and also it doesnt expand the node. The node deselects itself because the focus gets set on the first child that is loaded, however as the node doesnt expand it looks like the lead selection was lost. I also added the code selectedElem.setExpanded(true); but that makes you explicitly click on the root node. Also after, if I click any of the root nodes' children, the node doesnt get expanded after that. I put the code in onLeadSelect action for the table. Is there a way of mimicing the same behaviour as the actual mastercolumns onActionLoadChildren method so that as soon as the application loads, the nodes under the root node are already expanded, then when you clicks each child of the root at the table controls lead select level, its corresponding children are automatically loaded??

Marshall.

Former Member
0 Kudos

Hi,

This code will retain the lead selection as expected.


IPrivateSecondView.ICatalogEntriesElement ele;
try {
ele = (IPrivateSecondView.ICatalogEntriesElement)wdContext
                                                 .nodeCatalogEntries()
                                                 .getTreeSelection();
//load the children if they are not loaded
if(!ele.getChildrenLoaded()) {
   addCatalogEntries(ele.nodeChildCatalogEntries(), ele.getID());
   ele.setChildrenLoaded(Boolean.TRUE);
   //set the tree selection back to the original element
   wdContext.nodeCatalogEntries().setTreeSelection(ele);
   //check if the first child of this node has a child of its own
   ele.nodeChildCatalogEntries().getCatalogEntriesElementAt(0).getIsLeaf();
}
//if the children have been loaded simply check if the first child is a leaf
else if(ele.getChildrenLoaded()) {
   ele.nodeChildCatalogEntries().getCatalogEntriesElementAt(0).getIsLeaf();
}
} catch (WDContextException e) {logException(e);}

Do you want all the nodes to be expanded when the application loads? I did not understand the last part of your reply.

Regards,

Satyajit

Answers (1)

Answers (1)

Former Member
0 Kudos

Hi,

The TreeByNestingTableColumn has a property called IsLeaf. Can you not check this property to know whether the selected element is a leaf or not? Of course you will need to set it manually in the onLoadChildren event handler.

Regards,

Satyajit

Former Member
0 Kudos

Hi Satyajit,

Thanks for the response.

I do not want to check whether the selected node is a leaf or not. I want to check if the selected nodes child is a leaf or not.

Marshall.