changeset 1297:e6d1c213886d

Automated merge with ssh://jfxsrc.us.oracle.com//javafx/2.2/scrum/controls/jfx/rt
author jgiles
date Wed, 13 Jun 2012 16:18:07 +1200
parents 2f475847df17 b618eb1ac127
children d014ba0c953c 4b5bf956320b
files
diffstat 10 files changed, 129 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/NestedTableColumnHeader.java	Tue Jun 12 17:46:34 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/NestedTableColumnHeader.java	Wed Jun 13 16:18:07 2012 +1200
@@ -158,13 +158,25 @@
         // clear the column headers list before we recreate them
         getColumnHeaders().clear();
         
-        // then iterate through all columns.
-        for (int i = 0; i < getColumns().size(); i++) {
-            TableColumn<?,?> column = getColumns().get(i);
-            
-            if (column == null) continue;
-            
-            getColumnHeaders().add(createColumnHeader(column));
+        // then iterate through all columns, unless we've got no child columns
+        // any longer, in which case we should switch to a TableColumnHeader 
+        // instead
+        if (getColumns().isEmpty()) {
+            // switch out to be a TableColumn instead
+            NestedTableColumnHeader parentHeader = getParentHeader();
+            if (parentHeader != null) {
+                TableColumnHeader newHeader = createColumnHeader(getTableColumn());
+                int index = parentHeader.getColumnHeaders().indexOf(this);
+                parentHeader.getColumnHeaders().set(index, newHeader);
+            }
+        } else {
+            for (int i = 0; i < getColumns().size(); i++) {
+                TableColumn<?,?> column = getColumns().get(i);
+
+                if (column == null) continue;
+
+                getColumnHeaders().add(createColumnHeader(column));
+            }
         }
 
         // update the content
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableColumnHeader.java	Tue Jun 12 17:46:34 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableColumnHeader.java	Wed Jun 13 16:18:07 2012 +1200
@@ -246,7 +246,7 @@
     private Label label;
 
     // sort order 
-    private int sortPos;
+    private int sortPos = -1;
     private StackPane arrow;
     private Label sortOrderLabel;
     private HBox sortOrderDots;
@@ -283,6 +283,7 @@
         if (getTableColumn() != null) {
             getTableColumn().visibleProperty().removeListener(weakVisibleListener);
             getTableColumn().widthProperty().removeListener(weakWidthListener);
+            getTableColumn().sortTypeProperty().removeListener(weakSortTypeListener);
         }
         
         sceneProperty().removeListener(sceneListener);
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableRowSkin.java	Tue Jun 12 17:46:34 2012 -0700
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/TableRowSkin.java	Wed Jun 13 16:18:07 2012 +1200
@@ -27,7 +27,6 @@
 
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.WeakHashMap;
 
@@ -188,6 +187,8 @@
         }
     }
 
+    private int columnCount = 0;
+    
     private void recreateCells() {
         // This function is smart in the sense that we don't recreate all
         // TableCell instances every time this function is called. Instead we
@@ -205,11 +206,13 @@
         
         ObservableList<TableColumn<T,?>> columns = table.getVisibleLeafColumns();
         
-        if (fullRefreshCounter == 0 || cellsMap == null) {
+        if (columns.size() != columnCount || fullRefreshCounter == 0 || cellsMap == null) {
             clearCellsMap();
             cellsMap = new WeakHashMap<TableColumn, TableCell>(columns.size());
             fullRefreshCounter = DEFAULT_FULL_REFRESH_COUNTER;
+            getChildren().clear();
         }
+        columnCount = columns.size();
         fullRefreshCounter--;
         
         for (TableColumn col : columns) {
--- a/javafx-ui-controls/src/javafx/scene/control/ListView.java	Tue Jun 12 17:46:34 2012 -0700
+++ b/javafx-ui-controls/src/javafx/scene/control/ListView.java	Wed Jun 13 16:18:07 2012 +1200
@@ -979,6 +979,8 @@
          **********************************************************************/
 
         private final ListView<T> listView;
+        
+        private int previousModelSize = 0;
 
         // Listen to changes in the listview items list, such that when it 
         // changes we can update the selected indices bitset to refer to the 
@@ -1007,9 +1009,13 @@
                         // 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) {
+                        
+                        if (previousModelSize == c.getRemovedSize()) {
+                            // all items were removed from the model
+                            clearSelection();
+                        } else if (index < getItemCount() && index >= 0) {
+                            // Fix for RT-18969: the list had setAll called on it
                             // Use of makeAtomic is a fix for RT-20945
                             makeAtomic = true;
                             clearSelection(index);
@@ -1077,6 +1083,8 @@
                     }
                 }
             }
+            
+            previousModelSize = getItemCount();
         }
 
 
--- a/javafx-ui-controls/src/javafx/scene/control/TableCell.java	Tue Jun 12 17:46:34 2012 -0700
+++ b/javafx-ui-controls/src/javafx/scene/control/TableCell.java	Wed Jun 13 16:18:07 2012 +1200
@@ -97,8 +97,12 @@
     };
     
     @Override void indexChanged() {
-        itemDirty = true;
-        requestLayout();
+        // Ideally we would just use the following two lines of code, rather
+        // than the updateItem() call beneath, but if we do this we end up with
+        // RT-22428 where all the columns are collapsed.
+        // itemDirty = true;
+        // requestLayout();
+        updateItem();
     }
 
     /*
@@ -164,13 +168,11 @@
             updateColumnIndex();
         }
 
-        @Override
-        public Object getBean() {
+        @Override public Object getBean() {
             return TableCell.this;
         }
 
-        @Override
-        public String getName() {
+        @Override public String getName() {
             return "tableColumn";
         }
     };
--- a/javafx-ui-controls/src/javafx/scene/control/TableColumn.java	Tue Jun 12 17:46:34 2012 -0700
+++ b/javafx-ui-controls/src/javafx/scene/control/TableColumn.java	Wed Jun 13 16:18:07 2012 +1200
@@ -284,10 +284,12 @@
                     tc.setTableView(getTableView());
                 }
                 
-                // set the parent of this column to also have this tableView
-                if (getParentColumn() != null) {
-                    getParentColumn().setTableView(getTableView());
-                }
+                // This code was commented out due to RT-22391, with this enabled
+                // the parent column will be null, which is not desired
+//                // set the parent of this column to also have this tableView
+//                if (getParentColumn() != null) {
+//                    getParentColumn().setTableView(getTableView());
+//                }
             }
         });
     }
--- a/javafx-ui-controls/src/javafx/scene/control/TableView.java	Tue Jun 12 17:46:34 2012 -0700
+++ b/javafx-ui-controls/src/javafx/scene/control/TableView.java	Wed Jun 13 16:18:07 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
@@ -1845,6 +1858,7 @@
          *                                                                     *
          **********************************************************************/
 
+        private int previousModelSize = 0;
         
         // Listen to changes in the tableview items list, such that when it 
         // changes we can update the selected indices list to refer to the 
@@ -1852,12 +1866,26 @@
         private void updateSelection(ListChangeListener.Change<? extends S> c) {
             while (c.next()) {
                 if (c.wasReplaced()) {
-                    // Fix for RT-18969: the items list had setAll called on it
-                    if (getSelectedIndex() < getRowCount()) {
-                        int selectedIndex = getSelectedIndex();
-                        clearSelection(selectedIndex);
-                        select(selectedIndex);
+                    if (c.getList().isEmpty()) {
+                        // the entire items list was emptied - clear selection
+                        clearSelection();
+                    } else {
+                        int index = getSelectedIndex();
+                        
+                        if (previousModelSize == c.getRemovedSize()) {
+                            // all items were removed from the model
+                            clearSelection();
+                        } else if (index < getRowCount() && index >= 0) {
+                            // Fix for RT-18969: the list had setAll called on it
+                            clearSelection(index);
+                            select(index);
+                        } else {
+                            // Fix for RT-22079
+                            clearSelection();
+                        }
                     }
+                    
+                    
                 } else if (c.wasAdded() || c.wasRemoved()) {
                     int position = c.getFrom();
                     int shift = c.wasAdded() ? c.getAddedSize() : -c.getRemovedSize();
@@ -1925,6 +1953,8 @@
                     selectedCellsSeq.callObservers(new NonIterableChange.SimpleAddChange<TablePosition>(0, newIndices.size(), selectedCellsSeq));
                 }
             }
+            
+            previousModelSize = getRowCount();
         }
 
         /***********************************************************************
--- a/javafx-ui-controls/test/javafx/scene/control/ListViewTest.java	Tue Jun 12 17:46:34 2012 -0700
+++ b/javafx-ui-controls/test/javafx/scene/control/ListViewTest.java	Wed Jun 13 16:18:07 2012 +1200
@@ -371,4 +371,15 @@
         // used to be, so the test used to be for three hits)
         assertEquals(2, hitCount);
     }
+    
+    @Test public void test_rt21586() {
+        listView.getItems().setAll("Apple", "Orange", "Banana");
+        listView.getSelectionModel().select(1);
+        assertEquals(1, listView.getSelectionModel().getSelectedIndex());
+        assertEquals("Orange", listView.getSelectionModel().getSelectedItem());
+        
+        listView.getItems().setAll("Kiwifruit", "Pineapple", "Grape");
+        assertEquals(-1, listView.getSelectionModel().getSelectedIndex());
+        assertNull(listView.getSelectionModel().getSelectedItem());
+    }
 }
--- a/javafx-ui-controls/test/javafx/scene/control/TableViewTest.java	Tue Jun 12 17:46:34 2012 -0700
+++ b/javafx-ui-controls/test/javafx/scene/control/TableViewTest.java	Wed Jun 13 16:18:07 2012 +1200
@@ -416,4 +416,15 @@
         sm.selectRange(0, 2); // select from 0 (inclusive) to 2 (exclusive)
         assertEquals(2, sm.getSelectedIndices().size());
     }
+    
+    @Test public void test_rt21586() {
+        table.getItems().setAll("Apple", "Orange", "Banana");
+        table.getSelectionModel().select(1);
+        assertEquals(1, table.getSelectionModel().getSelectedIndex());
+        assertEquals("Orange", table.getSelectionModel().getSelectedItem());
+        
+        table.getItems().setAll("Kiwifruit", "Pineapple", "Grape");
+        assertEquals(-1, table.getSelectionModel().getSelectedIndex());
+        assertNull(table.getSelectionModel().getSelectedItem());
+    }
 }
--- a/javafx-ui-controls/test/javafx/scene/control/TreeViewTest.java	Tue Jun 12 17:46:34 2012 -0700
+++ b/javafx-ui-controls/test/javafx/scene/control/TreeViewTest.java	Wed Jun 13 16:18:07 2012 +1200
@@ -408,4 +408,21 @@
         treeView.getSelectionModel().selectRange(0, 2); // select from 0 (inclusive) to 2 (exclusive)
         assertEquals(2, treeView.getSelectionModel().getSelectedIndices().size());
     }
+    
+    @Test public void test_rt21586() {
+        installChildren();
+        treeView.getSelectionModel().select(1);
+        assertEquals(1, treeView.getSelectionModel().getSelectedIndex());
+        assertEquals(child1, treeView.getSelectionModel().getSelectedItem());
+        
+        TreeItem root = new TreeItem<String>("New Root");
+        TreeItem child1 = new TreeItem<String>("New Child 1");
+        TreeItem child2 = new TreeItem<String>("New Child 2");
+        TreeItem child3 = new TreeItem<String>("New Child 3");
+        root.setExpanded(true);
+        root.getChildren().setAll(child1, child2, child3);
+        treeView.setRoot(root);
+        assertEquals(-1, treeView.getSelectionModel().getSelectedIndex());
+        assertNull(treeView.getSelectionModel().getSelectedItem());
+    }
 }