changeset 6348:53fde3ac0336

RT-35889: HelloListView: Cell Editing
author jgiles
date Mon, 24 Feb 2014 10:20:39 +1300
parents 717abe6489a8
children 89603b0381ec
files modules/controls/src/main/java/javafx/scene/control/Cell.java modules/controls/src/test/java/javafx/scene/control/CellTest.java modules/controls/src/test/java/javafx/scene/control/DateCellTest.java modules/controls/src/test/java/javafx/scene/control/ListViewTest.java modules/controls/src/test/java/javafx/scene/control/TreeViewTest.java
diffstat 5 files changed, 87 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/javafx/scene/control/Cell.java	Mon Feb 24 10:19:17 2014 +1300
+++ b/modules/controls/src/main/java/javafx/scene/control/Cell.java	Mon Feb 24 10:20:39 2014 +1300
@@ -640,7 +640,6 @@
      * @expert
      */
     protected void updateItem(T item, boolean empty) {
-        if (isEditing()) cancelEdit();
         setItem(item);
         setEmpty(empty);
         if (empty && isSelected()) {
--- a/modules/controls/src/test/java/javafx/scene/control/CellTest.java	Mon Feb 24 10:19:17 2014 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/CellTest.java	Mon Feb 24 10:20:39 2014 +1300
@@ -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() {
--- a/modules/controls/src/test/java/javafx/scene/control/DateCellTest.java	Mon Feb 24 10:19:17 2014 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/DateCellTest.java	Mon Feb 24 10:20:39 2014 +1300
@@ -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() {
--- a/modules/controls/src/test/java/javafx/scene/control/ListViewTest.java	Mon Feb 24 10:19:17 2014 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/ListViewTest.java	Mon Feb 24 10:20:39 2014 +1300
@@ -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<String> textFieldListView = new ListView<String>();
+        textFieldListView.setItems(FXCollections.observableArrayList("A", "B", "C"));
+        textFieldListView.setEditable(true);
+        textFieldListView.setCellFactory(TextFieldListCell.forListView());
+        textFieldListView.setOnEditCancel(new EventHandler<ListView.EditEvent<String>>() {
+            @Override public void handle(ListView.EditEvent<String> 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);
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/TreeViewTest.java	Mon Feb 24 10:19:17 2014 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/TreeViewTest.java	Mon Feb 24 10:20:39 2014 +1300
@@ -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<String> root = new TreeItem<>("Root");
+        root.setExpanded(true);
+        root.getChildren().setAll(a, b);
+
+        final TreeView<String> textFieldTreeView = new TreeView<String>(root);
+        textFieldTreeView.setEditable(true);
+        textFieldTreeView.setCellFactory(TextFieldTreeCell.forTreeView());
+        textFieldTreeView.setOnEditCancel(new EventHandler<TreeView.EditEvent<String>>() {
+            @Override public void handle(TreeView.EditEvent<String> 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);
+    }
 }