Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8125893

[DnD] When url is put to the dragboard, hasFiles() method also returns true.

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Duplicate
    • Affects Version/s: 8
    • Fix Version/s: None
    • Component/s: javafx
    • Labels:
    • Environment:

      jdk1.8.0_b64

      Description

      To reproduce:
      Drag "source" to the "target".
      At source I use only putUrl() and expect the hasUrl() to return true. So it does,
      but hasFiles() also returns true.

      You may also notice that source never reciever onDragDone event.

      import java.io.File;
      import javafx.application.Application;
      import javafx.event.EventHandler;
      import javafx.scene.Scene;
      import javafx.scene.control.Button;
      import javafx.scene.input.*;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;

      public class BugDnD extends Application {

          @Override
          public void start(Stage primaryStage) {

              final Button source = new Button("Source");

              source.setOnDragDetected(new EventHandler<MouseEvent>() {
                  @Override
                  public void handle(MouseEvent event) {
                      System.out.println("onDragDetected");

                      Dragboard db = source.startDragAndDrop(TransferMode.MOVE);

                      ClipboardContent content = new ClipboardContent();
                      content.putUrl("www.oracle.com");
                      db.setContent(content);

                      event.consume();
                  }
              });

              source.setOnDragDone(new EventHandler<DragEvent>() {
                  @Override
                  public void handle(DragEvent event) {
                      System.out.println("onDragDone");
                      
                      System.out.println("event.getTransferMode() = " + event.getTransferMode());

                      event.consume();
                  }
              });

              final Button target = new Button("Target");
              target.setOnDragOver(new EventHandler<DragEvent>() {
                  @Override
                  public void handle(DragEvent event) {
                      //System.out.println("onDragOver");

                      if (event.getGestureSource() != target
                              && event.getDragboard().hasUrl()) {
                          event.acceptTransferModes(TransferMode.MOVE);
                      }

                      event.consume();
                  }
              });

              target.setOnDragDropped(new EventHandler<DragEvent>() {
                  @Override
                  public void handle(DragEvent event) {
                      System.out.println("onDragDropped");
                      
                      Dragboard db = event.getDragboard();
                      boolean success = false;
                      if (db.hasUrl()) {
                          System.out.println(db.getUrl());
                          success = true;
                      }
                      if (db.hasFiles()) {
                          for (File file : db.getFiles()) {
                              System.out.println("file = " + file);
                          }
                      }
                      event.setDropCompleted(success);

                      event.consume();
                  }
              });


              HBox root = new HBox(20d);
              root.getChildren().addAll(source, target);
              Scene scene = new Scene(root, 300, 250);

              primaryStage.setTitle(System.getProperty("java.runtime.version") + "; " + System.getProperty("javafx.runtime.version"));
              primaryStage.setScene(scene);
              primaryStage.show();
          }

          public static void main(String[] args) {
              launch(args);
          }
      }

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                msladecek Martin Sládeček
                Reporter:
                dzinkevi Dmitry Zinkevich (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported: