Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    TreeGrid openAll question

    Hi,

    I have a TreeGrid defined as follows:
    Code:
    		Tree grid1Tree = new Tree();
    		grid1Tree.setModelType(TreeModelType.PARENT);
    		grid1Tree.setRootValue("ROOT");  
    		grid1Tree.setTitleProperty("title");  
    		grid1Tree.setIdField("nodeID");  
    		grid1Tree.setParentIdField("parentNode");  
    		grid1Tree.setNameProperty("name");
    		...
    		TreeGrid treeGrid = new TreeGrid();
    		treeGrid.setDataSource(DataSource.get("DS"));
    		treeGrid.setData(grid1Tree);
    What is the best way to expand all selected nodes?

    At the moment I call
    Code:
    TreeGrid.getData().openAll(node);
    the problem is that this doen't expand all nodes recursively. It fetches data for one level only. Then I do the recursion manually. First I check if all nodes under selected nodes are open and loaded. If it at least one node is not loaded then I can expect DataArrivedEvent where I call openAll for the new loaded nodes. When all nodes are open and loaded then I start the drag and drop operation.
    Code:
    		boolean isOpen = sourceTreeGrid.getData().isOpen(node);
    		boolean isLoaded = sourceTreeGrid.getData().isLoaded(node);
    
    		treeGrid.addDataArrivedHandler(new DataArrivedHandler() {
    			@Override
    			public void onDataArrived(DataArrivedEvent event) {
    				Scheduler.get().scheduleDeferred(new Scheduler.ScheduledCommand() {
    					@Override
    					public void execute() {
    						TreeGrid.getData().openAll(node);
    					}
    				});
    			}
    		});
    There is, however, too many server-side calls. Is there a better way to do so?
    My goal is to drag and drop leaves on selected nodes in a tree.

    best regards,
    Zdary

    #2
    Set loadDataOnDemand to false, and the whole tree will be loaded by the first request, then openAll() will really open all nodes.

    Comment


      #3
      use this code:
      Code:
       addDataArrivedHandler(new DataArrivedHandler(){
      
      			@Override
      			public void onDataArrived(DataArrivedEvent event) {
      				// TODO Auto-generated method stub
      				grid.getData().openAll();
      			}
      };

      Comment


        #4
        Hi,

        I cannot effort to load up the whole tree at one because it can be a big one.
        I'd prefered a mix mode. Loading on demand as long as the user click on the tree.

        When I need it I would call something like
        Code:
        boolean fetchAll = true;
        boolean willFetchData = grid.getData().openAll(fetchAll);
        if I set and reset loadDataOnDemand later then there is no difference in criteria so I cannot even distinguish it in a DMI.

        kavyabellary: How will you know which DataArrivedEvent was the last one?

        Comment

        Working...
        X