GWT: How to programmatically reload CellBrowser?

后端 未结 4 1937
旧时难觅i
旧时难觅i 2021-02-08 21:31

I\'m using GWT 2.1\'s CellBrowser with a custom TreeViewModel. The TreeViewModel in turn uses an AsyncDataProvider to fetch data dynamically. This all

4条回答
  •  鱼传尺愫
    2021-02-08 21:42

    I don't understand why affablebloke's answer is marked as "correct" and upvoted so much!?

    Caffeine Coma asked about updating a Cell Browser and not a Cell Table, that are totally different things!

    For me, the following trick worked: I define the DataProviders outside of the TreeViewModel and pass them as an argument to the constructor. In my case they provide empty data structures at the beginning.

    Now you have a reference to the DataProviders from "outside" in order to update the Cell Browser.

    Example:

    private class MyTreeViewModel implements TreeViewModel {
    
        AbstractDataProvider myDataProvider;
    
        public MyTreeViewModel(AbstractDataProvider myDataProvider)
        {
            this.myDataProvider = myDataProvider;
        }
    
        @Override
        public  NodeInfo getNodeInfo(T value) {
            if(value == null)
            {
                // Level 0
                return new DefaultNodeInfo(myDataProvider, new MyCellImpl());
            }
        }
    }
    
    
    AbstractDataProvider myDataProvider = new ListDataProvider(new ArrayList()); // or AsyncDataProvider
    MyTreeViewModel myModel = new MyTreeViewModel(myDataProvider);
    
    CellBrowser cellBrowser = new CellBrowser.Builder(myModel, null).build();
    
    /*
      here you can do some stuff, for example, bind the CellBrowser to a template with UiBinder
    */
    
    /*
     if you use a ListDataProvider, do
    */
    
    myDataProvider.setList(myDataStructureFromSomewhere);
    myDataProvider.refresh();
    
    /*
     if you use an AsyncDataProvider, do
    */
    
    myDataProvider.updateRowData(..., myDataStructureFromSomewhere);
    myDataProvider.updateRowCount(...);
    

提交回复
热议问题