2013-03-07 66 views
0

我已經實現了CellTree,我使用的是GWT版本2.5.1-rc1,它工作正常,服務器響應是異步的。但我需要在CellTree中執行搜索,並找到節點並打開它。任何想法如何在CellTree執行?如何在CellTree GWT中搜索

我的視圖代碼:

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

你可以嘗試使用像樹節點操作:

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

它是一個神奇的。樹上的節點將展開:)