changeset 6843:71d5359db7ee

RT-36661: [TableView] Cell selection dont work properly
author jgiles
date Tue, 22 Apr 2014 11:37:08 +1200
parents 89a9d307ec2f
children 8c3083ca5111
files modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TableRowSkinBase.java modules/controls/src/main/java/javafx/scene/control/TableCell.java
diffstat 2 files changed, 31 insertions(+), 17 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TableRowSkinBase.java	Tue Apr 22 09:24:43 2014 +1200
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/TableRowSkinBase.java	Tue Apr 22 11:37:08 2014 +1200
@@ -156,6 +156,7 @@
         // --- end init bindings
 
         registerChangeListener(control.itemProperty(), "ITEM");
+        registerChangeListener(control.indexProperty(), "INDEX");
 
         if (fixedCellSizeProperty() != null) {
             registerChangeListener(fixedCellSizeProperty(), "FIXED_CELL_SIZE");
@@ -223,20 +224,16 @@
     @Override protected void handleControlPropertyChanged(String p) {
         super.handleControlPropertyChanged(p);
 
-        if ("ITEM".equals(p)) {
-            updateCells = true;
-            getSkinnable().requestLayout();
-
-            // update the index of all children cells (RT-29849).
-            // Note that we do this after the TableRow item has been updated,
-            // rather than when the TableRow index has changed (as this will be
-            // before the row has updated its item). This will result in the
-            // issue highlighted in RT-33602, where the table cell had the correct
-            // item whilst the row had the old item.
-            final int newIndex = getSkinnable().getIndex();
-            for (int i = 0, max = cells.size(); i < max; i++) {
-                cells.get(i).updateIndex(newIndex);
+        if ("INDEX".equals(p)) {
+            // Fix for RT-36661, where empty table cells were showing content, as they
+            // had incorrect table cell indices (but the table row index was correct).
+            // Note that we only do the update on empty cells to avoid the issue
+            // noted below in requestCellUpdate().
+            if (getSkinnable().isEmpty()) {
+                requestCellUpdate();
             }
+        } else if ("ITEM".equals(p)) {
+            requestCellUpdate();
         } else if ("FIXED_CELL_SIZE".equals(p)) {
             fixedCellSize = fixedCellSizeProperty().get();
             fixedCellSizeEnabled = fixedCellSize > 0;
@@ -626,6 +623,22 @@
      *                                                                         *
      **************************************************************************/
 
+    private void requestCellUpdate() {
+        updateCells = true;
+        getSkinnable().requestLayout();
+
+        // update the index of all children cells (RT-29849).
+        // Note that we do this after the TableRow item has been updated,
+        // rather than when the TableRow index has changed (as this will be
+        // before the row has updated its item). This will result in the
+        // issue highlighted in RT-33602, where the table cell had the correct
+        // item whilst the row had the old item.
+        final int newIndex = getSkinnable().getIndex();
+        for (int i = 0, max = cells.size(); i < max; i++) {
+            cells.get(i).updateIndex(newIndex);
+        }
+    }
+
     private void recreateCells() {
         // This function is smart in the sense that we don't recreate all
         // TableCell instances every time this function is called. Instead we
--- a/modules/controls/src/main/java/javafx/scene/control/TableCell.java	Tue Apr 22 09:24:43 2014 +1200
+++ b/modules/controls/src/main/java/javafx/scene/control/TableCell.java	Tue Apr 22 11:37:08 2014 +1200
@@ -505,13 +505,14 @@
         }
 
         final TableView<S> tableView = getTableView();
-        if (getIndex() == -1 || tableView == null) return;
+        final TableRow<S> tableRow = getTableRow();
+        final int index = getIndex();
+        if (index == -1 || tableView == null || tableRow == null) return;
 
         final TableViewFocusModel<S> fm = tableView.getFocusModel();
         if (fm == null) return;
-        
-        boolean isFocusedNow = fm != null &&
-                            fm.isFocused(getIndex(), getTableColumn());
+
+        boolean isFocusedNow = fm != null && fm.isFocused(index, getTableColumn());
 
         setFocused(isFocusedNow);
     }