Thanks Andreas..
We have a JAVA component as a Table from which we drag the file and dropped to native file system. We have code like
A> Component is JXTree. We have set following property to support Drag And Drop.
Component.setDropMode(DropMode.INSERT);
Component.setDragEnabled(true);
DragSource ds = DragSource.getDefaultDragSource();
DragGestureRecognizer dgr = ds.createDefaultDragGestureRecognizer( Component,
DnDConstants.ACTION_MOVE, new FileDragGestureListener());
B> We have written a class which implements Drag Gesture Listener.
public class FileDragGestureListener extends DragSourceAdapter implements DragGestureListener {
public void dragGestureRecognized(DragGestureEvent dge) {
We get selected row from table.
Download the selected File to Native file System's TEMP directory.
FileSystemView fsv = FileSystemView.getFileSystemView();
Icon icn = fsv.getSystemIcon(File);
Toolkit tk = Toolkit.getDefaultToolkit();
Dimension dim = tk.getBestCursorSize(icn.getIconWidth(), icn.getIconHeight());
BufferedImage buff = new BufferedImage(dim.width, dim.height,
BufferedImage.TYPE_INT_ARGB);
if (DragSource.isDragImageSupported()) {
evt.startDrag(DragSource.DefaultCopyDrop, buff, new Point(0, 0),
new TextFileTransferable(File),
this);
} else {
cursor = tk.createCustomCursor(buff, new Point(0, 0), "sString");
evt.startDrag(cursor, null, new Point(0, 0),
new TextFileTransferable(File),
this);
}
}
class TextFileTransferable implements Transferable {
File temp;
public TextFileTransferable(File temp) throws IOException {
this.temp = temp;
}
public Object getTransferData(DataFlavor flavor) {
List list = new ArrayList();
list.add(temp);
return list;
}
public DataFlavor[] getTransferDataFlavors() {
DataFlavor[] df = new DataFlavor[1];
df[0] = DataFlavor.javaFileListFlavor;
return df;
}
public boolean isDataFlavorSupported(DataFlavor flavor) {
if (flavor == DataFlavor.javaFileListFlavor) {
return true;
}
return false;
}
}
So this is how we can able to download the file up to %TEMP% then we can not move that file to a location where is has been dropped.
Please suggest where i am wrong OR what best approach to implement this Drag And Drop.
Thanks