changeset 6605:14c8808eca5c

RT-36425: Cannot sort bound TableView
author jgiles
date Thu, 03 Apr 2014 14:00:30 +1300
parents 1d9f6c50dc8b
children d778dbb6c528
files modules/controls/src/main/java/javafx/scene/control/TableView.java modules/controls/src/test/java/javafx/scene/control/TableViewTest.java
diffstat 2 files changed, 31 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/javafx/scene/control/TableView.java	Thu Apr 03 10:38:48 2014 +1300
+++ b/modules/controls/src/main/java/javafx/scene/control/TableView.java	Thu Apr 03 14:00:30 2014 +1300
@@ -704,15 +704,15 @@
         new SimpleObjectProperty<ObservableList<S>>(this, "items") {
             WeakReference<ObservableList<S>> oldItemsRef;
 
-            // need to override set() rather than invalidated() as we need to
-            // be notified of all changes (even when the item is the same, such
-            // as in the case of a new empty items list replacing an old (but
-            // equal) empty items list
-            
             @Override protected void invalidated() {
                 final ObservableList<S> oldItems = oldItemsRef == null ? null : oldItemsRef.get();
                 final ObservableList<S> newItems = getItems();
 
+                // Fix for RT-36425
+                if (newItems != null && newItems == oldItems) {
+                    return;
+                }
+
                 // Fix for RT-35763
                 if (! (newItems instanceof SortedList)) {
                     getSortOrder().clear();
--- a/modules/controls/src/test/java/javafx/scene/control/TableViewTest.java	Thu Apr 03 10:38:48 2014 +1300
+++ b/modules/controls/src/test/java/javafx/scene/control/TableViewTest.java	Thu Apr 03 14:00:30 2014 +1300
@@ -2695,4 +2695,30 @@
 
         VirtualFlowTestUtils.assertTableCellTextEquals(tableView, 0, 0, ""+expected);
     }
+
+    @Test public void test_rt36425() {
+        TableView<String> tableView = new TableView<>();
+
+        TableColumn<String, String> tableColumn = new TableColumn<>();
+        tableColumn.setCellValueFactory(data -> new SimpleStringProperty(data.getValue()));
+        tableColumn.setText("Test");
+        tableView.getColumns().add(tableColumn);
+
+        SimpleListProperty<String> data = new SimpleListProperty<>(FXCollections.observableArrayList());
+        tableView.itemsProperty().bind(data);
+        data.addAll("AAA", "BBB");
+
+        assertEquals("AAA", data.get(0));
+        assertEquals("BBB", data.get(1));
+
+        tableView.getSortOrder().add(tableColumn);
+
+        assertTrue(tableView.getSortOrder().contains(tableColumn));
+        assertEquals("AAA", data.get(0));
+        assertEquals("BBB", data.get(1));
+
+        tableColumn.setSortType(TableColumn.SortType.DESCENDING);
+        assertEquals("AAA", data.get(1));
+        assertEquals("BBB", data.get(0));
+    }
 }