changeset 5034:6e2462521fe1

RT-32560: Focus is not moved back on anchor Reviewed-by: psomashe
author jgiles
date Tue, 17 Sep 2013 10:23:41 +1200
parents 9d21ed934fd0
children e346d89c380b
files modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TableCellBehaviorBase.java modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TableRowBehavior.java modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TreeTableRowBehavior.java modules/controls/src/test/java/javafx/scene/control/ListViewMouseInputTest.java modules/controls/src/test/java/javafx/scene/control/TableViewMouseInputTest.java modules/controls/src/test/java/javafx/scene/control/TreeTableViewMouseInputTest.java modules/controls/src/test/java/javafx/scene/control/TreeViewMouseInputTest.java
diffstat 7 files changed, 199 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TableCellBehaviorBase.java	Tue Sep 17 10:21:34 2013 +1200
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TableCellBehaviorBase.java	Tue Sep 17 10:23:41 2013 +1200
@@ -267,14 +267,22 @@
                             }
                         }
 
-                        // RT-21444: We need to put the range in in the correct
-                        // order or else the last selected row will not be the
-                        // last item in the selectedItems list of the selection
-                        // model,
-                        if (asc) {
-                            sm.selectRange(minRow, maxRow + 1);
+                        if (minRow == maxRow) {
+                            // RT-32560: This prevents the anchor 'sticking' in
+                            // the wrong place when a range is selected and then
+                            // selection goes back to the anchor position.
+                            // (Refer to the video in RT-32560 for more detail).
+                            sm.select(minRow);
                         } else {
-                            sm.selectRange(maxRow, minRow - 1);
+                            // RT-21444: We need to put the range in the correct
+                            // order or else the last selected row will not be the
+                            // last item in the selectedItems list of the selection
+                            // model,
+                            if (asc) {
+                                sm.selectRange(minRow, maxRow + 1);
+                            } else {
+                                sm.selectRange(maxRow, minRow - 1);
+                            }
                         }
                     }
 
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TableRowBehavior.java	Tue Sep 17 10:21:34 2013 +1200
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TableRowBehavior.java	Tue Sep 17 10:23:41 2013 +1200
@@ -175,14 +175,22 @@
                         }
                     }
 
-                    // RT-21444: We need to put the range in in the correct
-                    // order or else the last selected row will not be the
-                    // last item in the selectedItems list of the selection
-                    // model,
-                    if (asc) {
-                        sm.selectRange(minRow, maxRow + 1);
+                    if (minRow == maxRow) {
+                        // RT-32560: This prevents the anchor 'sticking' in
+                        // the wrong place when a range is selected and then
+                        // selection goes back to the anchor position.
+                        // (Refer to the video in RT-32560 for more detail).
+                        sm.select(minRow);
                     } else {
-                        sm.selectRange(maxRow, minRow - 1);
+                        // RT-21444: We need to put the range in the correct
+                        // order or else the last selected row will not be the
+                        // last item in the selectedItems list of the selection
+                        // model,
+                        if (asc) {
+                            sm.selectRange(minRow, maxRow + 1);
+                        } else {
+                            sm.selectRange(maxRow, minRow - 1);
+                        }
                     }
                 } else {
                     sm.clearAndSelect(tableRow.getIndex());
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TreeTableRowBehavior.java	Tue Sep 17 10:21:34 2013 +1200
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TreeTableRowBehavior.java	Tue Sep 17 10:23:41 2013 +1200
@@ -195,14 +195,22 @@
                         }
                     }
 
-                    // RT-21444: We need to put the range in in the correct
-                    // order or else the last selected row will not be the
-                    // last item in the selectedItems list of the selection
-                    // model,
-                    if (asc) {
-                        sm.selectRange(minRow, maxRow + 1);
+                    if (minRow == maxRow) {
+                        // RT-32560: This prevents the anchor 'sticking' in
+                        // the wrong place when a range is selected and then
+                        // selection goes back to the anchor position.
+                        // (Refer to the video in RT-32560 for more detail).
+                        sm.select(minRow);
                     } else {
-                        sm.selectRange(maxRow, minRow - 1);
+                        // RT-21444: We need to put the range in the correct
+                        // order or else the last selected row will not be the
+                        // last item in the selectedItems list of the selection
+                        // model,
+                        if (asc) {
+                            sm.selectRange(minRow, maxRow + 1);
+                        } else {
+                            sm.selectRange(maxRow, minRow - 1);
+                        }
                     }
                 } else {
                     sm.clearAndSelect(treeTableRow.getIndex());
--- a/modules/controls/src/test/java/javafx/scene/control/ListViewMouseInputTest.java	Tue Sep 17 10:21:34 2013 +1200
+++ b/modules/controls/src/test/java/javafx/scene/control/ListViewMouseInputTest.java	Tue Sep 17 10:23:41 2013 +1200
@@ -243,4 +243,29 @@
         assertEquals("Row 5", sm.getSelectedItem());
         assertEquals("Row 5", sm.getSelectedItems().get(1));
     }
+
+    @Test public void test_rt32560_cell() {
+        final int items = 8;
+        listView.getItems().clear();
+        for (int i = 0; i < items; i++) {
+            listView.getItems().add("Row " + i);
+        }
+
+        final MultipleSelectionModel sm = listView.getSelectionModel();
+        sm.setSelectionMode(SelectionMode.MULTIPLE);
+        sm.clearAndSelect(0);
+
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals(0, fm.getFocusedIndex());
+
+        VirtualFlowTestUtils.clickOnRow(listView, 5, KeyModifier.SHIFT);
+        assertEquals(5, sm.getSelectedIndex());
+        assertEquals(5, fm.getFocusedIndex());
+        assertEquals(6, sm.getSelectedItems().size());
+
+        VirtualFlowTestUtils.clickOnRow(listView, 0, KeyModifier.SHIFT);
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals(0, fm.getFocusedIndex());
+        assertEquals(1, sm.getSelectedItems().size());
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/TableViewMouseInputTest.java	Tue Sep 17 10:21:34 2013 +1200
+++ b/modules/controls/src/test/java/javafx/scene/control/TableViewMouseInputTest.java	Tue Sep 17 10:23:41 2013 +1200
@@ -332,4 +332,54 @@
         assertEquals("Row 4", sm.getSelectedItem());
         assertEquals("Row 4", sm.getSelectedItems().get(1));
     }
+
+    @Test public void test_rt32560_cell() {
+        final int items = 8;
+        tableView.getItems().clear();
+        for (int i = 0; i < items; i++) {
+            tableView.getItems().add("Row " + i);
+        }
+
+        final MultipleSelectionModel sm = tableView.getSelectionModel();
+        sm.setSelectionMode(SelectionMode.MULTIPLE);
+        sm.clearAndSelect(0);
+
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals(0, fm.getFocusedIndex());
+
+        VirtualFlowTestUtils.clickOnRow(tableView, 5, KeyModifier.SHIFT);
+        assertEquals(5, sm.getSelectedIndex());
+        assertEquals(5, fm.getFocusedIndex());
+        assertEquals(6, sm.getSelectedItems().size());
+
+        VirtualFlowTestUtils.clickOnRow(tableView, 0, KeyModifier.SHIFT);
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals(0, fm.getFocusedIndex());
+        assertEquals(1, sm.getSelectedItems().size());
+    }
+
+    @Test public void test_rt32560_row() {
+        final int items = 8;
+        tableView.getItems().clear();
+        for (int i = 0; i < items; i++) {
+            tableView.getItems().add("Row " + i);
+        }
+
+        final MultipleSelectionModel sm = tableView.getSelectionModel();
+        sm.setSelectionMode(SelectionMode.MULTIPLE);
+        sm.clearAndSelect(0);
+
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals(0, fm.getFocusedIndex());
+
+        VirtualFlowTestUtils.clickOnRow(tableView, 5, true, KeyModifier.SHIFT);
+        assertEquals(5, sm.getSelectedIndex());
+        assertEquals(5, fm.getFocusedIndex());
+        assertEquals(6, sm.getSelectedItems().size());
+
+        VirtualFlowTestUtils.clickOnRow(tableView, 0, true, KeyModifier.SHIFT);
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals(0, fm.getFocusedIndex());
+        assertEquals(1, sm.getSelectedItems().size());
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/TreeTableViewMouseInputTest.java	Tue Sep 17 10:21:34 2013 +1200
+++ b/modules/controls/src/test/java/javafx/scene/control/TreeTableViewMouseInputTest.java	Tue Sep 17 10:23:41 2013 +1200
@@ -403,6 +403,59 @@
         assertEquals("Row 4", sm.getSelectedItem().getValue());
     }
 
+    @Test public void test_rt32560_cell() {
+        final int items = 8;
+        root.getChildren().clear();
+        for (int i = 0; i < items; i++) {
+            root.getChildren().add(new TreeItem<>("Row " + i));
+        }
+
+        final MultipleSelectionModel sm = tableView.getSelectionModel();
+        sm.setSelectionMode(SelectionMode.MULTIPLE);
+        sm.clearAndSelect(0);
+
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals(root, sm.getSelectedItem());
+        assertEquals(0, fm.getFocusedIndex());
+
+        VirtualFlowTestUtils.clickOnRow(tableView, 5, KeyModifier.SHIFT);
+        assertEquals(5, sm.getSelectedIndex());
+        assertEquals(5, fm.getFocusedIndex());
+        assertEquals(6, sm.getSelectedItems().size());
+
+        VirtualFlowTestUtils.clickOnRow(tableView, 0, KeyModifier.SHIFT);
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals(0, fm.getFocusedIndex());
+        assertEquals(1, sm.getSelectedItems().size());
+    }
+
+    @Test public void test_rt32560_row() {
+        final int items = 8;
+        root.getChildren().clear();
+        for (int i = 0; i < items; i++) {
+            root.getChildren().add(new TreeItem<>("Row " + i));
+        }
+
+        tableView.setShowRoot(true);
+        final MultipleSelectionModel sm = tableView.getSelectionModel();
+        sm.setSelectionMode(SelectionMode.MULTIPLE);
+        sm.clearAndSelect(0);
+
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals(root, sm.getSelectedItem());
+        assertEquals(0, fm.getFocusedIndex());
+
+        VirtualFlowTestUtils.clickOnRow(tableView, 5, true, KeyModifier.SHIFT);
+        assertEquals(5, sm.getSelectedIndex());
+        assertEquals(5, fm.getFocusedIndex());
+        assertEquals(sm.getSelectedItems().toString(), 6, sm.getSelectedItems().size());
+
+        VirtualFlowTestUtils.clickOnRow(tableView, 0, true, KeyModifier.SHIFT);
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals(0, fm.getFocusedIndex());
+        assertEquals(1, sm.getSelectedItems().size());
+    }
+
     @Test public void test_rt_32963() {
         final int items = 8;
         root.getChildren().clear();
--- a/modules/controls/src/test/java/javafx/scene/control/TreeViewMouseInputTest.java	Tue Sep 17 10:21:34 2013 +1200
+++ b/modules/controls/src/test/java/javafx/scene/control/TreeViewMouseInputTest.java	Tue Sep 17 10:23:41 2013 +1200
@@ -313,6 +313,32 @@
         assertEquals("Row 4", sm.getSelectedItems().get(1).getValue());
     }
 
+    @Test public void test_rt32560() {
+        final int items = 8;
+        root.getChildren().clear();
+        for (int i = 0; i < items; i++) {
+            root.getChildren().add(new TreeItem<>("Row " + i));
+        }
+
+        final MultipleSelectionModel sm = treeView.getSelectionModel();
+        sm.setSelectionMode(SelectionMode.MULTIPLE);
+        sm.clearAndSelect(0);
+
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals(root, sm.getSelectedItem());
+        assertEquals(0, fm.getFocusedIndex());
+
+        VirtualFlowTestUtils.clickOnRow(treeView, 5, KeyModifier.SHIFT);
+        assertEquals(5, sm.getSelectedIndex());
+        assertEquals(5, fm.getFocusedIndex());
+        assertEquals(6, sm.getSelectedItems().size());
+
+        VirtualFlowTestUtils.clickOnRow(treeView, 0, KeyModifier.SHIFT);
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals(0, fm.getFocusedIndex());
+        assertEquals(1, sm.getSelectedItems().size());
+    }
+
     @Test public void test_rt_32963() {
         final int items = 8;
         root.getChildren().clear();