TreeTable and DragAndDropWrapper

Hi,

I’ve got several questions about TreeTable and DragAndDropWrapper.

My goal is to build a Tree and drag and drop file(s) (from Desktop for example) on an item (node).
I quickly understood that it was not possible with a Tree component:
Vaadin forum

and

So I decided to use a TreeTable and DragAndDropWrapper.

This is a small part of my test program:


final Window w = new Window("Tree FilesystemContainer demo");
        setMainWindow(w);
        
        Panel mainPanel = new Panel("Main Panel !");
        
        Label label = new Label("ZZZZZZZZZZZz");
		DragAndDropWrapper dragAndDropWrapper = new DragAndDropWrapper(label);
		dragAndDropWrapper.setStyleName("v-multifileupload-dropzone");
		dragAndDropWrapper.setSizeUndefined();
		dragAndDropWrapper.setDropHandler(this);
		
        Label label2 = new Label("222ZZZZZZZZZZZz");
		DragAndDropWrapper dragAndDropWrapper2 = new DragAndDropWrapper(label2);
		dragAndDropWrapper2.setStyleName("v-multifileupload-dropzone");
		dragAndDropWrapper2.setSizeUndefined();
		dragAndDropWrapper2.setDropHandler(this);
        
        TreeTable tr = new TreeTable("Simple test with builtin container");
        tr.setSelectable(true);

        tr.setDragMode(TableDragMode.ROW);
        // populate table
        tr.addContainerProperty("Foo", String.class, "foo");
        tr.addContainerProperty("DropZone", DragAndDropWrapper.class, null);
        
        Object addItem = tr.addItem();
        tr.getContainerProperty(addItem, "Foo").setValue("First");
        tr.getContainerProperty(addItem, "DropZone").setValue(dragAndDropWrapper);
       
        Object addItem2 = tr.addItem();
        tr.getContainerProperty(addItem2, "Foo").setValue("Second");
        tr.getContainerProperty(addItem2, "DropZone").setValue(dragAndDropWrapper2);
        
        Object addItem3 = tr.addItem();
        tr.getContainerProperty(addItem3, "Foo").setValue("Third");
        tr.getContainerProperty(addItem3, "DropZone").setValue(dragAndDropWrapper);

        // build hierarchy
        tr.setParent(addItem3, addItem2);
        tr.setParent(addItem2, addItem);

        // flag to last item to be leaf
        tr.setChildrenAllowed(addItem3, false);

        // reserve excess space for the "treecolumn"
        tr.setWidth("100%");
        tr.setColumnExpandRatio("Foo", 1);
        
        mainPanel.addComponent(tr);
		
		w.setContent(mainPanel);

But I’ve got some questions…:

  • Using only one DragAndDropWrapper :
    Is it possible to only create one instance of DragAndDropWrapper, and use this instance for several nodes ?
    I try it but DragAndDropWrapper is only available with the last node.
  • Add a dragAndDropWrapper to an item:
    Is it possible to add the DragAndDropWrapper to an Item of the TreeTable ? Therefore, user will drag and drop his file on the Caption of the node, instead of having one column with the item and a second column with the DragAndDropWrapper ?
  • When user drops a file on the DragAndDropWrapper, how can I get the corresponding node of the Tree ?

My last question: Do you know where I could find an example to realize what I explained above ?

My apologies if someone has already asked these questions and I could not figure out yet.

Regards.