changeset 5259:006b0519158b

RT-29320: ChoiceBoxTableCell ChoiceBox does not use TableCell's StringConverter
author jgiles
date Thu, 03 Oct 2013 12:50:01 +1300
parents 50b282551554
children a217f67b7af6
files modules/controls/src/main/java/javafx/scene/control/cell/CellUtils.java modules/controls/src/main/java/javafx/scene/control/cell/ChoiceBoxListCell.java modules/controls/src/main/java/javafx/scene/control/cell/ChoiceBoxTableCell.java modules/controls/src/main/java/javafx/scene/control/cell/ChoiceBoxTreeCell.java modules/controls/src/main/java/javafx/scene/control/cell/ChoiceBoxTreeTableCell.java modules/controls/src/main/java/javafx/scene/control/cell/ComboBoxListCell.java modules/controls/src/main/java/javafx/scene/control/cell/ComboBoxTableCell.java modules/controls/src/main/java/javafx/scene/control/cell/ComboBoxTreeCell.java modules/controls/src/main/java/javafx/scene/control/cell/ComboBoxTreeTableCell.java modules/controls/src/test/java/javafx/scene/control/cell/ChoiceBoxListCellTest.java modules/controls/src/test/java/javafx/scene/control/cell/ChoiceBoxTableCellTest.java modules/controls/src/test/java/javafx/scene/control/cell/ChoiceBoxTreeCellTest.java modules/controls/src/test/java/javafx/scene/control/cell/ChoiceBoxTreeTableCellTest.java modules/controls/src/test/java/javafx/scene/control/cell/ComboBoxListCellTest.java modules/controls/src/test/java/javafx/scene/control/cell/ComboBoxTableCellTest.java modules/controls/src/test/java/javafx/scene/control/cell/ComboBoxTreeCellTest.java modules/controls/src/test/java/javafx/scene/control/cell/ComboBoxTreeTableCellTest.java
diffstat 17 files changed, 263 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/javafx/scene/control/cell/CellUtils.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/main/java/javafx/scene/control/cell/CellUtils.java	Thu Oct 03 12:50:01 2013 +1300
@@ -25,6 +25,7 @@
 
 package javafx.scene.control.cell;
 
+import javafx.beans.property.ObjectProperty;
 import javafx.beans.value.ChangeListener;
 import javafx.beans.value.ObservableValue;
 import javafx.collections.ObservableList;
@@ -149,10 +150,12 @@
     };
     
     static <T> ChoiceBox<T> createChoiceBox(
-            final Cell<T> cell, 
-            final ObservableList<T> items) {
+            final Cell<T> cell,
+            final ObservableList<T> items,
+            final ObjectProperty<StringConverter<T>> converter) {
         ChoiceBox<T> choiceBox = new ChoiceBox<T>(items);
         choiceBox.setMaxWidth(Double.MAX_VALUE);
+        choiceBox.converterProperty().bind(converter);
         choiceBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<T>() {
             @Override
             public void changed(ObservableValue<? extends T> ov, T oldValue, T newValue) {
@@ -291,9 +294,11 @@
         }
     };
     
-    static <T> ComboBox<T> createComboBox(final Cell<T> cell, final ObservableList<T> items, final StringConverter<T> converter) {
+    static <T> ComboBox<T> createComboBox(final Cell<T> cell,
+                                          final ObservableList<T> items,
+                                          final ObjectProperty<StringConverter<T>> converter) {
         ComboBox<T> comboBox = new ComboBox<T>(items);
-        comboBox.setConverter(converter);
+        comboBox.converterProperty().bind(converter);
         comboBox.setMaxWidth(Double.MAX_VALUE);
         comboBox.getSelectionModel().selectedItemProperty().addListener(new ChangeListener<T>() {
             @Override public void changed(ObservableValue<? extends T> ov, T oldValue, T newValue) {
--- a/modules/controls/src/main/java/javafx/scene/control/cell/ChoiceBoxListCell.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/main/java/javafx/scene/control/cell/ChoiceBoxListCell.java	Thu Oct 03 12:50:01 2013 +1300
@@ -289,7 +289,7 @@
         }
         
         if (choiceBox == null) {
-            choiceBox = createChoiceBox(this, items);
+            choiceBox = createChoiceBox(this, items, converterProperty());
         }
         
         choiceBox.getSelectionModel().select(getItem());
--- a/modules/controls/src/main/java/javafx/scene/control/cell/ChoiceBoxTableCell.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/main/java/javafx/scene/control/cell/ChoiceBoxTableCell.java	Thu Oct 03 12:50:01 2013 +1300
@@ -299,7 +299,7 @@
         }
         
         if (choiceBox == null) {
-            choiceBox = createChoiceBox(this, items);
+            choiceBox = createChoiceBox(this, items, converterProperty());
         }
         
         choiceBox.getSelectionModel().select(getItem());
--- a/modules/controls/src/main/java/javafx/scene/control/cell/ChoiceBoxTreeCell.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/main/java/javafx/scene/control/cell/ChoiceBoxTreeCell.java	Thu Oct 03 12:50:01 2013 +1300
@@ -300,7 +300,7 @@
         }
 
         if (choiceBox == null) {
-            choiceBox = createChoiceBox(this, items);
+            choiceBox = createChoiceBox(this, items, converterProperty());
         }
         if (hbox == null) {
             hbox = new HBox(CellUtils.TREE_VIEW_HBOX_GRAPHIC_PADDING);
--- a/modules/controls/src/main/java/javafx/scene/control/cell/ChoiceBoxTreeTableCell.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/main/java/javafx/scene/control/cell/ChoiceBoxTreeTableCell.java	Thu Oct 03 12:50:01 2013 +1300
@@ -299,7 +299,7 @@
         }
         
         if (choiceBox == null) {
-            choiceBox = createChoiceBox(this, items);
+            choiceBox = createChoiceBox(this, items, converterProperty());
         }
         
         choiceBox.getSelectionModel().select(getItem());
--- a/modules/controls/src/main/java/javafx/scene/control/cell/ComboBoxListCell.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/main/java/javafx/scene/control/cell/ComboBoxListCell.java	Thu Oct 03 12:50:01 2013 +1300
@@ -316,7 +316,7 @@
         }
         
         if (comboBox == null) {
-            comboBox = createComboBox(this, items, getConverter());
+            comboBox = createComboBox(this, items, converterProperty());
             comboBox.editableProperty().bind(comboBoxEditableProperty());
         }
         
--- a/modules/controls/src/main/java/javafx/scene/control/cell/ComboBoxTableCell.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/main/java/javafx/scene/control/cell/ComboBoxTableCell.java	Thu Oct 03 12:50:01 2013 +1300
@@ -331,7 +331,7 @@
         }
         
         if (comboBox == null) {
-            comboBox = createComboBox(this, items, getConverter());
+            comboBox = createComboBox(this, items, converterProperty());
             comboBox.editableProperty().bind(comboBoxEditableProperty());
         }
         
--- a/modules/controls/src/main/java/javafx/scene/control/cell/ComboBoxTreeCell.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/main/java/javafx/scene/control/cell/ComboBoxTreeCell.java	Thu Oct 03 12:50:01 2013 +1300
@@ -328,7 +328,7 @@
         }
 
         if (comboBox == null) {
-            comboBox = createComboBox(this, items, getConverter());
+            comboBox = createComboBox(this, items, converterProperty());
             comboBox.editableProperty().bind(comboBoxEditableProperty());
         }
         if (hbox == null) {
--- a/modules/controls/src/main/java/javafx/scene/control/cell/ComboBoxTreeTableCell.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/main/java/javafx/scene/control/cell/ComboBoxTreeTableCell.java	Thu Oct 03 12:50:01 2013 +1300
@@ -331,7 +331,7 @@
         }
         
         if (comboBox == null) {
-            comboBox = createComboBox(this, items, getConverter());
+            comboBox = createComboBox(this, items, converterProperty());
             comboBox.editableProperty().bind(comboBoxEditableProperty());
         }
         
--- a/modules/controls/src/test/java/javafx/scene/control/cell/ChoiceBoxListCellTest.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/cell/ChoiceBoxListCellTest.java	Thu Oct 03 12:50:01 2013 +1300
@@ -27,6 +27,7 @@
 
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
+import javafx.scene.control.ChoiceBox;
 import javafx.scene.control.ListCell;
 import javafx.scene.control.ListView;
 import javafx.util.Callback;
@@ -341,4 +342,32 @@
         assertFalse(cell.isEditing());
         assertNull(cell.getGraphic());
     }
+
+    @Test public void test_rt_29320() {
+        ListView listView = new ListView();
+        listView.setEditable(true);
+        ChoiceBoxListCell<Object> cell = new ChoiceBoxListCell<>();
+        cell.updateListView(listView);
+        cell.updateItem("TEST", false);
+        cell.setEditable(true);
+
+        cell.startEdit();
+        ChoiceBox cb = (ChoiceBox) cell.getGraphic();
+
+        // initially the choiceBox converter should equal the cell converter
+        assertNotNull(cell.getConverter());
+        assertNotNull(cb.getConverter());
+        assertEquals(cell.getConverter(), cb.getConverter());
+
+        // and if the cell changes the choicebox should follow
+        cell.setConverter(null);
+        assertNull(cb.getConverter());
+
+        StringConverter<Object> customConverter = new StringConverter<Object>() {
+            @Override public String toString(Object object) { return null; }
+            @Override public Object fromString(String string) { return null; }
+        };
+        cell.setConverter(customConverter);
+        assertEquals(customConverter, cb.getConverter());
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/cell/ChoiceBoxTableCellTest.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/cell/ChoiceBoxTableCellTest.java	Thu Oct 03 12:50:01 2013 +1300
@@ -27,6 +27,7 @@
 
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
+import javafx.scene.control.ChoiceBox;
 import javafx.scene.control.TableCell;
 import javafx.scene.control.TableColumn;
 import javafx.scene.control.TableView;
@@ -417,4 +418,35 @@
         assertFalse(cell.isEditing());
         assertNull(cell.getGraphic());
     }
+
+    @Test public void test_rt_29320() {
+        TableColumn tc = new TableColumn();
+        TableView tableView = new TableView(FXCollections.observableArrayList("TEST"));
+        tableView.getColumns().add(tc);
+        tableView.setEditable(true);
+        ChoiceBoxTableCell<Object,Object> cell = new ChoiceBoxTableCell<>();
+        cell.updateTableView(tableView);
+        cell.updateIndex(0);
+        cell.updateTableColumn(tc);
+        cell.setEditable(true);
+
+        tableView.edit(0, tc);
+        ChoiceBox cb = (ChoiceBox) cell.getGraphic();
+
+        // initially the choiceBox converter should equal the cell converter
+        assertNotNull(cell.getConverter());
+        assertNotNull(cb.getConverter());
+        assertEquals(cell.getConverter(), cb.getConverter());
+
+        // and if the cell changes the choicebox should follow
+        cell.setConverter(null);
+        assertNull(cb.getConverter());
+
+        StringConverter<Object> customConverter = new StringConverter<Object>() {
+            @Override public String toString(Object object) { return null; }
+            @Override public Object fromString(String string) { return null; }
+        };
+        cell.setConverter(customConverter);
+        assertEquals(customConverter, cb.getConverter());
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/cell/ChoiceBoxTreeCellTest.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/cell/ChoiceBoxTreeCellTest.java	Thu Oct 03 12:50:01 2013 +1300
@@ -27,6 +27,7 @@
 
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
+import javafx.scene.control.ChoiceBox;
 import javafx.scene.control.TreeCell;
 import javafx.scene.control.TreeItem;
 import javafx.scene.control.TreeView;
@@ -346,4 +347,33 @@
         assertFalse(cell.isEditing());
         assertNull(cell.getGraphic());
     }
+
+    @Test public void test_rt_29320() {
+        TreeItem root = new TreeItem("Root");
+        TreeView treeView = new TreeView(root);
+        treeView.setEditable(true);
+        ChoiceBoxTreeCell<Object> cell = new ChoiceBoxTreeCell<>();
+        cell.updateTreeView(treeView);
+        cell.updateIndex(0);
+        cell.setEditable(true);
+
+        cell.startEdit();
+        ChoiceBox cb = (ChoiceBox) cell.getGraphic();
+
+        // initially the choiceBox converter should equal the cell converter
+        assertNotNull(cell.getConverter());
+        assertNotNull(cb.getConverter());
+        assertEquals(cell.getConverter(), cb.getConverter());
+
+        // and if the cell changes the choicebox should follow
+        cell.setConverter(null);
+        assertNull(cb.getConverter());
+
+        StringConverter<Object> customConverter = new StringConverter<Object>() {
+            @Override public String toString(Object object) { return null; }
+            @Override public Object fromString(String string) { return null; }
+        };
+        cell.setConverter(customConverter);
+        assertEquals(customConverter, cb.getConverter());
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/cell/ChoiceBoxTreeTableCellTest.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/cell/ChoiceBoxTreeTableCellTest.java	Thu Oct 03 12:50:01 2013 +1300
@@ -27,10 +27,7 @@
 
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
-import javafx.scene.control.TreeItem;
-import javafx.scene.control.TreeTableCell;
-import javafx.scene.control.TreeTableColumn;
-import javafx.scene.control.TreeTableView;
+import javafx.scene.control.*;
 import javafx.util.Callback;
 import javafx.util.StringConverter;
 import org.junit.Before;
@@ -418,4 +415,35 @@
         assertFalse(cell.isEditing());
         assertNull(cell.getGraphic());
     }
+
+    @Test public void test_rt_29320() {
+        TreeTableColumn tc = new TreeTableColumn();
+        TreeTableView tableView = new TreeTableView(new TreeItem("TEST"));
+        tableView.getColumns().add(tc);
+        tableView.setEditable(true);
+        ChoiceBoxTreeTableCell<Object,Object> cell = new ChoiceBoxTreeTableCell<>();
+        cell.updateTreeTableView(tableView);
+        cell.updateIndex(0);
+        cell.updateTreeTableColumn(tc);
+        cell.setEditable(true);
+
+        tableView.edit(0, tc);
+        ChoiceBox cb = (ChoiceBox) cell.getGraphic();
+
+        // initially the choiceBox converter should equal the cell converter
+        assertNotNull(cell.getConverter());
+        assertNotNull(cb.getConverter());
+        assertEquals(cell.getConverter(), cb.getConverter());
+
+        // and if the cell changes the choicebox should follow
+        cell.setConverter(null);
+        assertNull(cb.getConverter());
+
+        StringConverter<Object> customConverter = new StringConverter<Object>() {
+            @Override public String toString(Object object) { return null; }
+            @Override public Object fromString(String string) { return null; }
+        };
+        cell.setConverter(customConverter);
+        assertEquals(customConverter, cb.getConverter());
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/cell/ComboBoxListCellTest.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/cell/ComboBoxListCellTest.java	Thu Oct 03 12:50:01 2013 +1300
@@ -27,6 +27,7 @@
 
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
+import javafx.scene.control.ComboBox;
 import javafx.scene.control.ListCell;
 import javafx.scene.control.ListView;
 import javafx.util.Callback;
@@ -341,4 +342,32 @@
         assertFalse(cell.isEditing());
         assertNull(cell.getGraphic());
     }
+
+    @Test public void test_rt_29320() {
+        ListView listView = new ListView();
+        listView.setEditable(true);
+        ComboBoxListCell<Object> cell = new ComboBoxListCell<>();
+        cell.updateListView(listView);
+        cell.updateItem("TEST", false);
+        cell.setEditable(true);
+
+        cell.startEdit();
+        ComboBox cb = (ComboBox) cell.getGraphic();
+
+        // initially the choiceBox converter should equal the cell converter
+        assertNotNull(cell.getConverter());
+        assertNotNull(cb.getConverter());
+        assertEquals(cell.getConverter(), cb.getConverter());
+
+        // and if the cell changes the choicebox should follow
+        cell.setConverter(null);
+        assertNull(cb.getConverter());
+
+        StringConverter<Object> customConverter = new StringConverter<Object>() {
+            @Override public String toString(Object object) { return null; }
+            @Override public Object fromString(String string) { return null; }
+        };
+        cell.setConverter(customConverter);
+        assertEquals(customConverter, cb.getConverter());
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/cell/ComboBoxTableCellTest.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/cell/ComboBoxTableCellTest.java	Thu Oct 03 12:50:01 2013 +1300
@@ -27,6 +27,7 @@
 
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
+import javafx.scene.control.ComboBox;
 import javafx.scene.control.TableCell;
 import javafx.scene.control.TableColumn;
 import javafx.scene.control.TableView;
@@ -450,4 +451,35 @@
         assertFalse(cell.isEditing());
         assertNull(cell.getGraphic());
     }
+
+    @Test public void test_rt_29320() {
+        TableColumn tc = new TableColumn();
+        TableView tableView = new TableView(FXCollections.observableArrayList("TEST"));
+        tableView.getColumns().add(tc);
+        tableView.setEditable(true);
+        ComboBoxTableCell<Object,Object> cell = new ComboBoxTableCell<>();
+        cell.updateTableView(tableView);
+        cell.updateIndex(0);
+        cell.updateTableColumn(tc);
+        cell.setEditable(true);
+
+        tableView.edit(0, tc);
+        ComboBox cb = (ComboBox) cell.getGraphic();
+
+        // initially the choiceBox converter should equal the cell converter
+        assertNotNull(cell.getConverter());
+        assertNotNull(cb.getConverter());
+        assertEquals(cell.getConverter(), cb.getConverter());
+
+        // and if the cell changes the choicebox should follow
+        cell.setConverter(null);
+        assertNull(cb.getConverter());
+
+        StringConverter<Object> customConverter = new StringConverter<Object>() {
+            @Override public String toString(Object object) { return null; }
+            @Override public Object fromString(String string) { return null; }
+        };
+        cell.setConverter(customConverter);
+        assertEquals(customConverter, cb.getConverter());
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/cell/ComboBoxTreeCellTest.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/cell/ComboBoxTreeCellTest.java	Thu Oct 03 12:50:01 2013 +1300
@@ -27,6 +27,7 @@
 
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
+import javafx.scene.control.ComboBox;
 import javafx.scene.control.TreeCell;
 import javafx.scene.control.TreeItem;
 import javafx.scene.control.TreeView;
@@ -346,4 +347,33 @@
         assertFalse(cell.isEditing());
         assertNull(cell.getGraphic());
     }
+
+    @Test public void test_rt_29320() {
+        TreeItem root = new TreeItem("Root");
+        TreeView treeView = new TreeView(root);
+        treeView.setEditable(true);
+        ComboBoxTreeCell<Object> cell = new ComboBoxTreeCell<>();
+        cell.updateTreeView(treeView);
+        cell.updateIndex(0);
+        cell.setEditable(true);
+
+        cell.startEdit();
+        ComboBox cb = (ComboBox) cell.getGraphic();
+
+        // initially the choiceBox converter should equal the cell converter
+        assertNotNull(cell.getConverter());
+        assertNotNull(cb.getConverter());
+        assertEquals(cell.getConverter(), cb.getConverter());
+
+        // and if the cell changes the choicebox should follow
+        cell.setConverter(null);
+        assertNull(cb.getConverter());
+
+        StringConverter<Object> customConverter = new StringConverter<Object>() {
+            @Override public String toString(Object object) { return null; }
+            @Override public Object fromString(String string) { return null; }
+        };
+        cell.setConverter(customConverter);
+        assertEquals(customConverter, cb.getConverter());
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/cell/ComboBoxTreeTableCellTest.java	Thu Oct 03 11:17:28 2013 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/cell/ComboBoxTreeTableCellTest.java	Thu Oct 03 12:50:01 2013 +1300
@@ -27,10 +27,7 @@
 
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
-import javafx.scene.control.TreeItem;
-import javafx.scene.control.TreeTableCell;
-import javafx.scene.control.TreeTableColumn;
-import javafx.scene.control.TreeTableView;
+import javafx.scene.control.*;
 import javafx.util.Callback;
 import javafx.util.StringConverter;
 import org.junit.Before;
@@ -440,4 +437,35 @@
         assertFalse(cell.isEditing());
         assertNull(cell.getGraphic());
     }
+
+    @Test public void test_rt_29320() {
+        TreeTableColumn tc = new TreeTableColumn();
+        TreeTableView tableView = new TreeTableView(new TreeItem("TEST"));
+        tableView.getColumns().add(tc);
+        tableView.setEditable(true);
+        ComboBoxTreeTableCell<Object,Object> cell = new ComboBoxTreeTableCell<>();
+        cell.updateTreeTableView(tableView);
+        cell.updateIndex(0);
+        cell.updateTreeTableColumn(tc);
+        cell.setEditable(true);
+
+        tableView.edit(0, tc);
+        ComboBox cb = (ComboBox) cell.getGraphic();
+
+        // initially the choiceBox converter should equal the cell converter
+        assertNotNull(cell.getConverter());
+        assertNotNull(cb.getConverter());
+        assertEquals(cell.getConverter(), cb.getConverter());
+
+        // and if the cell changes the choicebox should follow
+        cell.setConverter(null);
+        assertNull(cb.getConverter());
+
+        StringConverter<Object> customConverter = new StringConverter<Object>() {
+            @Override public String toString(Object object) { return null; }
+            @Override public Object fromString(String string) { return null; }
+        };
+        cell.setConverter(customConverter);
+        assertEquals(customConverter, cb.getConverter());
+    }
 }