vaadin7 - Drag and drop between two trees using Vaadin 7 -


i have 2 trees:tree1,tree2 , want drag , drop tree1 tree2. problem when want move folder,his childrens don't take right place in tree2. added in tree2 don't true parent (the folder dragged).in fact didn't find how know new id of folder in tree2. here code :

private void drag() {      tree1().setdragmode(treedragmode.node);                  // allow nodes have children             (final object itemid : tree2().getitemids()) {                 tree2().setchildrenallowed(itemid, true);             }              tree2().setdragmode(treedragmode.node);              tree2().setdrophandler(new treesortdrophandler(tree2(), tree1()));   }  public class treesortdrophandler implements drophandler { private final tree tree2; private final tree tree1;  /**  * tree must use {@link hierarchicalcontainer}.  *  * @param tree  */ public treesortdrophandler(final tree tree2,         final tree tree1) {     this.tree2 = tree2;     this.tree1 = tree1; }  @override public acceptcriterion getacceptcriterion() {     // todo auto-generated method stub     return acceptall.get(); }   @override public void drop(draganddropevent dropevent) {     // todo auto-generated method stub       final transferable t = dropevent.gettransferable();       // see comment in getacceptcriterion()      if (t.getsourcecomponent() != tree1              || !(t instanceof databoundtransferable)) {          return;      }       final treetargetdetails dropdata = ((treetargetdetails) dropevent              .gettargetdetails());       final object sourceitemid = ((databoundtransferable) t).getitemid();      // fixme: why "over", should "targetitemid" or      // "getitemid"      final object targetitemid = dropdata.getitemidover();       // location describes on part of node drop took      // place      final verticaldroplocation location = dropdata.getdroplocation();       movenode(sourceitemid, targetitemid, location);  }    private void movenode(final object sourceitemid,          object targetitemid, final verticaldroplocation location) {      final hierarchicalcontainer container = (hierarchicalcontainer) tree1              .getcontainerdatasource();      if (location == verticaldroplocation.middle) {          if (tree1.haschildren(sourceitemid))         {             collection<?> children=tree1.getchildren(sourceitemid);           tree2.additem(tree1.getitemcaption(sourceitemid));          tree2.setparent(tree1.getitemcaption(sourceitemid),targetitemid);           targetitemid=tree2.getitem(tree1.getitemcaption(sourceitemid));          tree2.additems(children);          tree2.setparent(children,tree2.getitemcaption(sourceitemid));                    system.out.print(tree2.getitem(tree1.getitemcaption(sourceitemid)));              system.out.print("//added");              }else {                  tree2.additem(tree1.getitemcaption(sourceitemid));                  tree2.setparent(tree1.getitemcaption(sourceitemid),targetitemid);                  system.out.print("added");              } 


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -