1 Reply Latest reply on Mar 5, 2008 12:46 PM by barmalini

    Example of a basic tree with drag and drop

      Hello All,

      I've been searching the posts and the examples on the net, but cannot seem to find an example of a basic drag and drop tree.

      At the moment I have the following:

      <h:form>
      
       <rich:panel style="width: 200px; height: 300px; overflow: auto;">
       <rich:tree id="dragTree" value="#{TreeBean.treee}" var="node">
       <rich:treeNode>
       <h:outputText value="#{node}"/>
       </rich:treeNode>
       </rich:tree>
       </rich:panel>
      
      
       <rich:panel style="width: 200px; height: 300px; overflow: auto;">
       <rich:tree id="dropTree" value="#{TreeBean.treee}" var="node">
       <rich:treeNode>
       <h:outputText value="#{node}"/>
       </rich:treeNode>
       </rich:tree>
       </rich:panel>
      
      </h:form>
      


      And

      import java.util.*;
      
      import org.richfaces.event.DropEvent;
      import org.richfaces.model.TreeNode;
      import org.richfaces.model.TreeNodeImpl;
      
      public class TreeBean
      {
       // http://jboss.com/index.html?module=bb&op=viewtopic&t=116378
      
       private TreeNode treee = new TreeNodeImpl();
      
       public void processDrop(DropEvent event)
       {
      
       }
      
       public void createTree()
       {
       TreeNodeImpl node;
       TreeNodeImpl nodeL2;
       TreeNodeImpl loopNode;
       int loop = 0;
       TreeNodeImpl parent = new TreeNodeImpl();
       parent.setData("I am a parent!");
       for( ; loop < 10 ; loop++ )
       {
       loopNode = new TreeNodeImpl();
       loopNode.setData("Loopy " + loop);
      
       for( int i = 0 ; i < 10 ; i++ )
       {
       node = new TreeNodeImpl();
       node.setData(i);
      
       loopNode.addChild("node " + i, node);
       for( int k = 0 ; k < 10 ; k++ )
       {
       nodeL2 = new TreeNodeImpl();
       nodeL2.setData("WOOO" + k);
       node.addChild("WOODENOO" + k, nodeL2);
       }
       }
       parent.addChild("loopy loop " + loop, loopNode);
       }
      
       treee.addChild("Main", parent);
       }
      
      
       public TreeNode getTreee()
       {
       createTree();
       return treee;
       }
      
       public void setTreee(TreeNode treee) {
       this.treee = treee;
       }
      }
      


      The trees are displayed well, probably not the correct way, but it works. I've tried to add drag and drop to it, but I don't get it..

      Any help would be much appreciated.

      Thank you
      Victoria