Announcement

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

    Tree - drag&drop nodes

    Hi,

    I have a problem related to a smartgwt Tree structure.
    I'm creating a Tree (called nodesTree) with values from a DB, and each node has a name set up.
    For ex I'm having 4 nodes (the numbers are the names of the nodes):
    1
    --2
    3
    --4
    (ignore '--')

    Code:
    for (TreeNode node : nodesTree.getAllNodes()){
            System.out.print(node.getName());
    }
    Output: 1 2 3 4

    If I drag node 4 under node 1(at the same level as 2)
    1
    --2
    --4
    3
    (ignore '--')

    I want to have the order of nodes: 1 2 4 3 but if I repeat the above "for" statement the output will be the same as above: 1 2 3 4.

    TreeGrid.refreshFields() does not work.

    I'm using smartgwt 2.4.

    Thank you.

    ------------------------------------
    Later edit:

    The tree is manually populated. I'm adding the nodes to the tree manually from code, accoding to some values that I'm receiving from DB.
    Code:
     
        Tree nodesTree = new Tree();
        TreeGrid navTreeGrid = new TreeGrid();
        navTreeGrid.setData(nodesTree);
        navTreeGrid.setCanReorderRecords(true); 
        navTreeGrid.setCanReparentNodes(true);
    Last edited by manu_tmu; 20 Feb 2011, 23:01.

    #2
    Added the entry point class below.
    In the method resetNodesAttributes which is called from onDrop method (from addDropHandler) I want to have the new order of nodes after drag&drop action was made

    Code:
    Please help me resolving this issue.
    
    package de.vogella.gwt.helloworld.client;
    
    import com.google.gwt.core.client.EntryPoint;
    import com.google.gwt.user.client.ui.RootPanel;
    import com.smartgwt.client.types.TreeModelType;
    import com.smartgwt.client.widgets.events.DropEvent;
    import com.smartgwt.client.widgets.events.DropHandler;
    import com.smartgwt.client.widgets.tree.Tree;
    import com.smartgwt.client.widgets.tree.TreeGrid;
    import com.smartgwt.client.widgets.tree.TreeNode;
    
    public class HelloGwt implements EntryPoint {
    	
    	private static final String NAVPATH_ROOT = "/";
    	Tree nodesTree = null;
    	
    	@Override
    	public void onModuleLoad() {
    		// Tree structure
    		nodesTree = new Tree();
    		nodesTree.setRootValue(NAVPATH_ROOT);
    		nodesTree.setModelType(TreeModelType.PARENT);
    
    		TreeGrid navTreeGrid = new TreeGrid();
    		navTreeGrid.setCanReorderRecords(true);
    		navTreeGrid.setCanReparentNodes(true);
    		navTreeGrid.setData(nodesTree);
    
    		// add first node
    		TreeNode newNode = new TreeNode();
    		newNode.setName("a");
    		nodesTree.add(newNode, NAVPATH_ROOT);
    
    		// add the second node
    		newNode = new TreeNode();
    		newNode.setName("ab");
    		nodesTree.add(newNode, NAVPATH_ROOT);
    
    		// add the third node to the tree 
    		newNode = new TreeNode();
    		newNode.setName("abc");
    		nodesTree.add(newNode, NAVPATH_ROOT);
    
    		navTreeGrid.addDropHandler(new DropHandler() {
    			@Override
    			public void onDrop(DropEvent event) {
    				resetNodesAttributes(); 
    			}
    		});
    	
    		RootPanel.get().add(navTreeGrid);
    	}
    	
    	public void resetNodesAttributes() {
                // here I want to have the new order of nodes after drag&drop action was made
    	    for (TreeNode node : nodesTree.getAllNodes()) {
    	       System.out.println(node.getName());
    	    }
    	}
     
    }
    Last edited by manu_tmu; 20 Feb 2011, 23:00.

    Comment


      #3
      Resolved by wrapping the output in a
      Code:
      DeferredCommand
      .

      Comment

      Working...
      X