changeset 4856:a11427375c9b

Automated merge with ssh://jfxsrc.us.oracle.com//javafx/8.0/scrum/controls/jfx/rt
author jgiles
date Sat, 31 Aug 2013 12:20:22 +1200
parents 089d0e8cb4d6 9245ffbe8c4f
children 3acaf13c190c
files
diffstat 6 files changed, 99 insertions(+), 30 deletions(-) [+]
line wrap: on
line diff
--- a/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ComboBoxPopupControl.java	Fri Aug 30 14:37:15 2013 -0700
+++ b/modules/controls/src/main/java/com/sun/javafx/scene/control/skin/ComboBoxPopupControl.java	Sat Aug 31 12:20:22 2013 +1200
@@ -26,16 +26,13 @@
 package com.sun.javafx.scene.control.skin;
 
 import javafx.css.Styleable;
+import javafx.geometry.*;
 import javafx.scene.control.ComboBoxBase;
 import com.sun.javafx.scene.control.behavior.ComboBoxBaseBehavior;
 import javafx.beans.InvalidationListener;
 import javafx.beans.Observable;
 import javafx.event.Event;
 import javafx.event.EventHandler;
-import javafx.geometry.HPos;
-import javafx.geometry.NodeOrientation;
-import javafx.geometry.Point2D;
-import javafx.geometry.VPos;
 import javafx.scene.Node;
 import javafx.scene.control.PopupControl;
 import javafx.scene.control.Skin;
@@ -98,6 +95,7 @@
         
         Point2D p = getPrefPopupPosition();
         getPopup().getScene().setNodeOrientation(getSkinnable().getEffectiveNodeOrientation());
+        reconfigurePopup();
         getPopup().show(getSkinnable().getScene().getWindow(), p.getX(), p.getY());
     }
     
@@ -144,24 +142,27 @@
         getSkinnable().layoutXProperty().addListener(layoutPosListener);
         getSkinnable().layoutYProperty().addListener(layoutPosListener);
         getSkinnable().widthProperty().addListener(layoutPosListener);
+        getSkinnable().heightProperty().addListener(layoutPosListener);
     }
     
     void reconfigurePopup() {
-        // RT-26861. Don't call getPopup() here because it may cause the popup
-        // to be created too early.
-        if (popup == null || !popup.isShowing()) return;
+        final PopupControl popupControl = getPopup();
+        if (popupControl == null) return;
                 
-        Point2D p = getPrefPopupPosition();
-        reconfigurePopup(p.getX(), p.getY(), 
-                getPopupContent().prefWidth(1), getPopupContent().prefHeight(1));
-    }   
-    
-    void reconfigurePopup(double x, double y, double minWidth, double minHeight) {
-        if (! getPopup().isShowing()) return;
-        
-        if (x > -1) getPopup().setX(x);
-        if (y > -1) getPopup().setY(y);
-        if (minWidth > -1) getPopup().setMinWidth(minWidth);
-        if (minHeight > -1) getPopup().setMinHeight(minHeight);
+        final Point2D p = getPrefPopupPosition();
+
+        final Node popupContent = getPopupContent();
+        final double minWidth = popupContent.prefWidth(1);
+        final double minHeight = popupContent.prefHeight(1);
+
+        if (p.getX() > -1) popupControl.setX(p.getX());
+        if (p.getY() > -1) popupControl.setY(p.getY());
+        if (minWidth > -1) popupControl.setMinWidth(minWidth);
+        if (minHeight > -1) popupControl.setMinHeight(minHeight);
+
+        final Bounds b = popupContent.getLayoutBounds();
+        final double w = b.getWidth() < minWidth ? minWidth : b.getWidth();
+        final double h = b.getHeight() < minHeight ? minHeight : b.getHeight();
+        popupContent.resize(w, h);
     }
 }
--- a/modules/controls/src/main/java/javafx/scene/control/MultipleSelectionModelBase.java	Fri Aug 30 14:37:15 2013 -0700
+++ b/modules/controls/src/main/java/javafx/scene/control/MultipleSelectionModelBase.java	Sat Aug 31 12:20:22 2013 +1200
@@ -313,8 +313,10 @@
         // RT-32411 We used to call quietClearSelection() here, but this
         // resulted in the selectedItems and selectedIndices lists never
         // reporting that they were empty.
-        // quietClearSelection();
+        // makeAtomic toggle added to resolve RT-32618
+        makeAtomic = true;
         clearSelection();
+        makeAtomic = false;
 
         // and select
         select(row);
--- a/modules/controls/src/main/java/javafx/scene/control/TableView.java	Fri Aug 30 14:37:15 2013 -0700
+++ b/modules/controls/src/main/java/javafx/scene/control/TableView.java	Sat Aug 31 12:20:22 2013 +1200
@@ -1874,7 +1874,8 @@
                     // There is a unit test for this, so if a more elegant solution
                     // can be found in the future and this code removed, the unit
                     // test will fail if it isn't fixed elsewhere.
-                    if (selectedItems.isEmpty() && getSelectedItem() != null) {
+                    // makeAtomic toggle added to resolve RT-32618
+                    if (! makeAtomic && selectedItems.isEmpty() && getSelectedItem() != null) {
                         setSelectedItem(null);
                     }
                     
@@ -2158,9 +2159,12 @@
             // RT-32411 We used to call quietClearSelection() here, but this
             // resulted in the selectedItems and selectedIndices lists never
             // reporting that they were empty.
-            // quietClearSelection();
+            // makeAtomic toggle added to resolve RT-32618
+            makeAtomic = true;
             clearSelection();
+            makeAtomic = false;
 
+            // and select
             select(row, column);
         }
 
@@ -2372,8 +2376,11 @@
         }
 
         @Override public void clearSelection() {
-            updateSelectedIndex(-1);
-            focus(-1);
+            if (! makeAtomic) {
+                updateSelectedIndex(-1);
+                focus(-1);
+            }
+
             quietClearSelection();
         }
 
--- a/modules/controls/src/main/java/javafx/scene/control/TreeTableView.java	Fri Aug 30 14:37:15 2013 -0700
+++ b/modules/controls/src/main/java/javafx/scene/control/TreeTableView.java	Sat Aug 31 12:20:22 2013 +1200
@@ -2164,7 +2164,8 @@
                     // There is a unit test for this, so if a more elegant solution
                     // can be found in the future and this code removed, the unit
                     // test will fail if it isn't fixed elsewhere.
-                    if (selectedItems.isEmpty() && getSelectedItem() != null) {
+                    // makeAtomic toggle added to resolve RT-32618
+                    if (!makeAtomic && selectedItems.isEmpty() && getSelectedItem() != null) {
                         setSelectedItem(null);
                     }
 
@@ -2396,12 +2397,15 @@
         }
 
         @Override public void clearAndSelect(int row, TableColumnBase<TreeItem<S>,?> column) {
-            // RT-32411 We used to call quietClearSelection() here, but this
+            // RT-32411: We used to call quietClearSelection() here, but this
             // resulted in the selectedItems and selectedIndices lists never
             // reporting that they were empty.
-            // quietClearSelection();
+            // makeAtomic toggle added to resolve RT-32618
+            makeAtomic = true;
             clearSelection();
+            makeAtomic = false;
 
+            // and select
             select(row, column);
         }
 
@@ -2616,8 +2620,11 @@
         }
 
         @Override public void clearSelection() {
-            updateSelectedIndex(-1);
-            focus(-1);
+            if (! makeAtomic) {
+                updateSelectedIndex(-1);
+                focus(-1);
+            }
+
             quietClearSelection();
         }
 
--- a/modules/controls/src/test/java/javafx/scene/control/MultipleSelectionModelImplTest.java	Fri Aug 30 14:37:15 2013 -0700
+++ b/modules/controls/src/test/java/javafx/scene/control/MultipleSelectionModelImplTest.java	Sat Aug 31 12:20:22 2013 +1200
@@ -37,6 +37,8 @@
 import java.util.Iterator;
 import java.util.List;
 
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
 import javafx.collections.FXCollections;
 import javafx.collections.ListChangeListener;
 import javafx.collections.ObservableList;
@@ -199,6 +201,9 @@
                 treeTableView.setFocusModel((TreeTableViewFocusModel) focusModel);
                 currentControl = treeTableView;
             }
+
+            // ensure the selection mode is set to multiple
+            model.setSelectionMode(SelectionMode.MULTIPLE);
         } catch (Exception ex) {
             ex.printStackTrace();
         }
@@ -270,12 +275,12 @@
     }
 
     @Test public void testSelectAllWithSingleSelection() {
+        msModel().setSelectionMode(SelectionMode.SINGLE);
         msModel().selectAll();
         ensureInEmptyState();
     }
 
     @Test public void testSelectAllWithMultipleSelection() {
-        msModel().setSelectionMode(SelectionMode.MULTIPLE);
         msModel().selectAll();
 
         assertEquals(19, model.getSelectedIndex());
@@ -896,4 +901,23 @@
         assertEquals(2, rt_32411_add_count);
         assertEquals(1, rt_32411_remove_count);
     }
+
+    private int rt32618_count = 0;
+    @Test public void test_rt32618_multipleSelection() {
+        model.selectedItemProperty().addListener(new ChangeListener<Object>() {
+            @Override public void changed(ObservableValue<? extends Object> ov, Object t, Object t1) {
+                rt32618_count++;
+            }
+        });
+
+        assertEquals(0, rt32618_count);
+
+        model.select(0);
+        assertEquals(1, rt32618_count);
+        assertEquals(ROW_1_VALUE, getValue(model.getSelectedItem()));
+
+        model.clearAndSelect(1);
+        assertEquals(2, rt32618_count);
+        assertEquals(ROW_2_VALUE, getValue(model.getSelectedItem()));
+    }
 }
--- a/modules/controls/src/test/java/javafx/scene/control/SelectionModelImplTest.java	Fri Aug 30 14:37:15 2013 -0700
+++ b/modules/controls/src/test/java/javafx/scene/control/SelectionModelImplTest.java	Sat Aug 31 12:20:22 2013 +1200
@@ -28,6 +28,8 @@
 import java.util.Arrays;
 import java.util.Collection;
 
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
 import javafx.scene.control.ChoiceBox.ChoiceBoxSelectionModel;
@@ -49,6 +51,7 @@
 import com.sun.javafx.scene.control.infrastructure.VirtualFlowTestUtils;
 
 import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
 
 /**
  * Unit tests for the SelectionModel abstract class used by ListView
@@ -218,6 +221,12 @@
                 focusModel = null;
                 currentControl = comboBox;
             }
+
+            // ensure the selection mode is set to single (if the selection model
+            // is actually a MultipleSelectionModel subclass)
+            if (model instanceof MultipleSelectionModel) {
+                ((MultipleSelectionModel)model).setSelectionMode(SelectionMode.SINGLE);
+            }
         } catch (Exception ex) {
             ex.printStackTrace();
         }
@@ -488,4 +497,23 @@
             assertTrue(cell.isSelected());
         }
     }
+
+    private int rt32618_count = 0;
+    @Test public void test_rt32618_singleSelection() {
+        model.selectedItemProperty().addListener(new ChangeListener<Object>() {
+            @Override public void changed(ObservableValue<? extends Object> ov, Object t, Object t1) {
+                rt32618_count++;
+            }
+        });
+
+        assertEquals(0, rt32618_count);
+
+        model.select(0);
+        assertEquals(1, rt32618_count);
+        assertEquals(ROW_1_VALUE, getValue(model.getSelectedItem()));
+
+        model.clearAndSelect(1);
+        assertEquals(2, rt32618_count);
+        assertEquals(ROW_2_VALUE, getValue(model.getSelectedItem()));
+    }
 }