vaadin / framework

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

Duplicate Drop when 2 GridRowDragger are applied to the same grid (Between grids and inside grid) #10697

Closed besatanas closed 5 years ago

besatanas commented 6 years ago

Framework version 8.3.1

We wanted to DnD beween 2 grids (Right to Left and LeftTo Right) and also being able to reorder inside one of the 2 grids (left one).

public AbonView() {
        ArrayList<Job> Alist = new ArrayList<>();
        Grid <Job>left = new Grid<>();
        Grid <Job>right = new Grid<>();

        left.addColumn(Job::modelDesc).setCaption("desc");
        left.setCaption("Jobs to run");   
        right.addColumn(Job::modelDesc).setCaption("desc");
        right.setCaption("Available jobs ");

        left.getColumns().stream().forEach(col -> col.setSortable(false));

        left.setDataProvider(new ListDataProvider<>(Alist));
    right.setDataProvider(new ListDataProvider<>(new JobHome().loadUnchainedJobs())); //DAO request of free Jobs

        GridRowDragger<Job> leftToRight, rightToLeft, leftToLeft;

    leftToLeft = new GridRowDragger<>(left);
    leftToLeft.getGridDropTarget().addGridDropListener(e -> System.out.printf("orig Left to Left : "+Alist.toString()+"\n"));

    leftToRight = new GridRowDragger<>(left, right);
        leftToRight.getGridDropTarget().addGridDropListener(e -> System.out.printf("orig Left to Rigth : "+Alist.toString()+"\n"));

        rightToLeft = new GridRowDragger<>(right, left);
    rightToLeft.getGridDropTarget().addGridDropListener(e-> System.out.printf("orig Rigth to Left : "+Alist.toString()+"\n"));

     addComponents(new HorizontalLayout(left, right));
}

To reproduce the bug, you need to provide an arrayList with values on the right grid, left grid is empty. 1: drag multiples object from right to left (More than 1) 2: drag back the 'dragged objets' from left to right until left grid is empty. 3: drag back 1 object from right to left and the object will be duplicated in the left grid.

if I remove the leftToLeft GridRowDragger, the issues doesn't happend.

As far as I can see, when dragging right to left, both leftToLeft and rightToLeft DropListener are firered.

dominic-simplan commented 6 years ago

Same issue here.

The problem is that the draggedItems list in the Reorder-GridRowDragger is set to the dragged items when the drag is started, but is never cleared when the drag is finished, as the drop is performed on another component. Now, dragging the item back into the grid, the Reorder-GridRowDragger finds a filled draggedItems list and adds the item to the Grid, even though the items are coming from another component.

besatanas commented 6 years ago

Up?

stale[bot] commented 5 years ago

Hello there!

We are sorry that this issue hasn't progressed lately. We are prioritizing issues by severity and the number of customers we expect are experiencing this and haven't gotten around to fix this issue yet.

There are a couple of things you could help to get things rolling on this issue (this is an automated message, so expect that some of these are already in use):

Thanks again for your contributions! Even though we haven't been able to get this issue fixed, we hope you to report your findings and enhancement ideas in the future too!

Kalomo commented 5 years ago

we have exactly the same behavior

besatanas commented 5 years ago

Hello Kalomo, Seems no priority on that issue.

But still available at 8.6.0 version

edler-san commented 5 years ago

After a long internal discussion we decided to not change the current behaviour of the GridRowDragger as it might cause unexpected behaviour and break existing code. It is intended that there is only one GridRowDragger per Grid. Unfortunately we missed to document that properly and are very sorry about that and the trouble that was caused by this.

As an immediate workaround, you have to keep track of the dragged items manually and update the data provider for the grids manually with the GridDropListeners (sadly that requires creation of a new DataProvider).

For the upcoming 8.7 release we will improve the API and add more info to the criteria script within GridDropTargetConnector (see https://github.com/vaadin/framework/pull/11321) which will allow for an easier workaround.