async tree children nodes

Hi,

I have an Async Tree using the LazyNodeTreeContentProvider provider class and the node’s getChildren method is calling a web service which gets the downstrem nodes.

This is the scenario:

1 - A list of root nodes (some with the plus sign on them)
2 - I click on one of them and it takes a bit to expand it
3 - because I left the web service doing some log I find that it calls the web service one time for each child node.

I think this is because it needs to check if each of the child nodes has children in order to render the tree apropriatelly. But this results in poor performance and I would like to know how to disable it, so that it doesn’t call the web service so many times.

Thanks
Bruno

Do you have caching turned on for your web service client? That should cache the results for queries made with the same input params.

Regards,
–mark

Hi,

Probably I didn’t explain myself correctly.
There aren’t any repeated (with the same inputs) calls to the web service.
The problem is like this:

  • Suppose you click on a root node, this will call the web service once in order to get the child nodes - this is fine - but looking at the logs I see that besides calling the service once to get the child nodes it also calls the web service for each of the child nodes (in order to see if these have children) - this isn’t ok and I would like to disable it.

Thanks
Bruno

Thanks for clarifying. Have you tried setting the initialDepth to 0? (There’s some information on this control in the online docs).

Regards,
–mark

Hi,

I was already setting the initialDepth to 0 but still I performed several tests with other values, unfortunately had no luck solving the problem.

Bruno

That doesn’t sound good. Just so i’m clear, when you set the initial Depth of the tree control to 0 and before the user clicks to expand the tree, the webServices are still invoked to fetch the next level of children.

Is that correct?

I can imagine that this is to determine whether or not the root has any children.

Hi,

That’s correct.
I thought that too and after some investigation I found that there’s a method on the provider named getHasChildren() which must be one called. So I decided to override the method so that it always returns false (has no children) and does nothing else. But unfortunately it still calls the ws for each of the child nodes!!!

Overrided the provider’s method this way:

lazyTree = new LazyNodeTreeContentProvider() {
@Override
public boolean getHasChildren() {
return false;
}
};

This seems a bug and I don’t know what else to do.
Thanks for the help,
Bruno

I can confirm that when expanding a node in the tree, each child will be queried to see if it has any children. This information is used to know whether to draw the + (node expansion icon) or not.

Please refer to the sample where I’ve isolated this logic into a simple example.

I’m not sure if I would consider this a bug or not, because the UI must have information in order to determine whether to draw the icon. Perhaps you’d like to request different functionality?

Regards,
–mark
LazyTreeApp.zip (9.14 KB)

Hi,

The LazyNodeTreeContentProvider was designed to access tree’s nodes only as needed (this is what the documentation states). By calling the getChildren() for each child on the current node it throws away this design and worst turns the async tree control unusable for performance reasons.
This behavior makes sense if you’re using the other async tree content providers because all the nodes already exist on MWS. If for each node you need to go to the end resource it becomes a problem.
I consider this a bug.

Thx
Bruno

I realize that the implementation of this interface (ISelectableTreeContentProvider) isn’t sufficient for your needs. You could try to implement this interface yourself or you could try to extend a more primitive implementation: NodeTreeContentProvider.

You can override NodeTreeContentProvider.getHasChildren() and provide your custom logic for determining whether a node has children without explicitly fetching those children.

Mimel,

I tried to implement this using NodeTreeContentProvider.getHasChildren(), but the behaviour is same.
When the tree is formed, the get children method for the parent/child node gets called.

Suppose I have three parent nodes. I overrode the getHasChildren method in my provider class to return true or false based on a predefined condition.

public boolean getHasChildren() {
// TODO Auto-generated method stub
boolean returnVal =false;
DepObjNode currRow =(DepObjNode) this.getCurrentRow();
if(currRow.getType()==“header”){
returnVal= true;
}
else {
returnVal= false;
}

	Logger.getLogger(DepObjProvider.class.getName()).log(Level.INFO, "inside getHasChildren of "+currRow.getId());
	return returnVal;
}

Now I also overrode the getChildren method in my Node class to return children based on the NodeId.
The problem is whenever the tree is rendering for the first time. It shows the parent nodes with plus sign but along with that it is calling the getChildren Method for each of them. Is there any way, then when I click on the + sign, I want to call only the getChildren of the node, I clicked on ?