< prev index next >

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

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

*** 335,364 **** /** {@inheritDoc} */ @Override public void commitEdit(T newValue) { if (! isEditing()) return; final TableView<S> table = getTableView(); if (table != null) { // Inform the TableView of the edit being ready to be committed. CellEditEvent editEvent = new CellEditEvent( table, ! table.getEditingCell(), TableColumn.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 --- 335,364 ---- /** {@inheritDoc} */ @Override public void commitEdit(T newValue) { if (! isEditing()) return; + // 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); + final TableView<S> table = getTableView(); if (table != null) { // Inform the TableView of the edit being ready to be committed. CellEditEvent editEvent = new CellEditEvent( table, ! new TablePosition<>(getTableView(), getIndex(), getTableColumn()), TableColumn.editCommitEvent(), newValue ); Event.fireEvent(getTableColumn(), editEvent); } // 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
*** 381,391 **** super.cancelEdit(); // reset the editing index on the TableView if (table != null) { TablePosition<S,?> editingCell = table.getEditingCell(); ! if (updateEditingIndex) table.edit(-1, null); // request focus back onto the table, only if the current focus // owner has the table as a parent (otherwise the user might have // clicked out of the table entirely and given focus to something else. // It would be rude of us to request it back again. --- 381,391 ---- super.cancelEdit(); // reset the editing index on the TableView if (table != null) { TablePosition<S,?> editingCell = table.getEditingCell(); ! table.edit(-1, null); // request focus back onto the table, only if the current focus // owner has the table as a parent (otherwise the user might have // clicked out of the table entirely and given focus to something else. // It would be rude of us to request it back again.
*** 550,576 **** private void updateEditing() { if (getIndex() == -1 || getTableView() == null) return; TablePosition<S,?> editCell = getTableView().getEditingCell(); 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<S,?> pos) { return pos != null && pos.getRow() == getIndex() && pos.getTableColumn() == getTableColumn(); } --- 550,568 ---- private void updateEditing() { if (getIndex() == -1 || getTableView() == null) return; TablePosition<S,?> editCell = getTableView().getEditingCell(); + boolean match = match(editCell); if (match && ! isEditing()) { startEdit(); } else if (! match && isEditing()) { ! attemptEditCommit(); } } private boolean match(TablePosition<S,?> pos) { return pos != null && pos.getRow() == getIndex() && pos.getTableColumn() == getTableColumn(); }
< prev index next >