changeset 1265:cc8d7f8bbab8

Automated merge with ssh://jfxsrc.us.oracle.com//javafx/2.2/scrum/controls/jfx/rt
author jgiles
date Tue, 12 Jun 2012 09:44:39 +1200
parents 6809fcdc77f4 634e4bbb4cf5
children 388637d028f3
files
diffstat 6 files changed, 90 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java	Mon Jun 11 13:04:12 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java	Tue Jun 12 09:44:39 2012 +1200
@@ -109,6 +109,7 @@
         super(comboBox, new ComboBoxListViewBehavior<T>(comboBox));
         this.comboBox = comboBox;
         this.listView = createListView();
+        this.textField = getEditableInputNode();
         
         // Fix for RT-21207. Additional code related to this bug is further below.
         this.listView.setManaged(false);
@@ -215,9 +216,6 @@
     @Override public Node getDisplayNode() {
         Node displayNode;
         if (comboBox.isEditable()) {
-            if (textField == null) {
-                textField = getEditableInputNode();
-            }
             displayNode = textField;
         } else {
             displayNode = buttonCell;
--- a/javafx-ui-controls/src/javafx/scene/control/ListView.java	Mon Jun 11 13:04:12 2012 -0700
+++ b/javafx-ui-controls/src/javafx/scene/control/ListView.java	Tue Jun 12 09:44:39 2012 +1200
@@ -58,6 +58,7 @@
 import com.sun.javafx.scene.control.WeakListChangeListener;
 import com.sun.javafx.scene.control.skin.ListViewSkin;
 import com.sun.javafx.scene.control.skin.VirtualContainerBase;
+import java.lang.ref.WeakReference;
 import javafx.beans.DefaultProperty;
 
 /**
@@ -305,19 +306,25 @@
     public final ObjectProperty<ObservableList<T>> itemsProperty() {
         if (items == null) {
             items = new SimpleObjectProperty<ObservableList<T>>(this, "items") {
+                WeakReference<ObservableList<T>> oldItemsRef;
+                
                 @Override protected void invalidated() {
+                    ObservableList<T> 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 ListViewBitSetSelectionModel) {
-                        ((ListViewBitSetSelectionModel)getSelectionModel()).updateItemsObserver(null, getItems());
+                        ((ListViewBitSetSelectionModel)getSelectionModel()).updateItemsObserver(oldItems, getItems());
                     }
                     if (getFocusModel() instanceof ListViewFocusModel) {
-                        ((ListViewFocusModel)getFocusModel()).updateItemsObserver(null, getItems());
+                        ((ListViewFocusModel)getFocusModel()).updateItemsObserver(oldItems, getItems());
                     }
                     if (getSkin() instanceof ListViewSkin) {
                         ListViewSkin skin = (ListViewSkin) getSkin();
                         skin.updateListViewItems();
                     }
+                    
+                    oldItemsRef = new WeakReference<ObservableList<T>>(getItems());
                 }
             };
         }
@@ -907,7 +914,7 @@
 
             this.listView.itemsProperty().addListener(weakItemsObserver);
             if (listView.getItems() != null) {
-                this.listView.getItems().addListener(weakItemsContentObserver);
+                updateItemsObserver(null, listView.getItems());
             }
         }
         
@@ -945,12 +952,14 @@
         private WeakChangeListener weakItemsObserver = 
                 new WeakChangeListener(itemsObserver);
         
+        private int newListHash = -1;
         private void updateItemsObserver(ObservableList<T> oldList, ObservableList<T> newList) {
             // update listeners
             if (oldList != null) {
                 oldList.removeListener(weakItemsContentObserver);
             }
-            if (newList != null) {
+            if (newList != null && newList.hashCode() != newListHash) {
+                newListHash = newList.hashCode();
                 newList.addListener(weakItemsContentObserver);
             }
 
@@ -993,11 +1002,22 @@
             c.reset();
             while (c.next()) {
                 if (c.wasReplaced()) {
-                    // Fix for RT-18969: the list had setAll called on it
-                    int index = getSelectedIndex();
-                    if (index < getItemCount() && index >= 0) {
-                        clearSelection(index);
-                        select(index);
+                    if (c.getList().isEmpty()) {
+                        // the entire items list was emptied - clear selection
+                        clearSelection();
+                    } else {
+                        // Fix for RT-18969: the list had setAll called on it
+                        int index = getSelectedIndex();
+                        if (index < getItemCount() && index >= 0) {
+                            // Use of makeAtomic is a fix for RT-20945
+                            makeAtomic = true;
+                            clearSelection(index);
+                            makeAtomic = false;
+                            select(index);
+                        } else {
+                            // Fix for RT-22079
+                            clearSelection();
+                        }
                     }
                 } else if (c.wasAdded() || c.wasRemoved()) {
                     int shift = c.wasAdded() ? c.getAddedSize() : -c.getRemovedSize();
--- a/javafx-ui-controls/src/javafx/scene/control/MultipleSelectionModelBase.java	Mon Jun 11 13:04:12 2012 -0700
+++ b/javafx-ui-controls/src/javafx/scene/control/MultipleSelectionModelBase.java	Tue Jun 12 09:44:39 2012 +1200
@@ -176,10 +176,12 @@
 
     /***********************************************************************
      *                                                                     *
-     * Internal properties                                                 *
+     * Internal field                                                      *
      *                                                                     *
      **********************************************************************/
 
+    // Fix for RT-20945
+    boolean makeAtomic = false;
 
 
     /***********************************************************************
@@ -441,12 +443,16 @@
 
 //            updateLeadSelection();
 //            support.fireChangedEvent(SELECTED_INDICES);
-        selectedIndicesSeq.callObservers(new NonIterableChange.GenericAddRemoveChange<Integer>(0, 0, Collections.singletonList(index), selectedIndicesSeq));
+        selectedIndicesSeq.callObservers(
+                new NonIterableChange.GenericAddRemoveChange<Integer>(0, 0, 
+                Collections.singletonList(index), selectedIndicesSeq));
     }
 
     @Override public void clearSelection() {
-        setSelectedIndex(-1);
-        focus(-1);
+        if (! makeAtomic) {
+            setSelectedIndex(-1);
+            focus(-1);
+        }
 
         if (! selectedIndices.isEmpty()) {
             List<Integer> removed = new AbstractList<Integer>() {
@@ -462,7 +468,10 @@
             };
 
             quietClearSelection();
-            selectedIndicesSeq.callObservers(new NonIterableChange.GenericAddRemoveChange<Integer>(0, 0, removed, selectedIndicesSeq));
+            
+            selectedIndicesSeq.callObservers(
+                    new NonIterableChange.GenericAddRemoveChange<Integer>(0, 0, 
+                    removed, selectedIndicesSeq));
         }
     }
 
@@ -509,4 +518,6 @@
             select(focusIndex + 1);
         }
     }
+    
+    
 }
--- a/javafx-ui-controls/src/javafx/scene/control/TableCell.java	Mon Jun 11 13:04:12 2012 -0700
+++ b/javafx-ui-controls/src/javafx/scene/control/TableCell.java	Tue Jun 12 09:44:39 2012 +1200
@@ -24,22 +24,17 @@
  */
 package javafx.scene.control;
 
-import com.sun.javafx.logging.PlatformLogger;
 import java.util.Map;
 
 import javafx.beans.InvalidationListener;
 import javafx.beans.Observable;
 import javafx.beans.WeakInvalidationListener;
-import javafx.beans.property.ObjectProperty;
-import javafx.beans.property.ObjectPropertyBase;
-import javafx.beans.property.SimpleObjectProperty;
 import javafx.beans.value.ObservableValue;
 import javafx.collections.ListChangeListener;
 import javafx.event.Event;
 import javafx.scene.control.TableView.TableViewFocusModel;
 
 import com.sun.javafx.property.PropertyReference;
-import com.sun.javafx.scene.control.Logging;
 import com.sun.javafx.scene.control.WeakListChangeListener;
 import java.lang.ref.WeakReference;
 import javafx.beans.property.ReadOnlyObjectProperty;
@@ -81,7 +76,6 @@
         // we listen to changes in the index property as this indicates that
         // the cell has been reappropriated
         indexProperty().addListener(indexListener);
-        updateItem();
     }
 
 
@@ -103,7 +97,8 @@
     };
     
     @Override void indexChanged() {
-        updateItem();
+        itemDirty = true;
+        requestLayout();
     }
 
     /*
@@ -132,7 +127,7 @@
             requestLayout();
         }
     };
-
+    
     private final InvalidationListener editingListener = new InvalidationListener() {
         @Override public void invalidated(Observable value) {
             updateEditing();
@@ -478,6 +473,15 @@
                 getTableView().getSelectionModel() != null &&
                 getTableView().getSelectionModel().isCellSelectionEnabled();
     }
+    
+    /*
+     * This was brought in to fix the issue in RT-22077, namely that the 
+     * ObservableValue was being GC'd, meaning that changes to the value were
+     * no longer being delivered. By extracting this value out of the method, 
+     * it is now referred to from TableCell and will therefore no longer be
+     * GC'd.
+     */
+    private ObservableValue<T> currentObservableValue = null;
 
     /*
      * This is called when we think that the data within this TableCell may have
@@ -510,6 +514,10 @@
      * the responsibility of the TableModel developer).
      */
     private void updateItem() {
+        if (currentObservableValue != null) {
+            currentObservableValue.removeListener(weaktableRowUpdateObserver);
+        }
+        
         // there is a whole heap of reasons why we should just punt...
         if (getIndex() < 0 || 
                 columnIndex < 0 ||
@@ -519,32 +527,30 @@
                 getTableView().getItems() == null) {
             return;
         }
-
+        
         // get the total number of items in the data model
         int itemCount = getTableView().getItems().size();
         
-        ObservableValue<T> observableValue = null;
         if (getIndex() >= itemCount) {
             updateItem(null, true);
             return;
         } else {
             if (getIndex() < itemCount) {
-                observableValue = getTableColumn().getCellObservableValue(getIndex());
+                currentObservableValue = getTableColumn().getCellObservableValue(getIndex());
             }
 
-            T value = observableValue == null ? null : observableValue.getValue();
+            T value = currentObservableValue == null ? null : currentObservableValue.getValue();
             
             // update the 'item' property of this cell.
             updateItem(value, value == null);
         }
         
-        if (observableValue == null) {
+        if (currentObservableValue == null) {
             return;
         }
         
         // add property change listeners to this item
-        observableValue.removeListener(weaktableRowUpdateObserver);
-        observableValue.addListener(weaktableRowUpdateObserver);
+        currentObservableValue.addListener(weaktableRowUpdateObserver);
     }
 
     @Override protected void layoutChildren() {
--- a/javafx-ui-controls/src/javafx/scene/control/TableColumn.java	Mon Jun 11 13:04:12 2012 -0700
+++ b/javafx-ui-controls/src/javafx/scene/control/TableColumn.java	Tue Jun 12 09:44:39 2012 +1200
@@ -1097,18 +1097,18 @@
         return columns;
     }
     
-    /**
-     * Returns the actual value for a cell at a given row index (and which 
-     * belongs to this TableColumn).
-     * 
-     * @param index The row index for which the data is required.
-     * @return The data that belongs to the cell at the intersection of the given
-     *      row index and the TableColumn that this method is called on.
-     */
-    public final T getCellData(final int index) {
-        ObservableValue<T> result = getCellObservableValue(index);
-        return result == null ? null : result.getValue();
-    }
+//    /**
+//     * Returns the actual value for a cell at a given row index (and which 
+//     * belongs to this TableColumn).
+//     * 
+//     * @param index The row index for which the data is required.
+//     * @return The data that belongs to the cell at the intersection of the given
+//     *      row index and the TableColumn that this method is called on.
+//     */
+//    public final T getCellData(final int index) {
+//        ObservableValue<T> result = getCellObservableValue(index);
+//        return result == null ? null : result.getValue();
+//    }
 
     /**
      * Returns the actual value for a cell from the given item.
@@ -1142,12 +1142,15 @@
      */
     public final ObservableValue<T> getCellObservableValue(int index) {
         if (index < 0) return null;
+        
         // Get the table
         final TableView<S> table = getTableView();
         if (table == null || table.getItems() == null) return null;
+        
         // Get the rowData
         final List<S> items = table.getItems();
         if (index >= items.size()) return null; // Out of range
+        
         final S rowData = items.get(index);
         return getCellObservableValue(rowData);
     }
@@ -1172,9 +1175,11 @@
         // Get the factory
         final Callback<CellDataFeatures<S,T>, ObservableValue<T>> factory = getCellValueFactory();
         if (factory == null) return null;
+        
         // Get the table
         final TableView<S> table = getTableView();
         if (table == null) return null;
+        
         // Call the factory
         final CellDataFeatures<S,T> cdf = new CellDataFeatures<S,T>(table, this, item);
         return factory.call(cdf);
--- a/javafx-ui-controls/src/javafx/scene/control/TableView.java	Mon Jun 11 13:04:12 2012 -0700
+++ b/javafx-ui-controls/src/javafx/scene/control/TableView.java	Tue Jun 12 09:44:39 2012 +1200
@@ -1874,10 +1874,12 @@
                     }
                     
                     quietClearSelection();
-                    selectedCells.setAll(newIndices);
-                    selectedCellsSeq.callObservers(
-                            new NonIterableChange.SimpleAddChange<TablePosition>(0, 
-                            newIndices.size(), selectedCellsSeq));
+                    
+                    // Fix for RT-22079
+                    for (int i = 0; i < newIndices.size(); i++) {
+                        TablePosition tp = newIndices.get(i);
+                        select(tp.getRow(), tp.getTableColumn());
+                    }
                 } else if (c.wasPermutated()) {
                     // General approach:
                     //   -- detected a sort has happened