GWT CEll浏览器实时更新

GWT CEll浏览器实时更新,gwt,widget,Gwt,Widget,是否有人能够在运行时正确更新单元格浏览器,即当您删除节点或添加节点时,更改会立即反映在单元格浏览器中,因为我使用的是列表,而当我进行更改时,它不会立即更新您可以使用ListDataProvider setList(…)方法进行动态更新。以下是我如何通过RPC更新单元格浏览器的示例: private void loadAllData(final ListDataProvider<Data> dataProvider) { dBservice.getAllData(new Asy

是否有人能够在运行时正确更新单元格浏览器,即当您删除节点或添加节点时,更改会立即反映在单元格浏览器中,因为我使用的是列表,而当我进行更改时,它不会立即更新

您可以使用ListDataProvider setList(…)方法进行动态更新。以下是我如何通过RPC更新单元格浏览器的示例:

private void loadAllData(final ListDataProvider<Data> dataProvider) {
    dBservice.getAllData(new AsyncCallback<List<Data>>() {
        public void onSuccess(List<Data> result) {
            dataProvider.setList(result);
        }

        public void onFailure(Throwable caught) {
            caught.printStackTrace();
        }
    });
}
private void loadAllData(最终列表dataProvider dataProvider){
getAllData(新的AsyncCallback(){
成功时公开作废(列表结果){
dataProvider.setList(结果);
}
失败时的公共无效(可丢弃){
已捕获。printStackTrace();
}
});
}

您可以使用ListDataProvider setList(…)方法进行动态更新。以下是我如何通过RPC更新单元格浏览器的示例:

private void loadAllData(final ListDataProvider<Data> dataProvider) {
    dBservice.getAllData(new AsyncCallback<List<Data>>() {
        public void onSuccess(List<Data> result) {
            dataProvider.setList(result);
        }

        public void onFailure(Throwable caught) {
            caught.printStackTrace();
        }
    });
}
private void loadAllData(最终列表dataProvider dataProvider){
getAllData(新的AsyncCallback(){
成功时公开作废(列表结果){
dataProvider.setList(结果);
}
失败时的公共无效(可丢弃){
已捕获。printStackTrace();
}
});
}

要刷新cellBrowser,必须关闭根节点上的所有子节点。 反正是这样的

for (int i = 0; i < cellBrowser.getRootTreeNode().getChildCount(); i++) {
        cellBrowser.getRootTreeNode().setChildOpen(i, false);
    }
for(int i=0;i
AsyncDataProvider调用刷新数据

private final class Model implements TreeViewModel{
    private List<ZonaProxy> zonaList = null;
    private List<CategoriaProxy> categoriaList  = null;

    public void setCategoriaList(List<CategoriaProxy> categoriaList) {
        this.categoriaList = categoriaList;
    }

    public void setListZona(List<ZonaProxy> zonaList) {
        this.zonaList = zonaList;
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public <T> NodeInfo<?> getNodeInfo(T value) {
            CategoryDataProvider dataProvider1 = new CategoryDataProvider();
            return new DefaultNodeInfo(dataProvider1, new CategoriaCell());
        }

    /**
     * Check if the specified value represents a leaf node. Leaf nodes cannot be
     * opened.
     */
    public boolean isLeaf(Object value) {
      if (value instanceof CategoriaProxy){
          if (((CategoriaProxy) value).getLivello() == 3) {
              return true;
          }
      }
      return false;
    }

}

private class CategoryDataProvider extends AsyncDataProvider<CategoriaProxy> 
{
    @Override
    protected void onRangeChanged(HasData<CategoriaProxy> display)
    {
        requests.categoriaRequest().findAllCategorias(0, 8).with().fire(new Receiver<List<CategoriaProxy>>() {
            @Override
            public void onSuccess(List<CategoriaProxy> values) {
                updateRowCount(values.size(), true);
                updateRowData(0, values);
            }
        });
    }
}
私有最终类模型实现TreeViewModel{
私有列表列表=空;
私有列表分类列表=null;
公共无效集合分类列表(列表分类列表){
this.categoriaList=分类主义者;
}
公共无效setListZona(列表zonaList){
this.zonaList=zonaList;
}
@SuppressWarnings({“unchecked”,“rawtypes”})
公共节点信息getNodeInfo(T值){
CategoryDataProvider dataProvider1=新CategoryDataProvider();
返回新的DefaultNodeInfo(dataProvider1,new CategoriaCell());
}
/**
*检查指定的值是否表示叶节点。叶节点不能为空
*打开。
*/
公共布尔isLeaf(对象值){
if(类别APROXY的值实例){
if(((CategoriaProxy)值).getLivello()==3){
返回true;
}
}
返回false;
}
}
私有类CategoryDataProvider扩展了AsyncDataProvider
{
@凌驾
受保护的无效onRangeChanged(HasData显示)
{
requests.categoriaRequest().findAllCategorias(0,8).with().fire(新接收者()){
@凌驾
成功时的公共void(列表值){
updateRowCount(values.size(),true);
updateRowData(0,值);
}
});
}
}

它可以工作。

要刷新cellBrowser,必须关闭根节点上的所有子节点。 反正是这样的

for (int i = 0; i < cellBrowser.getRootTreeNode().getChildCount(); i++) {
        cellBrowser.getRootTreeNode().setChildOpen(i, false);
    }
for(int i=0;i
AsyncDataProvider调用刷新数据

private final class Model implements TreeViewModel{
    private List<ZonaProxy> zonaList = null;
    private List<CategoriaProxy> categoriaList  = null;

    public void setCategoriaList(List<CategoriaProxy> categoriaList) {
        this.categoriaList = categoriaList;
    }

    public void setListZona(List<ZonaProxy> zonaList) {
        this.zonaList = zonaList;
    }

    @SuppressWarnings({ "unchecked", "rawtypes" })
    public <T> NodeInfo<?> getNodeInfo(T value) {
            CategoryDataProvider dataProvider1 = new CategoryDataProvider();
            return new DefaultNodeInfo(dataProvider1, new CategoriaCell());
        }

    /**
     * Check if the specified value represents a leaf node. Leaf nodes cannot be
     * opened.
     */
    public boolean isLeaf(Object value) {
      if (value instanceof CategoriaProxy){
          if (((CategoriaProxy) value).getLivello() == 3) {
              return true;
          }
      }
      return false;
    }

}

private class CategoryDataProvider extends AsyncDataProvider<CategoriaProxy> 
{
    @Override
    protected void onRangeChanged(HasData<CategoriaProxy> display)
    {
        requests.categoriaRequest().findAllCategorias(0, 8).with().fire(new Receiver<List<CategoriaProxy>>() {
            @Override
            public void onSuccess(List<CategoriaProxy> values) {
                updateRowCount(values.size(), true);
                updateRowData(0, values);
            }
        });
    }
}
私有最终类模型实现TreeViewModel{
私有列表列表=空;
私有列表分类列表=null;
公共无效集合分类列表(列表分类列表){
this.categoriaList=分类主义者;
}
公共无效setListZona(列表zonaList){
this.zonaList=zonaList;
}
@SuppressWarnings({“unchecked”,“rawtypes”})
公共节点信息getNodeInfo(T值){
CategoryDataProvider dataProvider1=新CategoryDataProvider();
返回新的DefaultNodeInfo(dataProvider1,new CategoriaCell());
}
/**
*检查指定的值是否表示叶节点。叶节点不能为空
*打开。
*/
公共布尔isLeaf(对象值){
if(类别APROXY的值实例){
if(((CategoriaProxy)值).getLivello()==3){
返回true;
}
}
返回false;
}
}
私有类CategoryDataProvider扩展了AsyncDataProvider
{
@凌驾
受保护的无效onRangeChanged(HasData显示)
{
requests.categoriaRequest().findAllCategorias(0,8).with().fire(新接收者()){
@凌驾
成功时的公共void(列表值){
updateRowCount(values.size(),true);
updateRowData(0,值);
}
});
}
}

它可以工作。

显然,仅仅更改数据提供程序并刷新它是不够的

您还需要强制受影响的单元格关闭并重新打开,如本例所示

public void updateCellBrowser(String id) {
    TreeNode node = getNode(cellBrowser.getRootTreeNode(),id);

    if(node != null && ! node.isDestroyed()) {
        TreeNode parent = node.getParent();
        int index = node.getIndex();

        parent.setChildOpen(index, false,true);
        parent.setChildOpen(index, true, true);
    }
}
在我的特定示例中,单元ID是路径名,因此如下所示 getNode()的实现

私有树节点getNode(树节点,字符串id){
对于(int i=0;i
显然,仅仅更改数据提供程序并刷新它是不够的

您还需要强制受影响的单元格关闭并重新打开,如本例所示

public void updateCellBrowser(String id) {
    TreeNode node = getNode(cellBrowser.getRootTreeNode(),id);

    if(node != null && ! node.isDestroyed()) {
        TreeNode parent = node.getParent();
        int index = node.getIndex();

        parent.setChildOpen(index, false,true);
        parent.setChildOpen(index, true, true);
    }
}
在我的特定示例中,单元ID是路径名,因此如下所示 getNode()的实现

私有树节点getNode(树节点,字符串id){
对于(int i=0;i