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

Regression: TableView single selects on multiple selection DND

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 8u20
    • Fix Version/s: 8u20
    • Component/s: javafx
    • Labels:
    • Environment:

      Java 8u20 b13 Linux

      Description

      This is a regression of issue RT-31104.

      When the table has a multiple selection it shouldn't single select until the mouse is released. This is how the ListView appears to operate.

      Below is a test class to reproduce with a ListView for comparison:

      1. Multi select on the table and then click to drag the selection. It will single select first and then drag.

      2. Try the same on the ListView...


      *************************************** Test Class *******************************************
      import java.util.List;

      import javafx.application.Application;
      import javafx.scene.Scene;
      import javafx.scene.control.ListView;
      import javafx.scene.control.SelectionMode;
      import javafx.scene.control.TableCell;
      import javafx.scene.control.TableColumn;
      import javafx.scene.control.TableView;
      import javafx.scene.input.ClipboardContent;
      import javafx.scene.input.Dragboard;
      import javafx.scene.input.MouseEvent;
      import javafx.scene.input.TransferMode;
      import javafx.scene.layout.HBox;
      import javafx.stage.Stage;

      public class DragAndDropTest extends Application {

          @Override public void start(Stage primaryStage) {
             
              TableView<String> table = new TableView<>();
              // add some rows
              for ( int i = 1; i <= 10; i++ ) {
                  table.getItems().add("" +i);
              }
              
              // add some columns
              for ( int i = 0; i < 3; i++ ) {
                  final TableColumn<String, String> column =
                        new TableColumn<>("Column " + i);
                  column.setPrefWidth(100);
                  column.setCellFactory(c -> new TableCell<String, String>() {
                     @Override protected void updateItem(String item, boolean empty) {
                         super.updateItem(item, empty);
                         if ( empty || getTableRow() == null ) {
                             setText("");
                         } else {
                             setText("row " + getTableRow().getItem() );
                         }
                     }
                 }) ;
                  
                  table.getColumns().add( column );
              }
              
              table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
              
              // setup simple DND of row data...
              table.setOnDragDetected(( MouseEvent event) -> {
                 List<String> sel = table.getSelectionModel().getSelectedItems();
                 if ( sel != null ) {
                    Dragboard db = table.startDragAndDrop(TransferMode.COPY);
                    ClipboardContent content = new ClipboardContent();
                    content.putString( String.join(", ", sel) );
                    db.setContent(content);
                    event.consume();
                 }
              });
              
              // a listview for comparison
              ListView<String> list = new ListView<>();
              for ( int i = 1; i <= 10; i++ ) {
                 list.getItems().add(""+ i);
              }
              list.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
              list.setOnDragDetected(( MouseEvent event) -> {
                 List<String> sel = list.getSelectionModel().getSelectedItems();
                 if ( sel != null ) {
                    Dragboard db = table.startDragAndDrop(TransferMode.COPY);
                    ClipboardContent content = new ClipboardContent();
                    content.putString( String.join(", ", sel) );
                    db.setContent(content);
                    event.consume();
                 }
              });
              
              primaryStage.setScene(new Scene(new HBox(20, table, list), 550, 350));
              primaryStage.show();
          }

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

      }

        Attachments

          Activity

            People

            Assignee:
            msladecek Martin Sládeček
            Reporter:
            csmithjfx Charles Smith (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:
              Imported: