changeset 1293:541a5c63514f

RT-22191: TableView: Performance degrades when resetting content
author jgiles
date Wed, 13 Jun 2012 13:19:26 +1200
parents b6f81f47c4c8
children 06a917ba0bfa
files javafx-ui-controls/src/javafx/scene/control/TableView.java
diffstat 1 files changed, 18 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/javafx/scene/control/TableView.java	Wed Jun 13 09:44:14 2012 +1200
+++ b/javafx-ui-controls/src/javafx/scene/control/TableView.java	Wed Jun 13 13:19:26 2012 +1200
@@ -60,6 +60,7 @@
 import com.sun.javafx.scene.control.WeakListChangeListener;
 import com.sun.javafx.scene.control.skin.TableViewSkin;
 import com.sun.javafx.scene.control.skin.VirtualContainerBase;
+import java.lang.ref.WeakReference;
 import java.util.HashMap;
 import javafx.beans.DefaultProperty;
 import javafx.beans.WeakInvalidationListener;
@@ -821,19 +822,25 @@
     public final ObjectProperty<ObservableList<S>> itemsProperty() { return items; }
     private ObjectProperty<ObservableList<S>> items = 
         new SimpleObjectProperty<ObservableList<S>>(this, "items") {
+            WeakReference<ObservableList<S>> oldItemsRef;
+            
             @Override protected void invalidated() {
+                ObservableList<S> oldItems = oldItemsRef == null ? null : oldItemsRef.get();
+                
                 // FIXME temporary fix for RT-15793. This will need to be
                 // properly fixed when time permits
                 if (getSelectionModel() instanceof TableViewArrayListSelectionModel) {
-                    ((TableViewArrayListSelectionModel)getSelectionModel()).updateItemsObserver(null, getItems());
+                    ((TableViewArrayListSelectionModel)getSelectionModel()).updateItemsObserver(oldItems, getItems());
                 }
                 if (getFocusModel() instanceof TableViewFocusModel) {
-                    ((TableViewFocusModel)getFocusModel()).updateItemsObserver(null, getItems());
+                    ((TableViewFocusModel)getFocusModel()).updateItemsObserver(oldItems, getItems());
                 }
                 if (getSkin() instanceof TableViewSkin) {
                     TableViewSkin skin = (TableViewSkin) getSkin();
-                    skin.updateTableItems(null, getItems());
+                    skin.updateTableItems(oldItems, getItems());
                 }
+                
+                oldItemsRef = new WeakReference<ObservableList<S>>(getItems());
             }
         };
     public final void setItems(ObservableList<S> value) { itemsProperty().set(value); }
@@ -1799,11 +1806,17 @@
         final WeakListChangeListener weakItemsContentListener 
                 = new WeakListChangeListener(itemsContentListener);
         
+        private int newListHash = -1;
         private void updateItemsObserver(ObservableList<S> oldList, ObservableList<S> newList) {
             // the listview items list has changed, we need to observe
             // the new list, and remove any observer we had from the old list
-            if (oldList != null) oldList.removeListener(weakItemsContentListener);
-            if (newList != null) newList.addListener(weakItemsContentListener);
+            if (oldList != null) {
+                oldList.removeListener(weakItemsContentListener);
+            }
+            if (newList != null && newList.hashCode() != newListHash) {
+                newListHash = newList.hashCode();
+                newList.addListener(weakItemsContentListener);
+            }
 
             // when the items list totally changes, we should clear out
             // the selection