changeset 6604:1d9f6c50dc8b

RT-46509:[TreeTableView] branches don't expand / collapse on double click
author jgiles
date Thu, 03 Apr 2014 10:38:48 +1300
parents 1a470be65586
children 14c8808eca5c
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/TableRowBehaviorBase.java modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TreeTableRowBehavior.java modules/controls/src/test/java/javafx/scene/control/TreeTableViewMouseInputTest.java modules/controls/src/test/java/javafx/scene/control/TreeViewMouseInputTest.java
diffstat 5 files changed, 72 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TableCellBehaviorBase.java	Thu Apr 03 09:21:41 2014 +1300
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TableCellBehaviorBase.java	Thu Apr 03 10:38:48 2014 +1300
@@ -211,18 +211,7 @@
             sm.clearAndSelect(row, sm.isCellSelectionEnabled() ? column : null);
         }
 
-        // handle editing, which only occurs with the primary mouse button
-        if (button == MouseButton.PRIMARY) {
-            if (clickCount == 1 && isAlreadySelected) {
-                edit(getControl());
-            } else if (clickCount == 1) {
-                // cancel editing
-                edit(null);
-            } else if (clickCount == 2 && getControl().isEditable()) {
-                // edit at the specified row and column
-                edit(getControl());
-            }
-        }
+        handleClicks(button, clickCount, isAlreadySelected);
     }
 
     private int getColumn() {
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TableRowBehaviorBase.java	Thu Apr 03 09:21:41 2014 +1300
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TableRowBehaviorBase.java	Thu Apr 03 10:38:48 2014 +1300
@@ -32,6 +32,7 @@
 import javafx.scene.control.TableColumnBase;
 import javafx.scene.control.TablePositionBase;
 import javafx.scene.control.TableSelectionModel;
+import javafx.scene.control.TreeItem;
 import javafx.scene.input.MouseButton;
 import javafx.scene.input.MouseEvent;
 
@@ -115,9 +116,11 @@
                     final int anchorRow = anchor.getRow();
                     selectRows(anchorRow, index);
                 } else {
-                    sm.clearAndSelect(getIndex());
+                    simpleSelect(button, clickCount, shortcutDown);
                 }
             }
+        } else {
+            simpleSelect(button, clickCount, shortcutDown);
         }
     }
 
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TreeTableRowBehavior.java	Thu Apr 03 09:21:41 2014 +1300
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/behavior/TreeTableRowBehavior.java	Thu Apr 03 10:38:48 2014 +1300
@@ -32,6 +32,7 @@
 import javafx.scene.control.TreeItem;
 import javafx.scene.control.TreeTableRow;
 import javafx.scene.control.TreeTableView;
+import javafx.scene.input.MouseButton;
 
 public class TreeTableRowBehavior<T> extends TableRowBehaviorBase<TreeTableRow<T>> {
 
@@ -74,4 +75,24 @@
     @Override void edit(TreeTableRow<T> cell) {
         // no-op (for now)
     }
+
+    @Override
+    protected void handleClicks(MouseButton button, int clickCount, boolean isAlreadySelected) {
+        // handle editing, which only occurs with the primary mouse button
+        TreeItem<T> treeItem = getControl().getTreeItem();
+        if (button == MouseButton.PRIMARY) {
+            if (clickCount == 1 && isAlreadySelected) {
+                edit(getControl());
+            } else if (clickCount == 1) {
+                // cancel editing
+                edit(null);
+            } else if (clickCount == 2 && treeItem.isLeaf()) {
+                // attempt to edit
+                edit(getControl());
+            } else if (clickCount % 2 == 0) {
+                // try to expand/collapse branch tree item
+                treeItem.setExpanded(! treeItem.isExpanded());
+            }
+        }
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/TreeTableViewMouseInputTest.java	Thu Apr 03 09:21:41 2014 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/TreeTableViewMouseInputTest.java	Thu Apr 03 10:38:48 2014 +1300
@@ -626,4 +626,27 @@
         MouseEventFirer mouse = new MouseEventFirer(row);
         mouse.fireMousePressAndRelease(1, 100, 10);
     }
+
+    @Test public void test_rt_36509() {
+        final int items = 8;
+        root.getChildren().clear();
+        root.setExpanded(false);
+        for (int i = 0; i < items; i++) {
+            root.getChildren().add(new TreeItem<>("Row " + i));
+        }
+        tableView.setRoot(root);
+
+        // expand
+        assertFalse(root.isExpanded());
+        VirtualFlowTestUtils.clickOnRow(tableView, 0, 2);
+        assertTrue(root.isExpanded());
+
+        // collapse
+        VirtualFlowTestUtils.clickOnRow(tableView, 0, 2);
+        assertFalse(root.isExpanded());
+
+        // expand again
+        VirtualFlowTestUtils.clickOnRow(tableView, 0, 2);
+        assertTrue(root.isExpanded());
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/TreeViewMouseInputTest.java	Thu Apr 03 09:21:41 2014 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/TreeViewMouseInputTest.java	Thu Apr 03 10:38:48 2014 +1300
@@ -407,4 +407,27 @@
         assertFalse(sm.isSelected(4));
         assertTrue(fm.isFocused(4));
     }
+
+    @Test public void test_rt_36509() {
+        final int items = 8;
+        root.getChildren().clear();
+        root.setExpanded(false);
+        for (int i = 0; i < items; i++) {
+            root.getChildren().add(new TreeItem<>("Row " + i));
+        }
+        treeView.setRoot(root);
+
+        // expand
+        assertFalse(root.isExpanded());
+        VirtualFlowTestUtils.clickOnRow(treeView, 0, 2);
+        assertTrue(root.isExpanded());
+
+        // collapse
+        VirtualFlowTestUtils.clickOnRow(treeView, 0, 2);
+        assertFalse(root.isExpanded());
+
+        // expand again
+        VirtualFlowTestUtils.clickOnRow(treeView, 0, 2);
+        assertTrue(root.isExpanded());
+    }
 }