JDK-8133342 : Issue with Drag and Drop functionality for email attachments
  • Type: Bug
  • Component: javafx
  • Sub-Component: graphics
  • Affected Version: 8u45
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2015-08-10
  • Updated: 2022-07-29
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
tbdUnresolved
Description
FULL PRODUCT VERSION :
java version "1.8.0_51"
Java(TM) SE Runtime Environment (build 1.8.0_51-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)

ADDITIONAL OS VERSION INFORMATION :
Windows 7 64-bit

EXTRA RELEVANT SYSTEM CONFIGURATION :
Microsoft Outlook Professional Plus

A DESCRIPTION OF THE PROBLEM :
I am trying to implement a requirement to drag and drop documents attached in an email into a JavaFX 8 application running on jdk 8b45. I am able to drag and drop from any Windows folder on my computer but not from an Outlook email attachment.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. Drag a file from Windows folder onto FX application. This works.
2. Now drag an attachment from Microsoft Outlook email. This does NOT work.

EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Should be able to drag and drop attachments from Outlook emails.
ACTUAL -
Does not identify the files being dragged from an email attachment. 

For email attachments, "dragboard.hasFiles()::false" is always displayed on the console inside 'setOnDragOver' method.

REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
import javafx.util.Duration;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.input.*;
import javafx.scene.layout.VBox;
import javafx.scene.paint.Color;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class HelloDragAndDrop extends Application {

    @Override
    public void start(Stage stage) {
        stage.setTitle("Hello Drag And Drop");

        VBox root = new VBox();
        root.setStyle("-fx-border-color: transparent;");
        root.setAlignment(Pos.CENTER);
        Scene scene = new Scene(root, 400, 200);
        scene.setFill(Color.WHITESMOKE);

        Text target = new Text("DROP HERE");
        target.setScaleX(2.0);
        target.setScaleY(2.0);

        root.setOnDragOver((DragEvent event) -> {
            System.out.println("onDragOver");

            // The below statement ALWAYS displays false for outlook attachments
            System.out.println("event.getDragboard().hasFiles()::" +  event.getDragboard().hasFiles());
            if (event.getGestureSource() != root && event.getDragboard().hasFiles()) {
                event.acceptTransferModes(TransferMode.ANY);
            }
            event.consume();
        });

        root.setOnDragEntered((DragEvent event) -> {
            System.out.println("onDragEntered");
            if (event.getGestureSource() != root && event.getDragboard().hasFiles()) {
                root.setStyle("-fx-border-color: green;");
            }
            event.consume();
        });

        root.setOnDragExited((DragEvent event) -> {
            root.setStyle("-fx-border-color: transparent;");
            event.consume();
        });

        root.setOnDragDropped((DragEvent event) -> {
            System.out.println("onDragDropped");
            Dragboard db = event.getDragboard();
            System.out.println("db.hasFiles()::" + db.hasFiles());
            boolean success = false;
            if (db.hasFiles()) {
                target.setText("SUCCESSFULLY DROPPED");
                success = true;
            }
            event.setDropCompleted(success);
            event.consume();

            Timeline timeline = new Timeline(
                new KeyFrame(Duration.seconds(2), (ActionEvent actionEvent) -> {
                        target.setText("DROP HERE");
            }),
                    new KeyFrame(Duration.seconds(5))
            );
            timeline.setCycleCount(1);
            timeline.play();

        });

        root.getChildren().add(target);
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        Application.launch(args);
    }
}
---------- END SOURCE ----------


Comments
possibly related https://stackoverflow.com/questions/41171840/drag-an-outlook-email-into-a-javafx-application/73166666#73166666
29-07-2022