Reputation: 1032
Context: Windows 7 64-bit, Java 8, Microsoft Outlook 2010.
Firstly, yes, there are a few other questions on this topic (e.g., here and here). This question has more background and the fact that what I'm trying to do actually works in Swing - so perhaps this is a limitation of JavaFX drag-and-drop capabilities compared to Swing.
Dragging a file attachment from an Outlook email works as expected in some Java Swing based applications. For example, if I have an email with a plain text file attachment (or XML for that matter), and drag that attachment directly into IntelliJ IDEA (version 2019.1), a new tab opens with the attachment contents.
Note I am not dragging the attachment onto the desktop, and then into the application, but directly from Outlook to IntelliJ.
This also works in NetBeans and DbVisualizer (both Swing-based applications).
My understanding of Outlook is that drag-and-drop for file attachments requires the receiving application to be able to stream the binary data directly from Outlook. There is some example C/C++ code for doing it here, and a .NET example here. Quite a few native Windows applications do not even bother to handle this - you cannot drag a file attachment from Outlook directly into Notepad for example.
I have not been able to make this work in JavaFX so far. I get the drop event, and 2 data formats enumerated (a private one called "RenPrivateItem", and a second called "message/external-body"). But trying to fetch either of those formats just returns null.
There is a bug filed against OpenJDK for this here.
And yes, I know there is a workaround - I can use an Outlook add-in such as OutlookFileDrag to make Outlook copy attachments to a local temp folder when doing a drag-and-drop. The drag-and-drop that my application receives is then just a list of local filenames, and everything is easy.
But I'd like to avoid Outlook add-ins if possible.
So my problem actually has a couple of sub-questions :-
It looks like Swing/AWT can manage the data transfer (IDataObject interface?) from Outlook when dragging a file attachement. Does JavaFX not implement the same functionality?
Is there any way of using the AWT drag-and-drop functionality in a JavaFX application? Or is that just asking for trouble?
If JavaFX has actually implemented the necessary Windows code to copy the file attachment data (and I'm hoping that it has, because I can see the data formats at least), is there any way of just getting the raw bytes off the dragboard object?
As an aside, I've been trying to delve into the source code for the JDK and IntelliJ to actually see how this is implemented in Swing, but am getting a bit lost in all the detail. If anyone can point me at the classes/files that actually implement this behaviour I'd be grateful, thanks.
Upvotes: 3
Views: 831
Reputation: 31
As postet in the comment above (not being able to comment due to restrictions of Stack Overflow), I did some work based on Java/SWT. This solution does not work for JavaFX out of the box and currently I am about to get it done for JavaFX as well. As we are sitting in the same boat: How did you get JavaFX answering drops on Outlook Attachments? I only get it working for mails dropped.
In the end my solution for SWT it was the challenge to accept dropped mails (not attachments). Therefor I had to access the raw pointer received from outlook and rebuild the whole Outlook Message based on OLE stuff (CompoundObject, CompoundStream, ...) I used Apache POI to write it to a new file which is not 1:1 binary compatible to the dropped .MSG file, but contained all needed information.
Handling attachments in SWT was as easy as in Swing, as you described above. Sorry, this answer does not help you further, but as I am also working on it, I hope to find a solution, too.
Upvotes: 1