Reputation: 1147
I am trying to drag and drop a cell in GWT and customize the drag image using dataTransfer.setDragImage(). My image is an ImageResource and here is what I have:
Here is how I construct my "draggable cell"
public CheckBoxDragCell(boolean dependsOnSelection, boolean handlesSelection,ImageResource icon) {
this(dependsOnSelection,handlesSelection);
this.icon = AbstractImagePrototype.create(icon);
}
Here is the eventHandler for the drag:
@Override
public void onBrowserEvent(Context context, Element parent, Boolean value,
NativeEvent event, ValueUpdater<Boolean> valueUpdater) {
String type = event.getType();
boolean enterPressed = "keydown".equals(type) && event.getKeyCode() == KeyCodes.KEY_ENTER;
if ("dragstart".equals(type)){
DataTransfer dataTransfer = event.getDataTransfer();
dataTransfer.setData("text", String.valueOf(context.getIndex()));
if (icon != null){
Image image = icon.createImage();
image.setVisible(true);
dataTransfer.setDragImage(ImageElement.as(image.getElement()), 25, 15);
}
But somehow the image never shows up. To debug, I created a dialogbox and displayed the image there when the eventHandler is called and sure enough it show up there... but not when I call the dataTransfer.setDragImage(....) function. Any help will be enormously appreciated.
Upvotes: 1
Views: 795
Reputation: 21
The reason the image did not show up in the first case is because the ImageElement
is not added to the DOM.
Try adding the ImageElement.as(image.getElement())
to the DOM, then it would show.
Upvotes: 2
Reputation: 51481
In this case it could be an issue of browser support?
I've tried this HTML5 native drag and drop demo: http://html5doctor.com/native-drag-and-drop/
The custom drag image part of it didn't work for me (Chrome 17.0.932.0 dev-m).
Upvotes: 0