0

我已经实现了CellTree,我使用的是 GWT 版本 2.5.1-rc1,它运行良好,服务器响应是异步的。但是我需要在这个CellTree和何时找到节点并打开它时实现搜索。知道我是如何实现的CellTree吗?

我的查看代码:

VerticalPanel vPanel = new VerticalPanel();

CustomTreeModel model = new CustomTreeModel();

CellTree.Resources res = GWT.create(CellTree.BasicResources.class);

CellTree tree = new CellTree(model, null, res);

vPanel.add(tree);

我的CustomTreeModel代码:

public class CustomTreeModel implements TreeViewModel {

    private MyCell dataTreeCell;
    private SingleSelectionModel<TreeNode> selectionModel;

    public CustomTreeModel() {
        dataTreeCell = new MyCell();
        selectionModel = new SingleSelectionModel<TreeNode>();

    }


    /**
     * Get the {@link NodeInfo} that provides the children of the specified
     * value.
     */
    @Override
    public <T> TreeViewModel.NodeInfo<?> getNodeInfo(T value) {
        ListDataProvider<TreeNode> dataProvider = new ListDataProvider<TreeNode>();
        requestData(dataProvider, (TreeNode) value);

        return new DefaultNodeInfo<TreeNode>(dataProvider, dataTreeCell,
            selectionModel, null);//dataTreeCell
    }

    @Override
    public boolean isLeaf(Object value) {
        return (value instanceof ...);
    }

    private void requestData(final ListDataProvider<TreeNode> dataProvider,
        final TreeNode node) {

        try {
            RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);

            rb.setCallback(new RequestCallback() {
                @Override
                public void onError(Request request, Throwable exception) {
                    Window.alert("Error occurred" + exception.getMessage());
                }

                @Override
                public void onResponseReceived(Request request, Response response) {
                    if (200 == response.getStatusCode()) {

                        dataProvider.getList().addAll(response.branchesList());

                        dataProvider.refresh();

                    } else {
                        Window.alert("Error occurred" + response.getStatusCode());
                    }
                }
            });

            rb.send();
        } catch (RequestException e) {
            Window.alert("Error occurred" + e.getMessage());
        }
    }
}

欢迎任何帮助!

4

1 回答 1

0

You can try to use operating on tree nodes like:

TreeNode node = cellTree.getRootTreeNode();
  int max = node.getChildCount();
for (int i = 0; i < max; i++) {
  if (!node.isChildOpen(i)) {
    node.setChildOpen(i, open, false);
  }

And it's a magic. Your node on tree will be expanded :)

于 2013-10-07T18:52:48.287 回答