Native DnD in GWT 2.5.1

147 views
Skip to first unread message

Adolfo Rodriguez

unread,
Jan 1, 2015, 8:54:56 PM1/1/15
to google-we...@googlegroups.com
Hi, I am trying a theoretically easy drag and drop over a GWT 2.5.1 Grid component using the native DnD. I want to drag the id (as String) of a row and drop in different position just to change the order of rows. The process I followed is:

* Initially I tried to drag from the Grid itself as source but then I would not know how to identify the dragged row.

* So I then thought to drag from a cell/row itself, but I do not know how to attach the drag events to the cell/rows

* So finally, I decided wrapping my text content on a Label placed within the Grid cell. With this approach I managed to drag the id of the item with no problems:

final Label label = new Label("blah blah blah item");
label.getElement().setDraggable(Element.DRAGGABLE_TRUE);
label.addDragStartHandler(new DragStartHandler() {
@Override
public void onDragStart(DragStartEvent event) {
String id = "successfully calculated_id";
event.setData("item", id);
}
});

Then again the same problem for the drop target.

* Ideally I would assign the target to the Grid so I can drop in the middle of 2 rows. However no drop event looks to be fired at any time. And, even if it would be fired, again I would not know how to calculate the row/cell number receiving the drop event.

* So, again I tried assigning the drop target to the same Label instances as:

label.addDropHandler(new DropHandler() {
   @Override
   public void onDrop(DropEvent event) {
System.out.println("stop: ");
       // prevent the native text drop
       event.preventDefault();
   }
});

but no drop event looks to be fired. Finally trying to create the drop by using a DOM Handler:

label.addDomHandler(new DropHandler() {
   @Override
   public void onDrop(DropEvent event) {
System.out.println("stop: " + event.getSource());
       event.preventDefault();
       // Do something with dropLabel and dragging
System.out.println("stop: " + event.getSource());
   }
}, DropEvent.getType());

again no drop event fired.

So, at the end:
* no problem dragging the id from the source row
*  but looks impossible to trigger a event for the target item, not mater if it is a Label or the Grid itself. 

My browser is FF and my API is the Native GWT 2.5.1 DnD. Any idea/advise/experience/example?

Thanks

Adolfo Rodriguez

unread,
Jan 1, 2015, 11:34:03 PM1/1/15
to google-we...@googlegroups.com
I have just came across this message in GWT 2.7 DnD API:


Experimental API: This API is still under development and is subject to change.

I suspect that, if is under development in 2.7, it can not yet be working  in 2.5.1

so it looks I will need to evaluate https://code.google.com/p/gwt-dnd/

Adolfo Rodriguez

unread,
Jan 2, 2015, 1:27:47 AM1/2/15
to google-we...@googlegroups.com
I solved the issue by adding

label.addDragOverHandler(new DragOverHandler() {
public void onDragOver(DragOverEvent event) {
// do nothing
}
});

even when this method does nothing.

solved, regards.
Reply all
Reply to author
Forward
0 new messages