Remote File Drag And Drop To Local PC

Hello:

I am trying to create a Remote File Drag And Drop Dialog to allow a user to drag a file from a Jlist that shows files
from a specified directory on a server.  I have found some code to get to that point.  My JList is a custom JList called
Droppable List that implements DropTargetListener, DragSourceListener, DragGestureListener.

In the implemented dragGestureRecognized method, I create a FileSelection object.  Then, I call the startDrag method()
as shown. :

FileSelection transferable = new FileSelection(fileNameDesignator);
dragGestureEvent.startDrag(
                        DragSource.DefaultCopyDrop,
                        transferable,
                        this);

The FileSelection object implements the Transferrable interface.  FileSelection extends ArrayList and adds the argument fileNameDesignator (a String) to the FileSelection object.  

Now, during the drag operation, I see the FileSelection getTransferData() get called.

In the getTransferData() method, I retrieve the fileNameDesignator string that I sent in using  the code:(String)get(0).
Now, another piece of this open source code that is part of this project knows how to take this fileNameDesignator string
and retrieve the data as a large String from the remote file.

I then use this code (after I get the fileNameDesignator string).  This code creates a temporary file from the data that
I have retrieved from the server.  So, now my data goes into temp.dat and this works.  The problem is that the return
of the getTransferData() method is causing a Class Cast Exception.  I am not sure what the Class is supposed to be that
getTransferData() is returning.  What would that be?

FileOutputStream outfile = new FileOutputStream("c:\\temp.dat");
DataOutputStream outData = new DataOutputStream(outfile);
outData.write(data.getBytes());
outData.close();
return ("c:\temp.dat");  <-- Class cast exception thrown from here.  I tried returning a File object and that causes the same exception.

Anyway, the end result that I want is to create a file with the same name by dragging it to a Windows Explorer window. How does Java know what File object (including the complete path) to create.  I've looked at local file drag drop examples and I can't find where this occurs.

Do you have any suggestions for me in helping me get my code to work?  I know I may have some issues in several areas
here so any comments about anything would be greatly appreciated.  I am a novice to the Drag and Drop interface although
I have worked with Java since 1998 in other APIs.

Thanks,

Dan

 
danw11Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

CEHJCommented:
>>The problem is that the return
of the getTransferData() method is causing a Class Cast Exception.  I am not sure what the Class is supposed to be that
getTransferData() is returning.  What would that be?

You can find out

System.out.println(getTransferData().getClass());
0
CEHJCommented:
return ("c:\temp.dat");  

should be

return ("c:\\temp.dat");  

or better

return ("c:/temp.dat");  
0
CEHJCommented:
Ignore my first comment !
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

CEHJCommented:
FileSelection should implement Transferable and getTransferData(DataFlavor flavor) should return a List of File when DataFlavor.javaFileListFlavor is requested, otherwise throwing an exception for an unsupported flavor
                       
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
danw11Author Commented:
Thanks CEHJ.  That's all that was missing. Once the getTransferData returned the correct type.  Things worked as expected.  There is some logic as part of the API that KNOWS how to create a file in the dragged-to-file directory on the Local PC.

Thanks,

Dan
0
CEHJCommented:
8-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.