changeset 5826:85ada295c274

RT-34425: Space does not select tree item I expanded the scope of this bug to also fix the fact that no controls were setting the anchor point properly when space was pressed.
author jgiles
date Wed, 27 Nov 2013 15:05:04 +1300
parents 3c2b98a1509d
children f60f42c44074
files modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/ListViewBehavior.java modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TableViewBehaviorBase.java modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TreeViewBehavior.java modules/controls/src/test/java/javafx/scene/control/ListViewKeyInputTest.java modules/controls/src/test/java/javafx/scene/control/TableViewKeyInputTest.java modules/controls/src/test/java/javafx/scene/control/TreeTableViewKeyInputTest.java modules/controls/src/test/java/javafx/scene/control/TreeViewKeyInputTest.java
diffstat 7 files changed, 127 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/ListViewBehavior.java	Wed Nov 27 14:40:28 2013 +1300
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/ListViewBehavior.java	Wed Nov 27 15:05:04 2013 +1300
@@ -720,6 +720,7 @@
     private void activate() {
         int focusedIndex = getControl().getFocusModel().getFocusedIndex();
         getControl().getSelectionModel().select(focusedIndex);
+        setAnchor(focusedIndex);
 
         // edit this row also
         if (focusedIndex >= 0) {
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TableViewBehaviorBase.java	Wed Nov 27 14:40:28 2013 +1300
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TableViewBehaviorBase.java	Wed Nov 27 15:05:04 2013 +1300
@@ -836,6 +836,7 @@
 
         TablePositionBase<TC> cell = getFocusedCell();
         sm.select(cell.getRow(), cell.getTableColumn());
+        setAnchor(cell);
 
         // edit this row also
         if (cell.getRow() >= 0) {
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TreeViewBehavior.java	Wed Nov 27 14:40:28 2013 +1300
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TreeViewBehavior.java	Wed Nov 27 15:05:04 2013 +1300
@@ -72,7 +72,7 @@
         TREE_VIEW_BINDINGS.add(new KeyBinding(END, "SelectAllToLastRow").shift());
         TREE_VIEW_BINDINGS.add(new KeyBinding(PAGE_UP, "SelectAllPageUp").shift());
         TREE_VIEW_BINDINGS.add(new KeyBinding(PAGE_DOWN, "SelectAllPageDown").shift());
-        
+
         TREE_VIEW_BINDINGS.add(new KeyBinding(SPACE, "SelectAllToFocus").shift());
         TREE_VIEW_BINDINGS.add(new KeyBinding(SPACE, "SelectAllToFocusAndSetAnchor").shortcut().shift());
         
@@ -81,7 +81,8 @@
 
         TREE_VIEW_BINDINGS.add(new KeyBinding(PAGE_UP, "ScrollUp"));
         TREE_VIEW_BINDINGS.add(new KeyBinding(PAGE_DOWN, "ScrollDown"));
-        
+
+        TREE_VIEW_BINDINGS.add(new KeyBinding(SPACE, "toggleFocusOwnerSelection"));
         if (PlatformUtil.isMac()) {
             TREE_VIEW_BINDINGS.add(new KeyBinding(SPACE, "toggleFocusOwnerSelection").ctrl().shortcut());
         } else {
--- a/modules/controls/src/test/java/javafx/scene/control/ListViewKeyInputTest.java	Wed Nov 27 14:40:28 2013 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/ListViewKeyInputTest.java	Wed Nov 27 15:05:04 2013 +1300
@@ -1765,4 +1765,34 @@
         assertEquals(0, sm.getSelectedIndex());
         assertTrue(isSelected(0, 1, 2));
     }
+
+    @Test public void test_rt34425() {
+        final int items = 5;
+        listView.getItems().clear();
+        for (int i = 0; i < items; i++) {
+            listView.getItems().add("Row " + i);
+        }
+
+        new StageLoader(listView);
+        final FocusModel fm = listView.getFocusModel();
+        final MultipleSelectionModel sm = listView.getSelectionModel();
+
+        sm.clearAndSelect(1);
+        assertEquals(1, getAnchor());
+        assertEquals(1, fm.getFocusedIndex());
+        assertEquals(1, sm.getSelectedIndex());
+
+        keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.getShortcutKey());
+        Toolkit.getToolkit().firePulse();
+        assertEquals(1, getAnchor());
+        assertEquals(2, fm.getFocusedIndex());
+        assertEquals(1, sm.getSelectedIndex());
+
+        keyboard.doKeyPress(KeyCode.SPACE);
+        Toolkit.getToolkit().firePulse();
+        assertEquals(2, getAnchor());
+        assertEquals(2, fm.getFocusedIndex());
+        assertEquals(2, sm.getSelectedIndex());
+        assertTrue(isSelected(1, 2));
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/TableViewKeyInputTest.java	Wed Nov 27 14:40:28 2013 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/TableViewKeyInputTest.java	Wed Nov 27 15:05:04 2013 +1300
@@ -2582,4 +2582,34 @@
         assertEquals(0, sm.getSelectedIndex());
         assertTrue(isSelected(0, 1, 2));
     }
+
+    @Test public void test_rt34425() {
+        final int items = 5;
+        tableView.getItems().clear();
+        for (int i = 0; i < items; i++) {
+            tableView.getItems().add("Row " + i);
+        }
+
+        new StageLoader(tableView);
+        final FocusModel fm = tableView.getFocusModel();
+        final MultipleSelectionModel sm = tableView.getSelectionModel();
+
+        sm.clearAndSelect(1);
+        assertEquals(1, getAnchor().getRow());
+        assertEquals(1, fm.getFocusedIndex());
+        assertEquals(1, sm.getSelectedIndex());
+
+        keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.getShortcutKey());
+        Toolkit.getToolkit().firePulse();
+        assertEquals(1, getAnchor().getRow());
+        assertEquals(2, fm.getFocusedIndex());
+        assertEquals(1, sm.getSelectedIndex());
+
+        keyboard.doKeyPress(KeyCode.SPACE);
+        Toolkit.getToolkit().firePulse();
+        assertEquals(2, getAnchor().getRow());
+        assertEquals(2, fm.getFocusedIndex());
+        assertEquals(2, sm.getSelectedIndex());
+        assertTrue(isSelected(1, 2));
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/TreeTableViewKeyInputTest.java	Wed Nov 27 14:40:28 2013 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/TreeTableViewKeyInputTest.java	Wed Nov 27 15:05:04 2013 +1300
@@ -3089,4 +3089,35 @@
         assertEquals(0, sm.getSelectedIndex());
         assertTrue(isSelected(0, 1, 2));
     }
+
+    @Test public void test_rt34425() {
+        final int items = 5;
+        root.getChildren().clear();
+        root.setExpanded(true);
+        for (int i = 0; i < items; i++) {
+            root.getChildren().add(new TreeItem<>("Row " + i));
+        }
+
+        new StageLoader(tableView);
+        final FocusModel fm = tableView.getFocusModel();
+        final MultipleSelectionModel sm = tableView.getSelectionModel();
+
+        sm.clearAndSelect(1);
+        assertEquals(1, getAnchor().getRow());
+        assertEquals(1, fm.getFocusedIndex());
+        assertEquals(1, sm.getSelectedIndex());
+
+        keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.getShortcutKey());
+        Toolkit.getToolkit().firePulse();
+        assertEquals(1, getAnchor().getRow());
+        assertEquals(2, fm.getFocusedIndex());
+        assertEquals(1, sm.getSelectedIndex());
+
+        keyboard.doKeyPress(KeyCode.SPACE);
+        Toolkit.getToolkit().firePulse();
+        assertEquals(2, getAnchor().getRow());
+        assertEquals(2, fm.getFocusedIndex());
+        assertEquals(2, sm.getSelectedIndex());
+        assertTrue(isSelected(1, 2));
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/TreeViewKeyInputTest.java	Wed Nov 27 14:40:28 2013 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/TreeViewKeyInputTest.java	Wed Nov 27 15:05:04 2013 +1300
@@ -1991,4 +1991,35 @@
         assertEquals(0, sm.getSelectedIndex());
         assertTrue(isSelected(0, 1, 2));
     }
+
+    @Test public void test_rt34425() {
+        final int items = 5;
+        root.getChildren().clear();
+        root.setExpanded(true);
+        for (int i = 0; i < items; i++) {
+            root.getChildren().add(new TreeItem<>("Row " + i));
+        }
+
+        new StageLoader(treeView);
+        final FocusModel fm = treeView.getFocusModel();
+        final MultipleSelectionModel sm = treeView.getSelectionModel();
+
+        sm.clearAndSelect(1);
+        assertEquals(1, getAnchor());
+        assertEquals(1, fm.getFocusedIndex());
+        assertEquals(1, sm.getSelectedIndex());
+
+        keyboard.doKeyPress(KeyCode.DOWN, KeyModifier.getShortcutKey());
+        Toolkit.getToolkit().firePulse();
+        assertEquals(1, getAnchor());
+        assertEquals(2, fm.getFocusedIndex());
+        assertEquals(1, sm.getSelectedIndex());
+
+        keyboard.doKeyPress(KeyCode.SPACE);
+        Toolkit.getToolkit().firePulse();
+        assertEquals(2, getAnchor());
+        assertEquals(2, fm.getFocusedIndex());
+        assertEquals(2, sm.getSelectedIndex());
+        assertTrue(isSelected(1, 2));
+    }
 }