Drag and drop of multiple rows in a table

I have a table set like the following :

        Table system = new Table();

When I handle a drop, I use the following code (non related pieces removed, like drop location management) :

            //The data being dropped
            TableTransferable t = (TableTransferable) event.getTransferable();
            //The container which has this object
            Container sourceContainer = t.getSourceContainer();
            //Get the incoming object being dropped 
            Object sourceItemId = t.getItemId();
            Item sourceItem = sourceContainer.getItem(sourceItemId);

            // ..... get dragged item from original container with getItem(sourceItemId)
            // ..... remove item from original container with removeItem(sourceItemId)
            // ..... create new item in new container with addItem()

This works perfectly with one item, when dragging several rows at once (MULTIROW) it behaves as if only the element under the mouse when the drag started is considered.

In the javadoc for MULTIROW there is this comment :

         * Table drags selected rows, if drag starts on a selected rows. Else it
         * starts like in ROW mode. Note, that in Transferable there will still
         * be only the row on which the drag started, other dragged rows need to
         * be checked from the source Table.

While it confirms it is not a bug, I have no idea how to check what group of elements were actually being dragged at that time.
Somebody has an idea or a piece of code ?

Look what is selected on the Table.


returns you either one item or a Collection/Array? of theselected items.

All selected items are dragged and dropped.


Thank you, the comment makes sense now.

I was looking for something more difficult -_-

Hi Andre and Mathias,

I have also requirement of dragging multiple items from table (Bean Item Container) to tree. But, I am not able to implement it. I got table.getValue() into collection and checked its size. It always returns zero. Also, I tried getting all items from table and check for selected using table.isSelected(itemid). If you have implemented it, please help me out.

Here is my code of drop method ::

DataBoundTransferable t = (DataBoundTransferable) dropEvent
Container sourceContainer = t.getSourceContainer();
AbstractSelectTargetDetails dropData = ((AbstractSelectTargetDetails) dropEvent
Object targetItemId = dropData.getItemIdOver();

            Collection<?> selections=(Collection<?>)table.getItemIds();
            if(targetItemId !=null)
                    for (Iterator i = table.getItemIds().iterator(); i.hasNext();) {
                        // Get the current item identifier, which is an integer.
                        int iid = (Integer) i.next();
                            final Item sourceItem = sourceContainer.getItem(iid);
                            final String name= sourceItem.getItemProperty("itemName").getValue().toString();
                            if(name !=null)
                                final Object newItemId= tree1.addItem();
                                tree1.setParent(newItemId, targetItemId);
                                tree1.setChildrenAllowed(newItemId, false);
                    for(all selected items)


Give some suggestions for how to use addons to customize the table to add checkbox into it. I am unable to open any sample codes.

So, Vaadin built a good structure to transfer object by drag and drop, but, in fact, in transfert only one row?? It seem like dummy solution… I hope in a better future solution…