Here I have an complete and very easy example to dynamically add/remove nodes to an celltree. My example is not working very well. It seems there is an refresh problem. Only
I think I may have licked the problem...
Essentially I've extended and subclasses many parts of CellTree and have obtained an almost perfect working example. Too complex to document here, but suffice to say the solution involved using a node class where I stored the data provider within each node.
https://code.google.com/p/updatable-cell-tree/
I just clear the array of objects maintained in my data provider. I do this in onRangeChanged(final HasData<?> display)
. I guess I don't use a ListDataProvider
here, I use something extending AbstractDataProvider<T>
instead.
To add the node add it to your list within the onRangeChanged()
method and then call updateRowData()
. You can do this for a delete too.
This is somehow a known problem with CellTree.
The reason for the refresh problem is that in the getNodeInfo()
function you create a new ListDataProvider
instance for each CellTree level.
The CellTree only updates/refreshes itself if you update the items in that ListDataProvider
.
I believe that your removeMenu() and addSubMenu() functions add and remove items from the original list stored in your MyNode class but won't update the list in the corresponding ListDataProviders (you can try to check that in debug mode).
The reason why the CellTree is refreshed when you close and re
-open the nodes is because when you re-open the nodes the getNodeInfo()
is called again and the whole CellTree structure will be constructed again (including the new menu or without the removed one respectively).
There are two possible solutions:
ListDataProviders
somewhere and call remove/add on that list (although you do that I assume that the items are not really added/removed there).Both are somehow a PITA to implement. Unfortunately there is no easy way around it.