3

I have a TableView with four rows and I try to test that my drag and drop implementation works. I have the following test:

TableViewDock table = ...;

//the four rows, using the first cell for the DnD
TableCellItemDock[] rows = {new TableCellItemDock(table.asTable(), 0, 0),
                            new TableCellItemDock(table.asTable(), 1, 0),
                            new TableCellItemDock(table.asTable(), 2, 0),
                            new TableCellItemDock(table.asTable(), 3, 0)};

Wrap target = rows[3].wrap();
rows[0].drag().dnd(target, target.getClickPoint());

But the call to dnd blocks: I need to manually move the mouse to "unblock" it and allow the drag and drop action to start (it then completes as expected).

What do I need to do to let dnd do its job on its own?

Note: JemmyFX version = 20120928

assylias
  • 321,522
  • 82
  • 660
  • 783

2 Answers2

2

There is an issue RT-25057 in product which prevented jemmy from correctly using drag-and-drop on some platforms. I'm afraid for now you need to use a workaround using mouse move and press/release:

rows[0].mouse().move();
rows[0].mouse().press();
Point from = rows[0].wrap().getClickPoint();
Point to = target.getClickPoint();
int steps = 10;
for(int i = 1; i<= steps; i++) {
    rows[0].mouse().move(new Point(
        from.x + i*(to.x - from.x)/steps, 
        from.y + i*(to.y - from.y)/steps));
}
rows[0].mouse().release();
Sergey Grinev
  • 34,078
  • 10
  • 128
  • 141
  • if this doesn't work you can do the same logic using AWT `Robot` – Sergey Grinev Sep 05 '13 at 12:32
  • Got it - thanks. One problem though: `target.getClickPoint()` returns the same Point as `from`. Not sure why (if I select rows[0] or target, I can definitely see that they are different rows) – assylias Sep 05 '13 at 13:41
  • See my answer. I fixed it with `Point from = table.wrap().toLocal(rows[0].wrap().toAbsolute(rows[0].wrap().getClickPoint()));` (same for to) and then `table.mouse().move(...)` - however it still does not work: the code blocks after the first loop iteration (I can see a DRAG_DETECED event). Pressing a key unblocks the move and the rest of the loop executes. – assylias Sep 05 '13 at 14:32
1

Thanks to Sergey, I managed to get it to work with the following method:

protected void dragAndDrop(Wrap<? extends Object> from, Wrap<? extends Object> to) throws InterruptedException {
    Point start = scene.wrap().toLocal(from.toAbsolute(from.getClickPoint()));
    Point end = scene.wrap().toLocal(to.toAbsolute(to.getClickPoint()));

    scene.mouse().move(start);
    scene.mouse().press();
    scene.mouse().move(end);
    scene.mouse().release();
}

I haven't managed to do a progressive move with a loop as he suggested: the code gets stuck at the second iteration when move is called again.

assylias
  • 321,522
  • 82
  • 660
  • 783