GWT - Add and remove nodes in celltree

前端 未结 3 905
梦谈多话
梦谈多话 2021-01-05 05:16

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

相关标签:
3条回答
  • 2021-01-05 05:28

    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/

    0 讨论(0)
  • 2021-01-05 05:35

    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.

    0 讨论(0)
  • 2021-01-05 05:45

    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:

    1. Keep a reference for each of the ListDataProviders somewhere and call remove/add on that list (although you do that I assume that the items are not really added/removed there).
    2. Programatically close all nodes and re-open it.

    Both are somehow a PITA to implement. Unfortunately there is no easy way around it.

    0 讨论(0)
提交回复
热议问题