parttio / dragdroplayouts

Drag and Drop for Vaadin layouts
7 stars 23 forks source link

DDTabSheet loses tabs #86

Open ariordan opened 7 years ago

ariordan commented 7 years ago

When transferring a tab between two DDtabSheets using DefaultTabSheetDropHandler, it is possible to lose the dragged tab. This occurs when HorizontalDropLocation (location) is null, which occurs when the tab is dragged over the content of the other tabsheet, rather then the tabsheet tabs.

There are two possible solutions to this issue:

1: do not perform the drag when location is null


protected void handleDropFromLayout(DragAndDropEvent event) {
    ....
    // cancel drag if location is null
    if (location == null) {
        return;
    }

    if(source instanceof ComponentContainer) {
        source.removeComponent(c);
    } else if(source instanceof SingleComponentContainer) {
        ((SingleComponentContainer)source).setContent((Component)null);
    }
    ....
}

2: append the tab to the end of the target tabsheets tab list


protected void handleDropFromLayout(DragAndDropEvent event) {
    ...
    if(location == HorizontalDropLocation.LEFT) {
        tabSheet.addTab(c, idx);
    } else if(location == HorizontalDropLocation.RIGHT) {
        tabSheet.addTab(c, idx + 1);

    // add tab to end of tab list if location is null
    } else {
        tabSheet.addTab(c);
    }
}