changeset 269:6beb94343169

RT-18786: TableView.edit(int,tableColumn) method is not working in the JavaFx 2.1 b07
author jgiles
date Tue, 17 Jan 2012 15:22:02 +1300
parents 8181c2557b4c
children e3a4425e79e6
files javafx-ui-controls/src/javafx/scene/control/TableCell.java
diffstat 1 files changed, 15 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/javafx/scene/control/TableCell.java	Tue Jan 17 11:43:56 2012 +1300
+++ b/javafx-ui-controls/src/javafx/scene/control/TableCell.java	Tue Jan 17 15:22:02 2012 +1300
@@ -358,7 +358,7 @@
         // reset the editing index on the TableView
         if (table != null) {
             TablePosition editingCell = table.getEditingCell();
-            table.edit(-1, null);
+            if (updateEditingIndex) table.edit(-1, null);
 
             CellEditEvent editEvent = new CellEditEvent(
                 table,
@@ -451,14 +451,23 @@
         if (getIndex() == -1 || getTableView() == null) return;
 
         TablePosition editCell = getTableView().getEditingCell();
-        if (! isEditing()) {
-            if (match(editCell)) {
-                startEdit();
-            }
-        } else {
+        boolean match = match(editCell);
+        
+        if (match && ! isEditing()) {
+            startEdit();
+        } else if (! match && isEditing()) {
+            // If my index is not the one being edited then I need to cancel
+            // the edit. The tricky thing here is that as part of this call
+            // I cannot end up calling list.edit(-1) the way that the standard
+            // cancelEdit method would do. Yet, I need to call cancelEdit
+            // so that subclasses which override cancelEdit can execute. So,
+            // I have to use a kind of hacky flag workaround.
+            updateEditingIndex = false;
             cancelEdit();
+            updateEditingIndex = true;
         }
     }
+    private boolean updateEditingIndex = true;
 
     private boolean match(TablePosition pos) {
         return pos != null && pos.getRow() == getIndex() && pos.getTableColumn() == getTableColumn();