diff --git a/modules/controls/src/main/java/javafx/scene/control/Cell.java b/modules/controls/src/main/java/javafx/scene/control/Cell.java --- a/modules/controls/src/main/java/javafx/scene/control/Cell.java +++ b/modules/controls/src/main/java/javafx/scene/control/Cell.java @@ -640,7 +640,6 @@ * @expert */ protected void updateItem(T item, boolean empty) { - if (isEditing()) cancelEdit(); setItem(item); setEmpty(empty); if (empty && isSelected()) { diff --git a/modules/controls/src/test/java/javafx/scene/control/CellTest.java b/modules/controls/src/test/java/javafx/scene/control/CellTest.java --- a/modules/controls/src/test/java/javafx/scene/control/CellTest.java +++ b/modules/controls/src/test/java/javafx/scene/control/CellTest.java @@ -54,7 +54,9 @@ {ListCell.class}, {TableRow.class}, {TableCell.class}, - {TreeCell.class} + {TreeCell.class}, +// {TreeTableRow.class}, +// {TreeTableCell.class} }); } @@ -75,6 +77,12 @@ TableRow tableRow = new TableRow(); tableRow.updateItem("TableRow", false); ((TableCell)cell).updateTableRow(tableRow); + ((TableCell)cell).lockItemOnEdit = true; + } else if (cell instanceof TreeTableCell) { + TreeTableRow tableRow = new TreeTableRow(); + tableRow.updateItem("TableRow", false); + ((TreeTableCell)cell).updateTreeTableRow(tableRow); +// ((TreeTableCell)cell).lockItemOnEdit = true; } } @@ -215,30 +223,34 @@ * Tests for editing * ********************************************************************/ - public void editingAnEmptyCellResultsInNoChange() { + @Test public void editingAnEmptyCellResultsInNoChange() { cell.startEdit(); assertFalse(cell.isEditing()); } - public void editingAnEmptyCellResultsInNoChange2() { + @Test public void editingAnEmptyCellResultsInNoChange2() { cell.updateItem(null, false); cell.updateItem(null, true); cell.startEdit(); assertFalse(cell.isEditing()); } - @Test public void updatingACellBeingEditedResultsInFirstACancelOfEdit() { + @Test public void updatingACellBeingEditedDoesNotResultInACancelOfEdit() { cell.updateItem("Apples", false); cell.startEdit(); + assertFalse(cell.isEmpty()); + assertTrue(cell.isEditing()); cell.updateItem("Oranges", false); - assertFalse(cell.isEditing()); + assertTrue(cell.isEditing()); } - @Test public void updatingACellBeingEditedResultsInFirstACancelOfEdit2() { + @Test public void updatingACellBeingEditedDoesNotResultInACancelOfEdit2() { cell.updateItem("Apples", false); cell.startEdit(); + assertFalse(cell.isEmpty()); + assertTrue(cell.isEditing()); cell.updateItem(null, true); - assertFalse(cell.isEditing()); + assertTrue(cell.isEditing()); } @Test public void startEditWhenEditableIsTrue() { diff --git a/modules/controls/src/test/java/javafx/scene/control/DateCellTest.java b/modules/controls/src/test/java/javafx/scene/control/DateCellTest.java --- a/modules/controls/src/test/java/javafx/scene/control/DateCellTest.java +++ b/modules/controls/src/test/java/javafx/scene/control/DateCellTest.java @@ -200,18 +200,18 @@ assertFalse(cell.isEditing()); } - @Test public void updatingACellBeingEditedResultsInFirstACancelOfEdit() { + @Test public void updatingACellBeingEditedDoesNotResultInACancelOfEdit() { cell.updateItem(today, false); cell.startEdit(); cell.updateItem(tomorrow, false); - assertFalse(cell.isEditing()); + assertTrue(cell.isEditing()); } @Test public void updatingACellBeingEditedResultsInFirstACancelOfEdit2() { cell.updateItem(today, false); cell.startEdit(); cell.updateItem(null, true); - assertFalse(cell.isEditing()); + assertTrue(cell.isEditing()); } @Test public void startEditWhenEditableIsTrue() { diff --git a/modules/controls/src/test/java/javafx/scene/control/ListViewTest.java b/modules/controls/src/test/java/javafx/scene/control/ListViewTest.java --- a/modules/controls/src/test/java/javafx/scene/control/ListViewTest.java +++ b/modules/controls/src/test/java/javafx/scene/control/ListViewTest.java @@ -46,6 +46,7 @@ import javafx.beans.value.ObservableValue; import javafx.collections.FXCollections; import javafx.collections.ObservableList; +import javafx.event.ActionEvent; import javafx.event.Event; import javafx.event.EventHandler; import javafx.scene.control.cell.CheckBoxListCell; @@ -807,4 +808,33 @@ listView.setItems(FXCollections.observableArrayList(data)); assertEquals("bbc", listView.getSelectionModel().getSelectedItem()); } + + private int rt_35889_cancel_count = 0; + @Test public void test_rt35889() { + final ListView textFieldListView = new ListView(); + textFieldListView.setItems(FXCollections.observableArrayList("A", "B", "C")); + textFieldListView.setEditable(true); + textFieldListView.setCellFactory(TextFieldListCell.forListView()); + textFieldListView.setOnEditCancel(new EventHandler>() { + @Override public void handle(ListView.EditEvent t) { + rt_35889_cancel_count++; + System.out.println("On Edit Cancel: " + t); + } + }); + + ListCell cell0 = (ListCell) VirtualFlowTestUtils.getCell(textFieldListView, 0); + assertNull(cell0.getGraphic()); + assertEquals("A", cell0.getText()); + + textFieldListView.edit(0); + TextField textField = (TextField) cell0.getGraphic(); + assertNotNull(textField); + + assertEquals(0, rt_35889_cancel_count); + + textField.setText("Z"); + textField.getOnAction().handle(new ActionEvent()); + + assertEquals(0, rt_35889_cancel_count); + } } diff --git a/modules/controls/src/test/java/javafx/scene/control/TreeViewTest.java b/modules/controls/src/test/java/javafx/scene/control/TreeViewTest.java --- a/modules/controls/src/test/java/javafx/scene/control/TreeViewTest.java +++ b/modules/controls/src/test/java/javafx/scene/control/TreeViewTest.java @@ -53,6 +53,7 @@ import javafx.collections.FXCollections; import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; +import javafx.event.ActionEvent; import javafx.event.Event; import javafx.event.EventHandler; import javafx.scene.Group; @@ -1648,4 +1649,38 @@ root.getChildren().setAll(aabbaa, bbc); assertEquals("bbc", treeView.getSelectionModel().getSelectedItem().getValue()); } + + private int rt_35889_cancel_count = 0; + @Test public void test_rt35889() { + TreeItem a = new TreeItem("a"); + TreeItem b = new TreeItem("b"); + TreeItem root = new TreeItem<>("Root"); + root.setExpanded(true); + root.getChildren().setAll(a, b); + + final TreeView textFieldTreeView = new TreeView(root); + textFieldTreeView.setEditable(true); + textFieldTreeView.setCellFactory(TextFieldTreeCell.forTreeView()); + textFieldTreeView.setOnEditCancel(new EventHandler>() { + @Override public void handle(TreeView.EditEvent t) { + rt_35889_cancel_count++; + System.out.println("On Edit Cancel: " + t); + } + }); + + TreeCell cell0 = (TreeCell) VirtualFlowTestUtils.getCell(textFieldTreeView, 0); + assertNull(cell0.getGraphic()); + assertEquals("Root", cell0.getText()); + + textFieldTreeView.edit(root); + TextField textField = (TextField) cell0.getGraphic(); + assertNotNull(textField); + + assertEquals(0, rt_35889_cancel_count); + + textField.setText("Z"); + textField.getOnAction().handle(new ActionEvent()); + + assertEquals(0, rt_35889_cancel_count); + } }