< prev index next >
modules/javafx.controls/src/test/java/test/javafx/scene/control/cell/TextFieldTableCellTest.java
Print this page
rev 10463 : 8089514: [TableView, TreeView, ListView, TreeTableView] Clicking outside of the edited cell, node, or entry should commit the value
@@ -1,7 +1,7 @@
/*
- * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2013, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -23,10 +23,11 @@
* questions.
*/
package test.javafx.scene.control.cell;
+import javafx.util.converter.DefaultStringConverter;
import test.com.sun.javafx.scene.control.infrastructure.MouseEventFirer;
import javafx.beans.property.ReadOnlyStringWrapper;
import javafx.collections.FXCollections;
import javafx.scene.control.TableCell;
import javafx.scene.control.TableColumn;
@@ -359,11 +360,12 @@
cell.cancelEdit();
assertFalse(cell.isEditing());
assertNull(cell.getGraphic());
}
- @Test public void test_cancelEdit_usingTableCancelEdit() {
+ @Test
+ public void test_cancelEdit_usingTableCancelEdit_nullConverter() {
TableColumn tc = new TableColumn();
TableView tableView = new TableView(FXCollections.observableArrayList("TEST"));
tableView.getColumns().add(tc);
tableView.setEditable(true);
TextFieldTableCell<Object,Object> cell = new TextFieldTableCell<>();
@@ -374,10 +376,33 @@
tableView.edit(0, tc);
assertTrue(cell.isEditing());
assertNotNull(cell.getGraphic());
+ // a null converter will mean that when editing is cancelled, the currently-editing cell
+ // will be unable to be committed as the returned value internally will be empty.
+ // Editing will stop as usual though.
+ tableView.edit(-1, null);
+ assertFalse(cell.isEditing());
+ assertNull(cell.getGraphic());
+ }
+
+ @Test public void test_cancelEdit_usingTableCancelEdit_nonNullConverter() {
+ TableColumn tc = new TableColumn();
+ TableView tableView = new TableView(FXCollections.observableArrayList("TEST"));
+ tableView.getColumns().add(tc);
+ tableView.setEditable(true);
+ TextFieldTableCell<Object,String> cell = new TextFieldTableCell<>(new DefaultStringConverter());
+ cell.updateTableView(tableView);
+ cell.updateIndex(0);
+ cell.updateTableColumn(tc);
+ cell.setEditable(true);
+
+ tableView.edit(0, tc);
+ assertTrue(cell.isEditing());
+ assertNotNull(cell.getGraphic());
+
tableView.edit(-1, null);
assertFalse(cell.isEditing());
assertNull(cell.getGraphic());
}
< prev index next >