First of all, Sorry that i posted it in wrong version forum and thanks for guidance.
I am here posting the code which will make DnD download possible using Label. If you replace the same code with Button ,TextBox, etc then it will work for them also.
This code will work in Chrome only. Just drag the label and Drop it to Desktop and you will see your files is getting downloaded.
Code:
package com.wa.dnd.client;
import com.google.gwt.event.dom.client.DragStartEvent;
import com.google.gwt.event.dom.client.DragStartHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
public class WidgetDownload extends Composite {
private Label lblDrag;
public WidgetDownload() {
lblDrag = new Label("Drag Me");
lblDrag.getElement().setAttribute("data-downloadurl", "application/pdf:"
+ "HTML5CheatSheet.pdf:"
+ "http://www.thecssninja.com/demo/gmail_dragout/html5-cheat-sheet.pdf");
lblDrag.getElement().setAttribute("draggable", "true");
lblDrag.getElement().setId("dragout");
lblDrag.getElement().setClassName("icon");
lblDrag.addDragStartHandler(new DragStartHandler() {
@Override
public void onDragStart(DragStartEvent event) {
event.getDataTransfer().setData("DownloadURL", lblDrag.getElement().getAttribute("data-downloadurl"));
}
});
initWidget(lblDrag);
}
}
Then i had tried to apply same thing in Reordering Grid (http://www.sencha.com/examples/#reorderinggrid),
Code:
GridCellRenderer<Stock> lblDownloadRender = new GridCellRenderer<Stock>() {
public Object render(final Stock model, String property,
ColumnData config, final int rowIndex, final int colIndex,
ListStore<Stock> store, Grid<Stock> grid) {
Label b = new Label((String) model.get(property));
b.getElement().setAttribute("data-downloadurl", "application/pdf:"
+ "HTML5CheatSheet.pdf:"
+ "http://www.thecssninja.com/demo/gmail_dragout/html5-cheat-sheet.pdf");
b.getElement().setAttribute("draggable", "true");
b.getElement().setId("dragout");
b.getElement().setClassName("icon folder");
b.addDragStartHandler(new DragStartHandler() {
@Override
public void onDragStart(DragStartEvent event) {
System.out.println("DT: " + event.getDataTransfer());
}
});
return b;
}
};
And set this render to "Symbol" column using below line.
Code:
column.setRenderer(buttonRenderer);
Now if you will drag the Symbol column, it wont fire the registreted DragStartHandler. The reason i think the native "dragStart" is not firing because, Grid itself managing mouseDown event in such way that it wont allow to fire the browser events like dragStart.
You can verify this at, com.extjs.gxt.ui.client.widget.grid.Grid.onMouseDown(GridEvent<M> e) where, below code is preventing the default browser action.
Code:
if (!"input".equalsIgnoreCase(tagName) && !"textarea".equalsIgnoreCase(tagName)) {
e.preventDefault();
}
After this i had been sure that i wont be able to get the native "dragStart" event, so i had started looking alternative ways to get it. Then i tried below code in our Reordering Grid.
Code:
new GridDragSource(grid) {
@Override
protected void onDragStart(DNDEvent e) {
super.onDragStart(e);
System.out.println("DT1: " + e.getDragEvent().getEvent().getDataTransfer());
System.out.println("DT2: " + e.getEvent().getDataTransfer());
}
};
Now when i start drag, i am getting output as,
DT1: null
DT2: null
Now this mean i am able to capture the "dragStart" (but its not native still, its been created and fired using GXT), but i am not able to getDataTransfer() , which is required to set the download "url" to it, so i can download that link document to desktop.
Can anyone help me with any sort of idea that how should i get the native "dragStart" event?