< prev index next >

modules/javafx.controls/src/main/java/javafx/scene/control/TreeTableCell.java

Print this page
rev 10463 : 8089514: [TableView, TreeView, ListView, TreeTableView] Clicking outside of the edited cell, node, or entry should commit the value

@@ -339,32 +339,31 @@
     /** {@inheritDoc} */
     @Override public void commitEdit(T newValue) {
         if (! isEditing()) return;
 
         final TreeTableView<S> table = getTreeTableView();
+
+        // inform parent classes of the commit, so that they can switch us
+        // out of the editing state.
+        // This MUST come before the updateItem call below, otherwise it will
+        // call cancelEdit(), resulting in both commit and cancel events being
+        // fired (as identified in RT-29650)
+        super.commitEdit(newValue);
+
         if (table != null) {
             @SuppressWarnings("unchecked")
-            TreeTablePosition<S,T> editingCell = (TreeTablePosition<S,T>) table.getEditingCell();
-
-            // Inform the TableView of the edit being ready to be committed.
+            // Inform the TreeTableView of the edit being ready to be committed.
             CellEditEvent<S,T> editEvent = new CellEditEvent<S,T>(
                 table,
-                editingCell,
+                    new TreeTablePosition<>(getTreeTableView(), getIndex(), getTableColumn()),
                 TreeTableColumn.<S,T>editCommitEvent(),
                 newValue
             );
 
             Event.fireEvent(getTableColumn(), editEvent);
         }
 
-        // inform parent classes of the commit, so that they can switch us
-        // out of the editing state.
-        // This MUST come before the updateItem call below, otherwise it will
-        // call cancelEdit(), resulting in both commit and cancel events being
-        // fired (as identified in RT-29650)
-        super.commitEdit(newValue);
-
         // update the item within this cell, so that it represents the new value
         updateItem(newValue, false);
 
         if (table != null) {
             // reset the editing cell on the TableView

@@ -438,11 +437,11 @@
 
     /** {@inheritDoc} */
     @Override void indexChanged(int oldIndex, int newIndex) {
         super.indexChanged(oldIndex, newIndex);
 
-        if (isEditing() && newIndex == oldIndex) {
+        if (isEditing()) {
             // no-op
             // Fix for RT-31165 - if we (needlessly) update the index whilst the
             // cell is being edited it will no longer be in an editing state.
             // This means that in certain (common) circumstances that it will
             // appear that a cell is uneditable as, despite being clicked, it

@@ -453,14 +452,15 @@
             // than the updateItem() call beneath, but if we do this we end up with
             // RT-22428 where all the columns are collapsed.
             // itemDirty = true;
             // requestLayout();
             updateItem(oldIndex);
-            updateSelection();
-            updateFocus();
             updateEditing();
         }
+
+        updateSelection();
+        updateFocus();
     }
 
     private boolean isLastVisibleColumn = false;
     private int columnIndex = -1;
 

@@ -541,19 +541,11 @@
         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;
+            attemptEditCommit();
         }
     }
     private boolean updateEditingIndex = true;
 
     private boolean match(TreeTablePosition pos) {
< prev index next >