vaadin / framework

Vaadin 6, 7, 8 is a Java framework for modern Java web applications.
http://vaadin.com/
Other
1.77k stars 729 forks source link

TreeGrid Drag & Drop : actions fails if a previous D&D action occurred #12498

Closed echarlus closed 2 years ago

echarlus commented 2 years ago

Hi, I have a TreeGrid on which I'm allowing items to be moved using Drag & Drop. I'm using a custom HierarchicalDataProvider. If I perform a first Drag & Drop action, everything works fine. If I perform a second D&D action , the DragEndListener is called but when I want to retrieve the DropTagerRow from the event (using e.getDropTargetRow()), the Row is never present. I traced the calls and I found out that the UI seems to be sending back an invalid row ID (or that the internal row mapping table has not been update)

The registered TreeGridDropTargetRpc is called with a rowKey parameter that is not present in the DataCommunicator's KeyMapper map.

In file TreeGridDropTarget.java, line 78 the code : dropTargetRow = getParent().getDataCommunicator().getKeyMapper().get(rowKey); returns null since the key is not in the map.

For example, after the first D&D action, the UI receives the following message :

INFO: Received push (websocket) message: for(;;);[{"syncId": 3, "clientId": 3, "changes" : [], "state":{}, "types":{"79":"36"}, "hierarchy":{"79":[]}, "rpc" : [["79","com.vaadin.shared.data.DataCommunicatorClientRpc","insertRows",[11,5]],["79","com.vaadin.shared.data.DataCommunicatorClientRpc","setData",[11,[{"k":"36","d":{"83":"ELECTRICITE"},"rhd":{"d":1,"c":true,"l":false,"ca":true},"drag-data":{"custom":"{id=96, dn=\"ELECTRICITE\"}","text":"ELECTRICITE"}},{"k":"37","d":{"83":"CLASSE 7"},"rhd":{"d":1,"c":true,"l":false,"ca":true},"drag-data":{"custom":"{id=26, dn=\"CLASSE 7\"}","text":"CLASSE 7"}},{"k":"38","d":{"83":"EAU (SUEZ)"},"rhd":{"d":1,"c":true,"l":false,"ca":true},"drag-data":{"custom":"{id=144, dn=\"EAU (SUEZ)\"}","text":"EAU (SUEZ)"}},{"k":"39","d":{"83":"GAZ"},"rhd":{"d":1,"c":true,"l":false,"ca":true},"drag-data":{"custom":"{id=102, dn=\"GAZ\"}","text":"GAZ"}},{"k":"40","d":{"83":"METEO"},"rhd":{"d":1,"c":true,"l":false,"ca":true},"drag-data":{"custom":"{id=91, dn=\"METEO\"}","text":"METEO"}}]]],["79","com.vaadin.shared.data.DataCommunicatorClientRpc","updateData",[[{"k":"4","d":{"83":"GYMNASE MUNICIPAL"},"rhd":{"d":0,"c":false,"l":false,"ca":true},"drag-data":{"custom":"{id=23, dn=\"GYMNASE MUNICIPAL\"}","text":"GYMNASE MUNICIPAL"}}]]]], "meta" : {}, "resources" : {}, "timings":[685081, 4]}]

And then I try to perform and another D&D and the TreeGridDropTargetRpc receives a rowKey with value 49 but the Communicator's keyObjectMap has only 40 entries (with keys from 1 to 40) with lastKey variable having value 52.

I've setup my D&D using the following code : TreeGridDragSource<SiteLocationWrapper> treeGridDragSource = new TreeGridDragSource<>(sitesGrid); TreeGridDropTarget<SiteLocationWrapper> treeGridDropTarget = new TreeGridDropTarget<>(sitesGrid, DropMode.BETWEEN); treeGridDropTarget.setDropEffect(DropEffect.MOVE); treeGridDragSource.setDragDataGenerator("custom", s -> "{id="+s.getId()+", dn=\""+s.getDisplayName()+"\"}"); and then I added the regular Drag & Drop listeners...

Any hints on what could be going wrong ? Thanks

echarlus commented 2 years ago

Sorry ... bug was caused by the fact that my object's hash() method was not working as expected ...