on 04-21-2009 9:23 PM
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.
IPrivate(n).I(n)Element selectedElem = wdContext.node(n).getTreeSelection();
if ( selectedElem.node<RecursiveChildNode>().size() > 0 )
{
/* there are children */
}
Armin
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
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.
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
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.
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
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.
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
90 | |
10 | |
10 | |
10 | |
7 | |
7 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.