Page 1 of 2 12 LastLast
Results 1 to 10 of 15

Thread: [FIXED] [1.2.1] Regression: Asynchronous Tree with DND does not expand folder

  1. #1
    Sencha Premium Member
    Join Date
    Dec 2008
    Location
    Munich, Germany
    Posts
    183

    Default [FIXED] [1.2.1] Regression: Asynchronous Tree with DND does not expand folder

    The following Tree loads the children asynchronously (FileServiceImpl from explorer demo is used) and allows the Tree items to be dragged into other folders.

    A TreeItem will expand and loads its children when a TreeItem is dragged and hovered over a folder. This works in the 1.2 release, but fails in version 1.2.1.

    Code:
    public class DNDTreeTest extends LayoutContainer {
        @SuppressWarnings("unchecked")
        @Override
        public void onRender(Element parent, int index) {
            super.onRender(parent, index);
    
            LayoutContainer container = new LayoutContainer();
            container.setSize(280, 400);
            container.setBorders(true);
            container.setScrollMode(Scroll.AUTO);
    
            this.setStyleAttribute("margin", "10px");
    
            final FileServiceAsync service = (FileServiceAsync) Registry.get("fileservice");
    
            RpcProxy<FileModel, List<FileModel>> proxy = new RpcProxy<FileModel, List<FileModel>>() {
                  @Override
                  protected void load(FileModel loadConfig, AsyncCallback<List<FileModel>> callback) {
                      service.getFolderChildren(loadConfig, callback);
                  }
            };
    
            TreeLoader loader = new BaseTreeLoader(proxy) {
                @Override
                public boolean hasChildren(ModelData parent) {
                    return parent instanceof FolderModel;
                }
            };
    
            TreeStore<FileModel> store = new TreeStore<FileModel>(loader);
    
            final Tree tree = new Tree();
            tree.getStyle().setLeafIconStyle("icon-list");
            TreeBinder<FileModel> binder = new TreeBinder<FileModel>(tree, store);
    
            binder.setDisplayProperty("name");
    
            loader.load(null);
    
            TreeDragSource source = new TreeDragSource(binder);
            source.addDNDListener(new DNDListener() {
                @Override
                public void dragStart(DNDEvent e) {
                    TreeItem item = tree.findItem(e.getTarget());
    
                    if (item != null && item == tree.getRootItem().getItem(0)
                            && tree.getRootItem().getItemCount() == 1) {
                        e.doit = false;
                        e.status.setStatus(false);
                        return;
                    }
    
                    super.dragStart(e);
                }
            });
    
            TreeDropTarget target = new TreeDropTarget(binder);
            target.setAllowSelfAsSource(true);
            target.setFeedback(Feedback.BOTH);
    
            container.add(tree);
            this.add(container);
        }
    }

  2. #2
    Sencha Premium Member
    Join Date
    Dec 2008
    Location
    Munich, Germany
    Posts
    183

    Default

    Has anybody been able to reproduce this? I assume it is a regression and not an error in the code, since it works fine in 1.2

  3. #3
    Sencha Premium Member
    Join Date
    Sep 2007
    Posts
    13,976

    Default

    Yes, not only to reproduce it, but also to look into it much deeper

  4. #4

    Default

    Figures, I spent all day developing a work around for this issue. I had no idea this worked in 1.2, I never had to do any Drag and Drop until 1.2.1. But if you need something working now...

    I had to use OnDragMove(DNDEvent event) on the TreeDropTarget instead of dragEnter on the DNDListener because the event.getTarget() on dragEnter gives you the entire Tree's Element instead of the specific tree node.

    Code:
    treeDropTarget = new TreeDropTarget(treeBinder) {
                protected void onDragMove(DNDEvent event) {
                    processDrag(event);
                    super.onDragMove(event);
                }
    }
    Code:
    private void processDrag(DNDEvent e) {
            Tree theTree = (Tree) e.target.getComponent();
            TreeItem item = theTree.findItem(e.getTarget());
            if (item != lastTreeItem && item != null && item.isExpanded() == false) {
                lastTreeItem = item;
                FolderTreeNode model = ((BeanModel) item.getModel()).getBean();
                if (!model.isLeaf()) {
                    BeanModel toBeExpanded = treeStore.findModel("id", model.getId());
                    if (toBeExpanded != null)
                        treeLoader.loadChildren(toBeExpanded);
                }
    
                item.setExpanded(true);
            }
        }
    Hope this helps.

  5. #5
    Sencha Premium Member
    Join Date
    Dec 2008
    Location
    Munich, Germany
    Posts
    183

    Default

    @amundb: Could you please provide the complete workaround solution? lastTreeItem has not been defined in your example.

  6. #6

    Default

    lastTreeItem is just a temp variable tracked by whatever class you have this code in. So somewhere in your class there is:

    private TreeItem lastTreeItem;

    The reason you should check this:
    if (item != lastTreeItem && item != null && item.isExpanded() == false)

    Is that everytime you have an active drag, and you move the mouse over your target
    tree node without releasing, the process drag method will be called. So we want to keep
    track of what node we are moused over, and only process this event once for the node.
    If we then leave this node and mouse over a different one, then go ahead and continue to process the event.

  7. #7
    Sencha User darrellmeyer's Avatar
    Join Date
    May 2007
    Location
    Washington, DC
    Posts
    2,242

    Default

    A TreeItem will expand and loads its children when a TreeItem is dragged and hovered over a folder. This works in the 1.2 release, but fails in version 1.2.1.
    This is fixed in SVN. Please validate.

  8. #8
    Sencha Premium Member
    Join Date
    Dec 2008
    Location
    Munich, Germany
    Posts
    183

    Default

    I can still reproduce this.

    I grabbed the source from http://code.extjs.com/svn/gxt/releases/1.2.

  9. #9
    Ext GWT Premium Member
    Join Date
    May 2008
    Posts
    52

    Default

    Quote Originally Posted by darrellmeyer View Post
    This is fixed in SVN. Please validate.
    I am using the trunk [r1181] and can reproduce this error when my Tree is not asynchronously loaded.

    Nathan

    Code:
    DataReader<List<MyModel>> treeReader=new DataReader<List<MyModel>>() {
        @SuppressWarnings("unchecked")
        public List<NavigableModel> read(Object _config,Object _parent) {
            if (_parent==null) {
                return((List)grandparentStore().getModels());
            }
            if (_parent instanceof MyGrandParentModel) {
                MyGrandParentModel myGrandParent=(MyGrandParentModel)_parent;
                return((List)myGrandParentModel.getParentStore().getModels());
            }
            if (_parent instanceof MyParentModel) {
                MyParentModel myParentModel=(MyParentModel)_parent;
                return((List)myParentModel.getChildrenStore().getModels());
            }
            throw(new IllegalArgumentException("Invalid data"));
        }
    };
    
    TreeLoader<MyModel> treeLoader=new BaseTreeLoader<MyModel>(treeReader) {
        public boolean hasChildren(MyModel _parent) {
            return(_parent instanceof MyParentModel||_parent instanceof MyGrandParentModel);
        }
    };
    
    TreeStore<MyModel> treeStore=new TreeStore<MyModel>(treeLoader);
    treeStore.setMonitorChanges(true);
    
    Tree tree=new Tree();
    tree.setAnimate(false);
    
    TreeBinder<MyModel> treeBinder=new TreeBinder<MyModel>(tree,treeStore);
    treeBinder.setDisplayProperty("name");
    
    TreeDragSource source=new TreeDragSource((TreeBinder)treeBinder);
    TreeDropTarget target=new TreeDropTarget((TreeBinder)treeBinder);
    target.setAllowSelfAsSource(true);
    target.setFeedback(Feedback.BOTH);[FONT=verdana,geneva,lucida,'lucida grande',arial,helvetica,sans-serif]

  10. #10
    Sencha Premium Member
    Join Date
    Dec 2008
    Location
    Munich, Germany
    Posts
    183

    Default

    Is there any update on this issue?

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •