我已经实现了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());
}
}
}
欢迎任何帮助!
答案 0 :(得分:0)
您可以尝试在树节点上使用操作,例如:
TreeNode node = cellTree.getRootTreeNode();
int max = node.getChildCount();
for (int i = 0; i < max; i++) {
if (!node.isChildOpen(i)) {
node.setChildOpen(i, open, false);
}
这是一种魔力。树上的节点将被扩展:)