Hi all,
I want to have the new order of nodes after drag&drop action was made in the onDrop method from addDropHandler.
Here's the code:
If I'm using new com.smartgwt.client.widgets.tree.DataChangedHandler():
the order is ok in resetNodesAttributes() method, but this method it is called to many times and I have bigger tree-s structures and I do not want this happen
And another question I have: how can I add a custom drag&drop action to my tree?
Thank you a lot!
I want to have the new order of nodes after drag&drop action was made in the onDrop method from addDropHandler.
Here's the code:
Code:
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); TreeNode newNode = new TreeNode(); newNode.setTitle("a1"); nodesTree.add(newNode, NAVPATH_ROOT); TreeNode newNode2 = new TreeNode(); newNode2.setTitle("a2"); nodesTree.add(newNode2, newNode); TreeNode newNode3 = new TreeNode(); newNode3.setTitle("a3"); nodesTree.add(newNode3, NAVPATH_ROOT); TreeNode newNode4 = new TreeNode(); newNode4.setTitle("a4"); nodesTree.add(newNode4, newNode3); 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 d&d action was made for (TreeNode node : nodesTree.getAllNodes()) { System.out.println(node.getName()); } } }
Code:
nodesTree.addDataChangedHandler(new com.smartgwt.client.widgets.tree.DataChangedHandler() { @Override public void onDataChanged(com.smartgwt.client.widgets.tree.DataChangedEvent dataChangedEvent) { resetNodesAttributes(); } });
And another question I have: how can I add a custom drag&drop action to my tree?
Thank you a lot!
Comment