2

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 folder on my computer but not from an email attachment.

// MY VBOX WHERE I WANT TO DROP FILES INTO
VBox bkgrndDocsVBox = new VBox(10.0);
bkgrndDocsVBox.setPadding(new Insets(15, 10, 5, 10));

bkgrndDocsVBox.setStyle("-fx-border-color: transparent;");
bkgrndDocsVBox.setOnDragOver((final DragEvent event) -> {
    mouseDragOver(event, bkgrndDocsVBox);
});
bkgrndDocsVBox.setOnDragDropped((final DragEvent event) -> {
    mouseDragDropped(event, backgroundDocsDataTable);
});
bkgrndDocsVBox.setOnDragExited((final DragEvent event) -> {
    bkgrndDocsVBox.setStyle("-fx-border-color: transparent;");
});

..............................
..............................

private void mouseDragOver(DragEvent dragEvent, VBox bkgrndDocsVBox) {
    final Dragboard dragboard = dragEvent.getDragboard();

    System.out.println("dragboard.hasFiles()::"+dragboard.hasFiles());

    if (dragboard.hasFiles()) {
        bkgrndDocsVBox.setStyle("-fx-border-color: green;");
        dragEvent.acceptTransferModes(TransferMode.ANY);
    } else {
        dragEvent.consume();
    }
}

..............................
..............................
private void mouseDragDropped(DragEvent dragEvent, TableView<BgDocBean> bgDocsTable) {

    System.out.println("ENTER mouseDragDropped");
    final Dragboard dragBoard = dragEvent.getDragboard();
    boolean success = false;
    boolean isAccepted = false;

// SAVE the FILES into the DATABASE
.......... .......... .......... .......... 
.......... .......... .......... ..........
}

The above code works when I try to drag and drop files from a windows folder. However when I try to drag and drop files from an email attachment, the 'dragboard.hasFiles()::false' is displayed on the console and the functionality does not work.

Please see the fully functional POC below:

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");
            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);
    }
}

On my console if always displays 'event.getDragboard().hasFiles()::false' when I drag and drop an attachment from Microsoft Outlook Professional Plus 2010.

I would highly appreciate any hints on how this could be successfully implemented. Thanks.

Sirish V
  • 930
  • 2
  • 12
  • 24
  • 1
    I can't reproduce this issue. Drag and drop of files from email attachments works fine for me. I modified [HelloDragAndDrop](https://docs.oracle.com/javase/8/javafx/events-tutorial/hellodraganddropjava.htm#CHDEAEAI) to accept files and any transfer mode then dragged file attachments from OS X Mail 7.3 running on OS X 10.9.5 to the JavaFX app running on Java8u20 and the drop was detected without issue, letting me set a JavaFX label to the name of the dropped file attachment. – jewelsea Aug 08 '15 at 08:35
  • Hello @jewelsea, I have executed a POC and still have the same problem. My JavaFX application identifies files dragged from a windows folder but not from outlook attachments. Please find the POC in my original question that I edited. I am running on java 8b45. Thanks. – Sirish V Aug 10 '15 at 18:19
  • I have filed a defect in the bug database: http://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8133342 – Sirish V Aug 12 '15 at 20:27

0 Answers0