Drag&Drop on Tree component in Vaadin 8.x

Could someone tell me how to enable drag & drop functionality on
Tree
component in Vaadin 8?

It seems like old methods, like
Tree.setDragMode(Tree.TreeDragMode dragMode)
and
Tree.setDropHandler(DropHandler dropHandler)
have dissapeared from
Tree
API. Official documention only mentions how to use drag & drop on
Grid
component which is not what I want currently.

I would be glad to receive some advice on the subject.

Hi,

Tree does not support drag & drop right now. Here’s a GitHub issue:
https://github.com/vaadin/framework/issues/9804
. There is only an ugly workaround available currently - get the TreeGrid component that is the composition root of Tree and use the Grid drag & drop mechanism with that one.

-Olli

Thanks Olli.
Tree
component really uses
TreeGrid
as a root composition, so I was able to do a little hack based on that:

class HackedTree<T> : Tree<T>() { override public fun getCompositionRoot(): TreeGrid<T> { @Suppress("UNCHECKED_CAST") return super.getCompositionRoot() as TreeGrid<T> } } After that I could apply
TreeGridDragSource
and
TreeGridDropTarget
extensions on root itself :slight_smile:

Even so I hope that Vaadin Framework would support something so oblivious without any tricks just like before.

Even with the @Override subclassing, extending the Tree’s grid to be both the TreeGridDragSource AND TreeGridDropTarget does not yield desired re-ordering results. I.e. the GridDragEndListener will fire, but the TreeGridDropListener will not.

Hi there,

Michael Cordero:
Even with the @Override subclassing, extending the Tree’s grid to be both the TreeGridDragSource AND TreeGridDropTarget does not yield desired re-ordering results. I.e. the GridDragEndListener will fire, but the TreeGridDropListener will not.

I have used the solution from Mad Max. I can use GridDropListener or TreeGridDropListener, and both are working for me. I have tried it, with 2 Trees (TreeGrids later), only with 1 Tree, and I always get the DropListener fired.

By the way, thanks for your solution Mad Max.