< prev index next >
modules/javafx.controls/src/main/java/javafx/scene/control/ListCell.java
Print this page
rev 10463 : 8089514: [TableView, TreeView, ListView, TreeTableView] Clicking outside of the edited cell, node, or entry should commit the value
@@ -106,11 +106,10 @@
* on our side.
*/
private final InvalidationListener editingListener = value -> {
updateEditing();
};
- private boolean updateEditingIndex = true;
/**
* Listens to the selection model on the ListView. Whenever the selection model
* is changed (updated), the selected property on the ListCell is updated accordingly.
*/
@@ -226,10 +225,12 @@
private final WeakListChangeListener<T> weakItemsListener = new WeakListChangeListener<T>(itemsListener);
private final WeakInvalidationListener weakItemsPropertyListener = new WeakInvalidationListener(itemsPropertyListener);
private final WeakInvalidationListener weakFocusedListener = new WeakInvalidationListener(focusedListener);
private final WeakChangeListener<FocusModel<T>> weakFocusModelPropertyListener = new WeakChangeListener<FocusModel<T>>(focusModelPropertyListener);
+
+
/***************************************************************************
* *
* Properties *
* *
**************************************************************************/
@@ -323,24 +324,25 @@
/** {@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
// will not change to the editing state as a layout of VirtualFlow
// is immediately invoked, which forces all cells to be updated.
} else {
updateItem(oldIndex);
+ }
+
updateSelection();
updateFocus();
}
- }
/** {@inheritDoc} */
@Override protected Skin<?> createDefaultSkin() {
return new ListCellSkin<T>(this);
}
@@ -367,36 +369,36 @@
// Inform the ListView of the edit starting.
if (list != null) {
list.fireEvent(new ListView.EditEvent<T>(list,
ListView.<T>editStartEvent(),
null,
- list.getEditingIndex()));
+ getIndex()));
list.edit(getIndex());
list.requestFocus();
}
}
/** {@inheritDoc} */
@Override public void commitEdit(T newValue) {
if (! isEditing()) return;
ListView<T> list = getListView();
- if (list != null) {
- // Inform the ListView of the edit being ready to be committed.
- list.fireEvent(new ListView.EditEvent<T>(list,
- ListView.<T>editCommitEvent(),
- newValue,
- list.getEditingIndex()));
- }
-
// 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 (list != null) {
+ // Inform the ListView of the edit being ready to be committed.
+ list.fireEvent(new ListView.EditEvent<T>(list,
+ ListView.editCommitEvent(),
+ newValue,
+ getIndex()));
+ }
+
// update the item within this cell, so that it represents the new value
updateItem(newValue, false);
if (list != null) {
// reset the editing index on the ListView. This must come after the
@@ -421,25 +423,23 @@
ListView<T> list = getListView();
super.cancelEdit();
if (list != null) {
- int editingIndex = list.getEditingIndex();
-
// reset the editing index on the ListView
- if (updateEditingIndex) list.edit(-1);
+ list.edit(-1);
// request focus back onto the list, only if the current focus
// owner has the list as a parent (otherwise the user might have
// clicked out of the list entirely and given focus to something else.
// It would be rude of us to request it back again.
ControlUtils.requestFocusOnControlOnlyIfCurrentFocusOwnerIsChild(list);
list.fireEvent(new ListView.EditEvent<T>(list,
ListView.<T>editCancelEvent(),
null,
- editingIndex));
+ getIndex()));
}
}
/* *************************************************************************
@@ -545,19 +545,11 @@
// If my index is the index being edited and I'm not currently in
// the edit mode, then I need to enter the edit mode
if (index == editIndex && !editing) {
startEdit();
} else if (index != editIndex && editing) {
- // 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();
}
}
}
< prev index next >