changeset 290:c1cc0e7893d3

Automated merge with ssh://jfxsrc.us.oracle.com//javafx/2.1/scrum/controls/jfx/rt
author jgiles
date Fri, 20 Jan 2012 17:16:49 +1300
parents 16ffa41b79df 025dacc36e76
children b3a9c6786253 cebb6cf6d439
files
diffstat 9 files changed, 348 insertions(+), 238 deletions(-) [+]
line wrap: on
line diff
--- a/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java	Thu Jan 19 15:23:33 2012 -0800
+++ b/javafx-ui-controls/src/com/sun/javafx/scene/control/skin/ComboBoxListViewSkin.java	Fri Jan 20 17:16:49 2012 +1300
@@ -25,6 +25,7 @@
 
 package com.sun.javafx.scene.control.skin;
 
+import com.sun.javafx.scene.control.WeakListChangeListener;
 import javafx.scene.control.ComboBox;
 import com.sun.javafx.scene.control.behavior.ComboBoxListViewBehavior;
 import java.util.List;
@@ -32,6 +33,7 @@
 import javafx.beans.Observable;
 import javafx.beans.value.ChangeListener;
 import javafx.beans.value.ObservableValue;
+import javafx.collections.ListChangeListener;
 import javafx.collections.ObservableList;
 import javafx.event.EventHandler;
 import javafx.event.EventTarget;
@@ -53,6 +55,8 @@
     
     private final ListView<T> listView;
     
+    private ObservableList<T> listViewItems;
+    
     public ComboBoxListViewSkin(final ComboBox<T> comboBox) {
         super(comboBox, new ComboBoxListViewBehavior<T>(comboBox));
         this.comboBox = comboBox;
@@ -67,38 +71,45 @@
             }
         });
         
-        updateItemsListener(null, comboBox.getItems());
-        comboBox.itemsProperty().addListener(new ChangeListener<ObservableList<T>>() {
-            @Override 
-            public void changed(ObservableValue<? extends ObservableList<T>> ov, ObservableList<T> t, ObservableList<T> t1) {
-                updateItemsListener(t, t1);
-            }
-        });
+        updateListViewItems();
         
+        registerChangeListener(comboBox.itemsProperty(), "ITEMS");
         registerChangeListener(comboBox.promptTextProperty(), "PROMPT_TEXT");
     }
     
-    private boolean itemCountDirty = false;
-    private InvalidationListener itemsListener = new InvalidationListener() {
-        @Override public void invalidated(Observable o) {
+    public void updateListViewItems() {
+        if (listViewItems != null) {
+            listViewItems.removeListener(weakListViewItemsListener);
+        }
+
+        this.listViewItems = comboBox.getItems();
+        listView.setItems(listViewItems);
+
+        if (listViewItems != null) {
+            listViewItems.addListener(weakListViewItemsListener);
+        }
+        
+        itemCountDirty = true;
+        requestLayout();
+    }
+    
+    private boolean itemCountDirty;
+    private final ListChangeListener listViewItemsListener = new ListChangeListener() {
+        @Override public void onChanged(ListChangeListener.Change c) {
             itemCountDirty = true;
             requestLayout();
         }
     };
     
-    private void updateItemsListener(ObservableList<T> oldList, ObservableList<T> newList) {
-        if (oldList != null) {
-            oldList.removeListener(itemsListener);
-        }
-        if (newList != null) {
-            newList.addListener(itemsListener);
-        }
-    }
-
+    private final WeakListChangeListener weakListViewItemsListener =
+            new WeakListChangeListener(listViewItemsListener);
+    
     @Override protected void handleControlPropertyChanged(String p) {
         super.handleControlPropertyChanged(p);
         
-        if ("PROMPT_TEXT".equals(p)) {
+        if (p == "ITEMS") {
+            updateListViewItems();
+        } else if ("PROMPT_TEXT".equals(p)) {
             updateDisplayNode();
         }
     }
@@ -161,7 +172,7 @@
                 textField.setText(stringValue);
             }
         } else {
-            int index = comboBox.getSelectionModel().getSelectedIndex();        
+            int index = getSelectedIndex();
             listCellLabel.updateListView(listView);
             listCellLabel.updateIndex(index);
         }
@@ -183,6 +194,12 @@
         }
     }
     
+    private int getSelectedIndex() {
+        T value = comboBox.getValue();
+        int index = comboBox.getItems().indexOf(value);
+        return index;
+    }
+    
     private ListCell<T> getListCellLabel() {
         if (listCellLabel != null) return listCellLabel;
         
@@ -254,13 +271,12 @@
             }
         };
 
-        listView.itemsProperty().bind(comboBox.itemsProperty());
         listView.cellFactoryProperty().bind(comboBox.cellFactoryProperty());
         listView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
 
         listView.getSelectionModel().selectedIndexProperty().addListener(new InvalidationListener() {
             @Override public void invalidated(Observable o) {
-                int index = listView.getSelectionModel().getSelectedIndex();
+                int index = getSelectedIndex();
                 comboBox.getSelectionModel().select(index);
                 comboBox.setValue(listView.getSelectionModel().getSelectedItem());
                 updateDisplayNode();
--- a/javafx-ui-controls/src/javafx/scene/control/ComboBox.java	Thu Jan 19 15:23:33 2012 -0800
+++ b/javafx-ui-controls/src/javafx/scene/control/ComboBox.java	Fri Jan 20 17:16:49 2012 +1300
@@ -27,6 +27,7 @@
 
 import com.sun.javafx.css.StyleManager;
 import com.sun.javafx.scene.control.WeakListChangeListener;
+import com.sun.javafx.scene.control.skin.ComboBoxListViewSkin;
 import com.sun.javafx.scene.control.skin.ListViewSkin;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -147,10 +148,14 @@
         valueProperty().addListener(new ChangeListener<T>() {
             @Override public void changed(ObservableValue<? extends T> ov, T t, T t1) {
                 if (getItems() == null) return;
-                int index = getItems().indexOf(t1);
-                if (index > -1) {
-                    getSelectionModel().select(index);
-                }
+                getSelectionModel().setSelectedItem(t1);
+            }
+        });
+        
+        editableProperty().addListener(new InvalidationListener() {
+            @Override public void invalidated(Observable o) {
+                // when editable changes, we reset the selection / value states
+                getSelectionModel().clearSelection();
             }
         });
     }
@@ -174,6 +179,10 @@
             if (getSelectionModel() instanceof ComboBoxSelectionModel) {
                 ((ComboBoxSelectionModel)getSelectionModel()).updateItemsObserver(null, getItems());
             }
+            if (getSkin() instanceof ComboBoxListViewSkin) {
+                ComboBoxListViewSkin skin = (ComboBoxListViewSkin) getSkin();
+                skin.updateListViewItems();
+            }
         }
     };
     public final void setItems(ObservableList<T> value) { itemsProperty().set(value); }
@@ -253,6 +262,8 @@
      *                                                                         *
      **************************************************************************/    
     
+    // Listen to changes in the selectedItem property of the SelectionModel.
+    // When it changes, set the selectedItem in the value property.
     private ChangeListener<T> selectedItemListener = new ChangeListener<T>() {
         @Override public void changed(ObservableValue<? extends T> ov, T t, T t1) {
             if (! valueProperty().isBound()) {
--- a/javafx-ui-controls/src/javafx/scene/control/ComboBoxBase.java	Thu Jan 19 15:23:33 2012 -0800
+++ b/javafx-ui-controls/src/javafx/scene/control/ComboBoxBase.java	Fri Jan 20 17:16:49 2012 +1300
@@ -100,6 +100,9 @@
      * Specifies whether the ComboBox allows for user input. When editable is 
      * true, the ComboBox has a text input area that a user may type in to. This
      * input is then available via the {@link #valueProperty() value} property.
+     * 
+     * <p>Note that when the editable property changes, the value property is 
+     * reset, along with any other relevant state.
      */
     public BooleanProperty editableProperty() { return editable; }
     public final void setEditable(boolean value) { editableProperty().set(value); }
--- a/javafx-ui-controls/src/javafx/scene/control/ListView.java	Thu Jan 19 15:23:33 2012 -0800
+++ b/javafx-ui-controls/src/javafx/scene/control/ListView.java	Fri Jan 20 17:16:49 2012 +1300
@@ -898,17 +898,19 @@
         // watching for changes to the items list content
         private final ListChangeListener<T> itemsContentObserver = new ListChangeListener<T>() {
             @Override public void onChanged(Change<? extends T> c) {
-                if (listView.getItems() == null || listView.getItems().isEmpty()) {
-                    setSelectedIndex(-1);
-                    focus(-1);
-                } else if (getSelectedIndex() == -1 && getSelectedItem() != null) {
-                    int newIndex = listView.getItems().indexOf(getSelectedItem());
-                    if (newIndex != -1) {
-                        setSelectedIndex(newIndex);
+                while (c.next()) {
+                    if (listView.getItems() == null || listView.getItems().isEmpty()) {
+                        setSelectedIndex(-1);
+                        focus(-1);
+                    } else if (getSelectedIndex() == -1 && getSelectedItem() != null) {
+                        int newIndex = listView.getItems().indexOf(getSelectedItem());
+                        if (newIndex != -1) {
+                            setSelectedIndex(newIndex);
+                        }
                     }
+
+                    updateSelection(c);
                 }
-
-                updateSelection(c);
             }
         };
         
@@ -972,9 +974,15 @@
 //            if (c.wasPermutated()) {
 //                System.out.println("\tWas permutated");
 //            }
+            c.reset();
             while (c.next()) {
                 if (c.wasReplaced()) {
-                    // no-op
+                    // Fix for RT-18969: the list had setAll called on it
+                    int index = getSelectedIndex();
+                    if (index < getItemCount() && index >= 0) {
+                        clearSelection(index);
+                        select(index);
+                    }
                 } else if (c.wasAdded() || c.wasRemoved()) {
                     int shift = c.wasAdded() ? c.getAddedSize() : -c.getRemovedSize();
                     shiftSelection(c.getFrom(), shift);
--- a/javafx-ui-controls/src/javafx/scene/control/TableView.java	Thu Jan 19 15:23:33 2012 -0800
+++ b/javafx-ui-controls/src/javafx/scene/control/TableView.java	Fri Jan 20 17:16:49 2012 +1300
@@ -1852,7 +1852,12 @@
         private void updateSelection(ListChangeListener.Change<? extends S> c) {
             while (c.next()) {
                 if (c.wasReplaced()) {
-                    // no-op
+                    // Fix for RT-18969: the items list had setAll called on it
+                    if (getSelectedIndex() < getRowCount()) {
+                        int selectedIndex = getSelectedIndex();
+                        clearSelection(selectedIndex);
+                        select(selectedIndex);
+                    }
                 } else if (c.wasAdded() || c.wasRemoved()) {
                     int position = c.getFrom();
                     int shift = c.wasAdded() ? c.getAddedSize() : -c.getRemovedSize();
--- a/javafx-ui-controls/test/javafx/scene/control/ComboBoxTest.java	Thu Jan 19 15:23:33 2012 -0800
+++ b/javafx-ui-controls/test/javafx/scene/control/ComboBoxTest.java	Fri Jan 20 17:16:49 2012 +1300
@@ -26,9 +26,11 @@
 
 public class ComboBoxTest {
     private ComboBox<String> comboBox;
+    private SelectionModel<String> sm;
     
     @Before public void setup() {
         comboBox = new ComboBox<String>();
+        sm = comboBox.getSelectionModel();
     }
     
     /*********************************************************************
@@ -40,7 +42,7 @@
     }
     
     @Test public void noArgConstructorSetsNonNullSelectionModel() {
-        assertNotNull(comboBox.getSelectionModel());
+        assertNotNull(sm);
     }
     
     @Test public void noArgConstructorSetsNonNullItems() {
@@ -48,11 +50,11 @@
     }
     
     @Test public void noArgConstructor_selectedItemIsNull() {
-        assertNull(comboBox.getSelectionModel().getSelectedItem());
+        assertNull(sm.getSelectedItem());
     }
     
     @Test public void noArgConstructor_selectedIndexIsNegativeOne() {
-        assertEquals(-1, comboBox.getSelectionModel().getSelectedIndex());
+        assertEquals(-1, sm.getSelectedIndex());
     }
     
     @Test public void noArgConstructor_valueIsNull() {
@@ -171,124 +173,124 @@
         SelectionModel<String> sm = new ComboBox.ComboBoxSelectionModel<String>(comboBox);
         ObjectProperty<SelectionModel<String>> other = new SimpleObjectProperty<SelectionModel<String>>(sm);
         comboBox.selectionModelProperty().bind(other);
-        assertSame(sm, comboBox.getSelectionModel());
+        assertSame(sm, sm);
     }
 
     @Test public void selectionModelCanBeChanged() {
         SelectionModel<String> sm = new ComboBox.ComboBoxSelectionModel<String>(comboBox);
         comboBox.setSelectionModel(sm);
-        assertSame(sm, comboBox.getSelectionModel());
+        assertSame(sm, sm);
     }
     
     @Test public void canSetSelectedItemToAnItemEvenWhenThereAreNoItems() {
         final String randomString = new String("I AM A CRAZY RANDOM STRING");
-        comboBox.getSelectionModel().select(randomString);
-        assertEquals(-1, comboBox.getSelectionModel().getSelectedIndex());
-        assertSame(randomString, comboBox.getSelectionModel().getSelectedItem());
+        sm.select(randomString);
+        assertEquals(-1, sm.getSelectedIndex());
+        assertSame(randomString, sm.getSelectedItem());
     }
         
     @Test public void canSetSelectedItemToAnItemNotInTheDataModel() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
         final String randomString = new String("I AM A CRAZY RANDOM STRING");
-        comboBox.getSelectionModel().select(randomString);
-        assertEquals(-1, comboBox.getSelectionModel().getSelectedIndex());
-        assertSame(randomString, comboBox.getSelectionModel().getSelectedItem());
+        sm.select(randomString);
+        assertEquals(-1, sm.getSelectedIndex());
+        assertSame(randomString, sm.getSelectedItem());
     }
         
     @Test public void settingTheSelectedItemToAnItemInItemsResultsInTheCorrectSelectedIndex() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
-        comboBox.getSelectionModel().select("Orange");
-        assertEquals(1, comboBox.getSelectionModel().getSelectedIndex());
-        assertSame("Orange", comboBox.getSelectionModel().getSelectedItem());
+        sm.select("Orange");
+        assertEquals(1, sm.getSelectedIndex());
+        assertSame("Orange", sm.getSelectedItem());
     }
     
     @Test public void settingTheSelectedItemToANonexistantItemAndThenSettingItemsWhichContainsItResultsInCorrectSelectedIndex() {
-        comboBox.getSelectionModel().select("Orange");
+        sm.select("Orange");
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
-        assertEquals(1, comboBox.getSelectionModel().getSelectedIndex());
-        assertSame("Orange", comboBox.getSelectionModel().getSelectedItem());
+        assertEquals(1, sm.getSelectedIndex());
+        assertSame("Orange", sm.getSelectedItem());
     }
     
     @Test public void ensureSelectionClearsWhenAllItemsAreRemoved_selectIndex0() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
-        comboBox.getSelectionModel().select(0);
+        sm.select(0);
         comboBox.getItems().clear();
-        assertEquals(-1, comboBox.getSelectionModel().getSelectedIndex());
-        assertEquals(null, comboBox.getSelectionModel().getSelectedItem());
+        assertEquals(-1, sm.getSelectedIndex());
+        assertEquals(null, sm.getSelectedItem());
     }
     
     @Test public void ensureSelectionClearsWhenAllItemsAreRemoved_selectIndex2() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
-        comboBox.getSelectionModel().select(2);
+        sm.select(2);
         comboBox.getItems().clear();
-        assertEquals(-1, comboBox.getSelectionModel().getSelectedIndex());
-        assertEquals(null, comboBox.getSelectionModel().getSelectedItem());
+        assertEquals(-1, sm.getSelectedIndex());
+        assertEquals(null, sm.getSelectedItem());
     }
     
     @Test public void ensureSelectedItemRemainsAccurateWhenItemsAreCleared() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
-        comboBox.getSelectionModel().select(2);
+        sm.select(2);
         comboBox.getItems().clear();
-        assertNull(comboBox.getSelectionModel().getSelectedItem());
-        assertEquals(-1, comboBox.getSelectionModel().getSelectedIndex());
+        assertNull(sm.getSelectedItem());
+        assertEquals(-1, sm.getSelectedIndex());
         
         comboBox.getItems().addAll("Kiwifruit", "Mandarin", "Pineapple");
-        comboBox.getSelectionModel().select(2);
-        assertEquals("Pineapple", comboBox.getSelectionModel().getSelectedItem());
+        sm.select(2);
+        assertEquals("Pineapple", sm.getSelectedItem());
     }
     
     @Test public void ensureSelectionShiftsDownWhenOneNewItemIsAdded() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
-        comboBox.getSelectionModel().select(1);
-        assertEquals(1, comboBox.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", comboBox.getSelectionModel().getSelectedItem());
+        sm.select(1);
+        assertEquals(1, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
         
         comboBox.getItems().add(0, "Kiwifruit");
-        assertEquals(2, comboBox.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", comboBox.getSelectionModel().getSelectedItem());
+        assertEquals(2, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
     }
     
     @Test public void ensureSelectionShiftsDownWhenMultipleNewItemAreAdded() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
-        comboBox.getSelectionModel().select(1);
-        assertEquals(1, comboBox.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", comboBox.getSelectionModel().getSelectedItem());
+        sm.select(1);
+        assertEquals(1, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
         
         comboBox.getItems().addAll(0, Arrays.asList("Kiwifruit", "Pineapple", "Mandarin"));
-        assertEquals("Orange", comboBox.getSelectionModel().getSelectedItem());
-        assertEquals(4, comboBox.getSelectionModel().getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
+        assertEquals(4, sm.getSelectedIndex());
     }
     
     @Test public void ensureSelectionShiftsUpWhenOneItemIsRemoved() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
-        comboBox.getSelectionModel().select(1);
-        assertEquals(1, comboBox.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", comboBox.getSelectionModel().getSelectedItem());
+        sm.select(1);
+        assertEquals(1, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
         
         comboBox.getItems().remove("Apple");
-        assertEquals(0, comboBox.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", comboBox.getSelectionModel().getSelectedItem());
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
     }
     
     @Test public void ensureSelectionShiftsUpWheMultipleItemsAreRemoved() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
-        comboBox.getSelectionModel().select(2);
-        assertEquals(2, comboBox.getSelectionModel().getSelectedIndex());
-        assertEquals("Banana", comboBox.getSelectionModel().getSelectedItem());
+        sm.select(2);
+        assertEquals(2, sm.getSelectedIndex());
+        assertEquals("Banana", sm.getSelectedItem());
         
         comboBox.getItems().removeAll(Arrays.asList("Apple", "Orange"));
-        assertEquals(0, comboBox.getSelectionModel().getSelectedIndex());
-        assertEquals("Banana", comboBox.getSelectionModel().getSelectedItem());
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals("Banana", sm.getSelectedItem());
     }
     
     @Test public void ensureSelectionIsCorrectWhenItemsChange() {
         comboBox.setItems(FXCollections.observableArrayList("Item 1"));
-        comboBox.getSelectionModel().select(0);
-        assertEquals("Item 1", comboBox.getSelectionModel().getSelectedItem());
+        sm.select(0);
+        assertEquals("Item 1", sm.getSelectedItem());
         
         comboBox.setItems(FXCollections.observableArrayList("Item 2"));
-        assertEquals(-1, comboBox.getSelectionModel().getSelectedIndex());
-        assertEquals(null, comboBox.getSelectionModel().getSelectedItem());
+        assertEquals(-1, sm.getSelectedIndex());
+        assertEquals(null, sm.getSelectedItem());
     }
     
     @Test(expected=NullPointerException.class) 
@@ -323,92 +325,92 @@
     @Test public void ensureSelectionModelUpdatesValueProperty_withSelectIndex() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
         assertNull(comboBox.getValue());
-        comboBox.getSelectionModel().select(0);
+        sm.select(0);
         assertEquals("Apple", comboBox.getValue());
     }
     
     @Test public void ensureSelectionModelUpdatesValueProperty_withSelectItem() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
         assertNull(comboBox.getValue());
-        comboBox.getSelectionModel().select("Apple");
+        sm.select("Apple");
         assertEquals("Apple", comboBox.getValue());
     }
     
     @Test public void ensureSelectionModelUpdatesValueProperty_withSelectPrevious() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
         assertNull(comboBox.getValue());
-        comboBox.getSelectionModel().select(2);
-        comboBox.getSelectionModel().selectPrevious();
+        sm.select(2);
+        sm.selectPrevious();
         assertEquals("Orange", comboBox.getValue());
     }
     
     @Test public void ensureSelectionModelUpdatesValueProperty_withSelectNext() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
         assertNull(comboBox.getValue());
-        comboBox.getSelectionModel().select("Apple");
-        comboBox.getSelectionModel().selectNext();
+        sm.select("Apple");
+        sm.selectNext();
         assertEquals("Orange", comboBox.getValue());
     }
     
     @Test public void ensureSelectionModelUpdatesValueProperty_withSelectFirst() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
         assertNull(comboBox.getValue());
-        comboBox.getSelectionModel().selectFirst();
+        sm.selectFirst();
         assertEquals("Apple", comboBox.getValue());
     }
     
     @Test public void ensureSelectionModelUpdatesValueProperty_withSelectLast() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
         assertNull(comboBox.getValue());
-        comboBox.getSelectionModel().selectLast();
+        sm.selectLast();
         assertEquals("Banana", comboBox.getValue());
     }
     
     @Test public void ensureSelectionModelClearsValueProperty() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
         assertNull(comboBox.getValue());
-        comboBox.getSelectionModel().select(0);
+        sm.select(0);
         assertEquals("Apple", comboBox.getValue());
         
-        comboBox.getSelectionModel().clearSelection();
+        sm.clearSelection();
         assertNull(comboBox.getValue());
     }
     
     @Test public void ensureSelectionModelClearsValuePropertyWhenNegativeOneSelected() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
         assertNull(comboBox.getValue());
-        comboBox.getSelectionModel().select(0);
+        sm.select(0);
         assertEquals("Apple", comboBox.getValue());
         
-        comboBox.getSelectionModel().select(-1);
+        sm.select(-1);
         assertNull("Expected null, actual value: " + comboBox.getValue(), comboBox.getValue());
     }
     
     @Test public void ensureValueIsCorrectWhenItemsIsAddedToWithExistingSelection() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
-        comboBox.getSelectionModel().select(1);
+        sm.select(1);
         
         comboBox.getItems().add(0, "Kiwifruit");
         
-        assertEquals(2, comboBox.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", comboBox.getSelectionModel().getSelectedItem());
+        assertEquals(2, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
         assertEquals("Orange", comboBox.getValue());
     }
     
     @Test public void ensureValueIsCorrectWhenItemsAreRemovedWithExistingSelection() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
-        comboBox.getSelectionModel().select(1);
+        sm.select(1);
         
         comboBox.getItems().remove("Apple");
         
-        assertEquals(0, comboBox.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", comboBox.getSelectionModel().getSelectedItem());
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
         assertEquals("Orange", comboBox.getValue());
     }
     
     @Test public void ensureValueIsUpdatedByCorrectSelectionModelWhenSelectionModelIsChanged() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
-        SelectionModel sm1 = comboBox.getSelectionModel();
+        SelectionModel sm1 = sm;
         sm1.select(1);
         assertEquals("Orange", comboBox.getValue());
         
@@ -428,32 +430,32 @@
         StringProperty sp = new SimpleStringProperty("empty");
         comboBox.valueProperty().bind(sp);
         
-        comboBox.getSelectionModel().select(1);
+        sm.select(1);
         assertEquals("empty", comboBox.getValue());
     }
     
     @Test public void ensureSelectionModelUpdatesWhenValueChanges() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
-        assertNull(comboBox.getSelectionModel().getSelectedItem());
+        assertNull(sm.getSelectedItem());
         comboBox.setValue("Orange");
-        assertEquals("Orange", comboBox.getSelectionModel().getSelectedItem());
+        assertEquals("Orange", sm.getSelectedItem());
     }
     
     @Test public void ensureSelectionModelUpdatesWhenValueChangesToNull() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
         comboBox.setValue("Kiwifruit");
-        assertNull(comboBox.getSelectionModel().getSelectedItem());
+        assertEquals("Kiwifruit", sm.getSelectedItem());
         assertEquals("Kiwifruit", comboBox.getValue());
         comboBox.setValue(null);
-        assertEquals(null, comboBox.getSelectionModel().getSelectedItem());
-        assertEquals(-1, comboBox.getSelectionModel().getSelectedIndex());
+        assertEquals(null, sm.getSelectedItem());
+        assertEquals(-1, sm.getSelectedIndex());
         assertEquals(null, comboBox.getValue());
     }
     
     @Test public void ensureValueEqualsSelectedItemWhenNotInItemsList() {
         comboBox.getItems().addAll("Apple", "Orange", "Banana");
-        comboBox.getSelectionModel().setSelectedItem("pineapple");
-        assertEquals("pineapple", comboBox.getSelectionModel().getSelectedItem());
+        sm.setSelectedItem("pineapple");
+        assertEquals("pineapple", sm.getSelectedItem());
         assertEquals("pineapple", comboBox.getValue());
     }
     
@@ -666,4 +668,30 @@
         strPr.setValue("newvalue");
         assertTrue("PromptText cannot be bound", comboBox.getValue().equals("newvalue"));
     }
+    
+    
+    /*********************************************************************
+     * Tests for bug reports                                             *
+     ********************************************************************/    
+    
+    @Test public void test_rt18972() {
+        comboBox.getItems().addAll("Apple", "Orange", "Banana");
+        sm.select(1);
+        assertTrue(sm.isSelected(1));
+        
+        comboBox.setEditable(true);
+        comboBox.setValue("New Value");
+        
+        // there should be no selection in the selection model, as "New Value" 
+        // isn't an item in the list, however, it is a totally valid value for
+        // the value property
+        assertFalse(sm.isSelected(1));      
+        assertEquals("New Value", sm.getSelectedItem());
+        assertEquals("New Value", comboBox.getValue());
+        
+        comboBox.setEditable(false);
+        assertEquals(-1, sm.getSelectedIndex());
+        assertEquals("New Value", sm.getSelectedItem());
+        assertEquals("New Value", comboBox.getValue());
+    }
 }
--- a/javafx-ui-controls/test/javafx/scene/control/KeyEventFirer.java	Thu Jan 19 15:23:33 2012 -0800
+++ b/javafx-ui-controls/test/javafx/scene/control/KeyEventFirer.java	Fri Jan 20 17:16:49 2012 +1300
@@ -54,17 +54,17 @@
     }
     
     private KeyEvent createEvent(KeyCode keyCode, EventType<KeyEvent> evtType, KeyModifier... modifiers) {
-        List<KeyModifier> modifiersList = Arrays.asList(modifiers);
-        
+        List<KeyModifier> ml = Arrays.asList(modifiers);
+
         return KeyEvent.impl_keyEvent(
                 target, // EventTarget
                 null,     // Character (unused unless KeyCode == KEY_TYPED
                 null,     // text
                 keyCode.impl_getCode(), // KeyCode
-                modifiersList.contains(KeyModifier.SHIFT),    // shiftDown
-                modifiersList.contains(KeyModifier.CTRL),     // ctrlDown
-                modifiersList.contains(KeyModifier.ALT),      // altDown
-                modifiersList.contains(KeyModifier.META),     // metaData
+                ml.contains(KeyModifier.SHIFT),                                   // shiftDown
+                ml.contains(KeyModifier.CTRL),                                    // ctrlDown
+                ml.contains(KeyModifier.ALT),                                     // altDown
+                ml.contains(KeyModifier.META) || ml.contains(KeyModifier.CMD),    // metaData
                 evtType);  // eventType
     }
 }
--- a/javafx-ui-controls/test/javafx/scene/control/ListViewTest.java	Thu Jan 19 15:23:33 2012 -0800
+++ b/javafx-ui-controls/test/javafx/scene/control/ListViewTest.java	Fri Jan 20 17:16:49 2012 +1300
@@ -9,6 +9,8 @@
 
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.property.SimpleObjectProperty;
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
 
@@ -17,9 +19,11 @@
 
 public class ListViewTest {
     private ListView<String> listView;
+    private MultipleSelectionModel<String> sm;
     
     @Before public void setup() {
         listView = new ListView<String>();
+        sm = listView.getSelectionModel();
     }
     
     /*********************************************************************
@@ -31,7 +35,7 @@
     }
     
     @Test public void noArgConstructorSetsNonNullSelectionModel() {
-        assertNotNull(listView.getSelectionModel());
+        assertNotNull(sm);
     }
     
     @Test public void noArgConstructorSetsNonNullItems() {
@@ -39,11 +43,11 @@
     }
     
     @Test public void noArgConstructor_selectedItemIsNull() {
-        assertNull(listView.getSelectionModel().getSelectedItem());
+        assertNull(sm.getSelectedItem());
     }
     
     @Test public void noArgConstructor_selectedIndexIsNegativeOne() {
-        assertEquals(-1, listView.getSelectionModel().getSelectedIndex());
+        assertEquals(-1, sm.getSelectedIndex());
     }
     
     @Test public void singleArgConstructorSetsTheStyleClass() {
@@ -90,124 +94,124 @@
         MultipleSelectionModel<String> sm = new ListView.ListViewBitSetSelectionModel<String>(listView);
         ObjectProperty<MultipleSelectionModel<String>> other = new SimpleObjectProperty<MultipleSelectionModel<String>>(sm);
         listView.selectionModelProperty().bind(other);
-        assertSame(sm, listView.getSelectionModel());
+        assertSame(sm, sm);
     }
 
     @Test public void selectionModelCanBeChanged() {
         MultipleSelectionModel<String> sm = new ListView.ListViewBitSetSelectionModel<String>(listView);
         listView.setSelectionModel(sm);
-        assertSame(sm, listView.getSelectionModel());
+        assertSame(sm, sm);
     }
     
     @Test public void canSetSelectedItemToAnItemEvenWhenThereAreNoItems() {
         final String randomString = new String("I AM A CRAZY RANDOM STRING");
-        listView.getSelectionModel().select(randomString);
-        assertEquals(-1, listView.getSelectionModel().getSelectedIndex());
-        assertSame(randomString, listView.getSelectionModel().getSelectedItem());
+        sm.select(randomString);
+        assertEquals(-1, sm.getSelectedIndex());
+        assertSame(randomString, sm.getSelectedItem());
     }
         
     @Test public void canSetSelectedItemToAnItemNotInTheDataModel() {
         listView.getItems().addAll("Apple", "Orange", "Banana");
         final String randomString = new String("I AM A CRAZY RANDOM STRING");
-        listView.getSelectionModel().select(randomString);
-        assertEquals(-1, listView.getSelectionModel().getSelectedIndex());
-        assertSame(randomString, listView.getSelectionModel().getSelectedItem());
+        sm.select(randomString);
+        assertEquals(-1, sm.getSelectedIndex());
+        assertSame(randomString, sm.getSelectedItem());
     }
         
     @Test public void settingTheSelectedItemToAnItemInItemsResultsInTheCorrectSelectedIndex() {
         listView.getItems().addAll("Apple", "Orange", "Banana");
-        listView.getSelectionModel().select("Orange");
-        assertEquals(1, listView.getSelectionModel().getSelectedIndex());
-        assertSame("Orange", listView.getSelectionModel().getSelectedItem());
+        sm.select("Orange");
+        assertEquals(1, sm.getSelectedIndex());
+        assertSame("Orange", sm.getSelectedItem());
     }
     
     @Test public void settingTheSelectedItemToANonexistantItemAndThenSettingItemsWhichContainsItResultsInCorrectSelectedIndex() {
-        listView.getSelectionModel().select("Orange");
+        sm.select("Orange");
         listView.getItems().addAll("Apple", "Orange", "Banana");
-        assertEquals(1, listView.getSelectionModel().getSelectedIndex());
-        assertSame("Orange", listView.getSelectionModel().getSelectedItem());
+        assertEquals(1, sm.getSelectedIndex());
+        assertSame("Orange", sm.getSelectedItem());
     }
     
     @Test public void ensureSelectionClearsWhenAllItemsAreRemoved_selectIndex0() {
         listView.getItems().addAll("Apple", "Orange", "Banana");
-        listView.getSelectionModel().select(0);
+        sm.select(0);
         listView.getItems().clear();
-        assertEquals(-1, listView.getSelectionModel().getSelectedIndex());
-        assertEquals(null, listView.getSelectionModel().getSelectedItem());
+        assertEquals(-1, sm.getSelectedIndex());
+        assertEquals(null, sm.getSelectedItem());
     }
     
     @Test public void ensureSelectionClearsWhenAllItemsAreRemoved_selectIndex2() {
         listView.getItems().addAll("Apple", "Orange", "Banana");
-        listView.getSelectionModel().select(2);
+        sm.select(2);
         listView.getItems().clear();
-        assertEquals(-1, listView.getSelectionModel().getSelectedIndex());
-        assertEquals(null, listView.getSelectionModel().getSelectedItem());
+        assertEquals(-1, sm.getSelectedIndex());
+        assertEquals(null, sm.getSelectedItem());
     }
     
     @Test public void ensureSelectedItemRemainsAccurateWhenItemsAreCleared() {
         listView.getItems().addAll("Apple", "Orange", "Banana");
-        listView.getSelectionModel().select(2);
+        sm.select(2);
         listView.getItems().clear();
-        assertNull(listView.getSelectionModel().getSelectedItem());
-        assertEquals(-1, listView.getSelectionModel().getSelectedIndex());
+        assertNull(sm.getSelectedItem());
+        assertEquals(-1, sm.getSelectedIndex());
         
         listView.getItems().addAll("Kiwifruit", "Mandarin", "Pineapple");
-        listView.getSelectionModel().select(2);
-        assertEquals("Pineapple", listView.getSelectionModel().getSelectedItem());
+        sm.select(2);
+        assertEquals("Pineapple", sm.getSelectedItem());
     }
     
     @Test public void ensureSelectionShiftsDownWhenOneNewItemIsAdded() {
         listView.getItems().addAll("Apple", "Orange", "Banana");
-        listView.getSelectionModel().select(1);
-        assertEquals(1, listView.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", listView.getSelectionModel().getSelectedItem());
+        sm.select(1);
+        assertEquals(1, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
         
         listView.getItems().add(0, "Kiwifruit");
-        assertEquals(2, listView.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", listView.getSelectionModel().getSelectedItem());
+        assertEquals(2, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
     }
     
     @Test public void ensureSelectionShiftsDownWhenMultipleNewItemAreAdded() {
         listView.getItems().addAll("Apple", "Orange", "Banana");
-        listView.getSelectionModel().select(1);
-        assertEquals(1, listView.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", listView.getSelectionModel().getSelectedItem());
+        sm.select(1);
+        assertEquals(1, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
         
         listView.getItems().addAll(0, Arrays.asList("Kiwifruit", "Pineapple", "Mandarin"));
-        assertEquals("Orange", listView.getSelectionModel().getSelectedItem());
-        assertEquals(4, listView.getSelectionModel().getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
+        assertEquals(4, sm.getSelectedIndex());
     }
     
     @Test public void ensureSelectionShiftsUpWhenOneItemIsRemoved() {
         listView.getItems().addAll("Apple", "Orange", "Banana");
-        listView.getSelectionModel().select(1);
-        assertEquals(1, listView.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", listView.getSelectionModel().getSelectedItem());
+        sm.select(1);
+        assertEquals(1, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
         
         listView.getItems().remove("Apple");
-        assertEquals(0, listView.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", listView.getSelectionModel().getSelectedItem());
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
     }
     
     @Test public void ensureSelectionShiftsUpWheMultipleItemsAreRemoved() {
         listView.getItems().addAll("Apple", "Orange", "Banana");
-        listView.getSelectionModel().select(2);
-        assertEquals(2, listView.getSelectionModel().getSelectedIndex());
-        assertEquals("Banana", listView.getSelectionModel().getSelectedItem());
+        sm.select(2);
+        assertEquals(2, sm.getSelectedIndex());
+        assertEquals("Banana", sm.getSelectedItem());
         
         listView.getItems().removeAll(Arrays.asList("Apple", "Orange"));
-        assertEquals(0, listView.getSelectionModel().getSelectedIndex());
-        assertEquals("Banana", listView.getSelectionModel().getSelectedItem());
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals("Banana", sm.getSelectedItem());
     }
     
     @Test public void ensureSelectionIsCorrectWhenItemsChange() {
         listView.setItems(FXCollections.observableArrayList("Item 1"));
-        listView.getSelectionModel().select(0);
-        assertEquals("Item 1", listView.getSelectionModel().getSelectedItem());
+        sm.select(0);
+        assertEquals("Item 1", sm.getSelectedItem());
         
         listView.setItems(FXCollections.observableArrayList("Item 2"));
-        assertEquals(-1, listView.getSelectionModel().getSelectedIndex());
-        assertEquals(null, listView.getSelectionModel().getSelectedItem());
+        assertEquals(-1, sm.getSelectedIndex());
+        assertEquals(null, sm.getSelectedItem());
     }
     
     @Test public void test_rt15793() {
@@ -301,10 +305,10 @@
     
     @Test public void test_rt18385() {
         listView.getItems().addAll("row1", "row2", "row3");
-        listView.getSelectionModel().select(1);
+        sm.select(1);
         listView.getItems().add("Another Row");
-        assertEquals(1, listView.getSelectionModel().getSelectedIndices().size());
-        assertEquals(1, listView.getSelectionModel().getSelectedItems().size());
+        assertEquals(1, sm.getSelectedIndices().size());
+        assertEquals(1, sm.getSelectedItems().size());
     }
     
     @Test public void test_rt18339_onlyEditWhenListViewIsEditable_editableIsFalse() {
@@ -321,8 +325,39 @@
     
     @Test public void test_rt14451() {
         listView.getItems().addAll("Apple", "Orange", "Banana");
-        listView.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
-        listView.getSelectionModel().selectRange(0, 2); // select from 0 (inclusive) to 2 (exclusive)
-        assertEquals(2, listView.getSelectionModel().getSelectedIndices().size());
+        sm.setSelectionMode(SelectionMode.MULTIPLE);
+        sm.selectRange(0, 2); // select from 0 (inclusive) to 2 (exclusive)
+        assertEquals(2, sm.getSelectedIndices().size());
+    }
+    
+    private int hitCount = 0;
+    @Test public void test_rt18969() {
+        hitCount = 0;
+        ObservableList<String> emptyModel = FXCollections.observableArrayList();
+        listView.setItems(emptyModel);
+        assertTrue(listView.getItems().isEmpty());
+        
+        sm.selectedItemProperty().addListener(new ChangeListener<String>() {
+            @Override public void changed(ObservableValue<? extends String> observable, String oldValue, final String newValue) {
+                hitCount++;
+            }
+        });
+        
+        ObservableList<String> mod = FXCollections.observableArrayList();
+        mod.add(System.currentTimeMillis()+"");
+        listView.getItems().setAll(mod);
+        
+        sm.select(0);
+        assertTrue(sm.isSelected(0));
+        assertEquals(1, hitCount);
+        
+        // the list is totally changing (it is being cleared), so we should 
+        // be nulling out the selection model state
+        mod = FXCollections.observableArrayList();
+        mod.add(System.currentTimeMillis()+"");
+        listView.getItems().setAll(mod);
+        
+        // it should be three, as there is a null event in between
+        assertEquals(3, hitCount);
     }
 }
--- a/javafx-ui-controls/test/javafx/scene/control/TableViewTest.java	Thu Jan 19 15:23:33 2012 -0800
+++ b/javafx-ui-controls/test/javafx/scene/control/TableViewTest.java	Fri Jan 20 17:16:49 2012 +1300
@@ -11,6 +11,8 @@
 
 import javafx.beans.property.ObjectProperty;
 import javafx.beans.property.SimpleObjectProperty;
+import javafx.beans.value.ChangeListener;
+import javafx.beans.value.ObservableValue;
 import javafx.collections.FXCollections;
 import javafx.collections.ObservableList;
 import javafx.scene.control.cell.PropertyValueFactory;
@@ -21,9 +23,11 @@
 
 public class TableViewTest {
     private TableView<String> table;
+    private TableView.TableViewSelectionModel sm;
 
     @Before public void setup() {
         table = new TableView<String>();
+        sm = table.getSelectionModel();
     }
 
     /*********************************************************************
@@ -35,7 +39,7 @@
     }
 
     @Test public void noArgConstructorSetsNonNullSelectionModel() {
-        assertNotNull(table.getSelectionModel());
+        assertNotNull(sm);
     }
 
     @Test public void noArgConstructorSetsNonNullItems() {
@@ -43,11 +47,11 @@
     }
 
     @Test public void noArgConstructor_selectedItemIsNull() {
-        assertNull(table.getSelectionModel().getSelectedItem());
+        assertNull(sm.getSelectedItem());
     }
 
     @Test public void noArgConstructor_selectedIndexIsNegativeOne() {
-        assertEquals(-1, table.getSelectionModel().getSelectedIndex());
+        assertEquals(-1, sm.getSelectedIndex());
     }
 
     @Test public void singleArgConstructorSetsTheStyleClass() {
@@ -94,126 +98,126 @@
         TableView.TableViewSelectionModel<String> sm = new TableView.TableViewArrayListSelectionModel<String>(table);
         ObjectProperty<TableView.TableViewSelectionModel<String>> other = new SimpleObjectProperty<TableView.TableViewSelectionModel<String>>(sm);
         table.selectionModelProperty().bind(other);
-        assertSame(sm, table.getSelectionModel());
+        assertSame(sm, sm);
     }
 
     @Test public void selectionModelCanBeChanged() {
         TableView.TableViewSelectionModel<String> sm = new TableView.TableViewArrayListSelectionModel<String>(table);
         table.setSelectionModel(sm);
-        assertSame(sm, table.getSelectionModel());
+        assertSame(sm, sm);
     }
 
     @Test public void canSetSelectedItemToAnItemEvenWhenThereAreNoItems() {
         final String randomString = new String("I AM A CRAZY RANDOM STRING");
-        table.getSelectionModel().select(randomString);
-        assertEquals(-1, table.getSelectionModel().getSelectedIndex());
-        assertSame(randomString, table.getSelectionModel().getSelectedItem());
+        sm.select(randomString);
+        assertEquals(-1, sm.getSelectedIndex());
+        assertSame(randomString, sm.getSelectedItem());
     }
 
     @Test public void canSetSelectedItemToAnItemNotInTheDataModel() {
         table.getItems().addAll("Apple", "Orange", "Banana");
         final String randomString = new String("I AM A CRAZY RANDOM STRING");
-        table.getSelectionModel().select(randomString);
-        assertEquals(-1, table.getSelectionModel().getSelectedIndex());
-        assertSame(randomString, table.getSelectionModel().getSelectedItem());
+        sm.select(randomString);
+        assertEquals(-1, sm.getSelectedIndex());
+        assertSame(randomString, sm.getSelectedItem());
     }
 
     @Test public void settingTheSelectedItemToAnItemInItemsResultsInTheCorrectSelectedIndex() {
         table.getItems().addAll("Apple", "Orange", "Banana");
-        table.getSelectionModel().select("Orange");
-        assertEquals(1, table.getSelectionModel().getSelectedIndex());
-        assertSame("Orange", table.getSelectionModel().getSelectedItem());
+        sm.select("Orange");
+        assertEquals(1, sm.getSelectedIndex());
+        assertSame("Orange", sm.getSelectedItem());
     }
 
     @Test public void settingTheSelectedItemToANonexistantItemAndThenSettingItemsWhichContainsItResultsInCorrectSelectedIndex() {
-        table.getSelectionModel().select("Orange");
+        sm.select("Orange");
         table.getItems().addAll("Apple", "Orange", "Banana");
-        assertEquals(1, table.getSelectionModel().getSelectedIndex());
-        assertSame("Orange", table.getSelectionModel().getSelectedItem());
+        assertEquals(1, sm.getSelectedIndex());
+        assertSame("Orange", sm.getSelectedItem());
     }
     
     @Test public void ensureSelectionClearsWhenAllItemsAreRemoved_selectIndex0() {
         table.getItems().addAll("Apple", "Orange", "Banana");
-        table.getSelectionModel().select(0);
+        sm.select(0);
         table.getItems().clear();
-        assertEquals(-1, table.getSelectionModel().getSelectedIndex());
+        assertEquals(-1, sm.getSelectedIndex());
     }
     
     @Test public void ensureSelectionClearsWhenAllItemsAreRemoved_selectIndex2() {
         table.getItems().addAll("Apple", "Orange", "Banana");
-        table.getSelectionModel().select(2);
+        sm.select(2);
         table.getItems().clear();
-        assertEquals(-1, table.getSelectionModel().getSelectedIndex());
+        assertEquals(-1, sm.getSelectedIndex());
     }
     
     @Test public void ensureSelectedItemRemainsAccurateWhenItemsAreCleared() {
         table.getItems().addAll("Apple", "Orange", "Banana");
-        table.getSelectionModel().select(2);
+        sm.select(2);
         table.getItems().clear();
-        assertNull("Selected Item: " + table.getSelectionModel().getSelectedItem(), table.getSelectionModel().getSelectedItem());
-        assertEquals(-1, table.getSelectionModel().getSelectedIndex());
+        assertNull("Selected Item: " + sm.getSelectedItem(), sm.getSelectedItem());
+        assertEquals(-1, sm.getSelectedIndex());
         
         table.getItems().addAll("Kiwifruit", "Mandarin", "Pineapple");
-        table.getSelectionModel().select(2);
-        assertEquals("Pineapple", table.getSelectionModel().getSelectedItem());
+        sm.select(2);
+        assertEquals("Pineapple", sm.getSelectedItem());
     }
     
     @Ignore("Not fixed yet")
     @Test public void ensureSelectionShiftsDownWhenOneNewItemIsAdded() {
         table.getItems().addAll("Apple", "Orange", "Banana");
-        table.getSelectionModel().select(1);
-        assertEquals(1, table.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", table.getSelectionModel().getSelectedItem());
+        sm.select(1);
+        assertEquals(1, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
         
         table.getItems().add(0, "Kiwifruit");
-        assertEquals(2, table.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", table.getSelectionModel().getSelectedItem());
+        assertEquals(2, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
     }
     
     @Ignore("Not fixed yet")
     @Test public void ensureSelectionShiftsDownWhenMultipleNewItemAreAdded() {
         table.getItems().addAll("Apple", "Orange", "Banana");
-        table.getSelectionModel().select(1);
-        assertEquals(1, table.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", table.getSelectionModel().getSelectedItem());
+        sm.select(1);
+        assertEquals(1, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
         
         table.getItems().addAll(0, Arrays.asList("Kiwifruit", "Pineapple", "Mandarin"));
-        assertEquals("Orange", table.getSelectionModel().getSelectedItem());
-        assertEquals(4, table.getSelectionModel().getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
+        assertEquals(4, sm.getSelectedIndex());
     }
     
     @Ignore("Not fixed yet")
     @Test public void ensureSelectionShiftsDownWhenOneItemIsRemoved() {
         table.getItems().addAll("Apple", "Orange", "Banana");
-        table.getSelectionModel().select(1);
-        assertEquals(1, table.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", table.getSelectionModel().getSelectedItem());
+        sm.select(1);
+        assertEquals(1, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
         
         table.getItems().remove("Apple");
-        assertEquals(0, table.getSelectionModel().getSelectedIndex());
-        assertEquals("Orange", table.getSelectionModel().getSelectedItem());
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals("Orange", sm.getSelectedItem());
     }
     
     @Ignore("Not fixed yet")
     @Test public void ensureSelectionShiftsDownWheMultipleItemsAreRemoved() {
         table.getItems().addAll("Apple", "Orange", "Banana");
-        table.getSelectionModel().select(2);
-        assertEquals(2, table.getSelectionModel().getSelectedIndex());
-        assertEquals("Banana", table.getSelectionModel().getSelectedItem());
+        sm.select(2);
+        assertEquals(2, sm.getSelectedIndex());
+        assertEquals("Banana", sm.getSelectedItem());
         
         table.getItems().removeAll(Arrays.asList("Apple", "Orange"));
-        assertEquals(0, table.getSelectionModel().getSelectedIndex());
-        assertEquals("Banana", table.getSelectionModel().getSelectedItem());
+        assertEquals(0, sm.getSelectedIndex());
+        assertEquals("Banana", sm.getSelectedItem());
     }
     
     @Test public void ensureSelectionIsCorrectWhenItemsChange() {
         table.setItems(FXCollections.observableArrayList("Item 1"));
-        table.getSelectionModel().select(0);
-        assertEquals("Item 1", table.getSelectionModel().getSelectedItem());
+        sm.select(0);
+        assertEquals("Item 1", sm.getSelectedItem());
         
         table.setItems(FXCollections.observableArrayList("Item 2"));
-        assertEquals(-1, table.getSelectionModel().getSelectedIndex());
-        assertEquals(null, table.getSelectionModel().getSelectedItem());
+        assertEquals(-1, sm.getSelectedIndex());
+        assertEquals(null, sm.getSelectedItem());
     }
 
     /*********************************************************************
@@ -363,11 +367,11 @@
     
     @Test public void test_rt18385() {
         table.getItems().addAll("row1", "row2", "row3");
-        table.getSelectionModel().select(1);
+        sm.select(1);
         table.getItems().add("Another Row");
-        assertEquals(1, table.getSelectionModel().getSelectedIndices().size());
-        assertEquals(1, table.getSelectionModel().getSelectedItems().size());
-        assertEquals(1, table.getSelectionModel().getSelectedCells().size());
+        assertEquals(1, sm.getSelectedIndices().size());
+        assertEquals(1, sm.getSelectedItems().size());
+        assertEquals(1, sm.getSelectedCells().size());
     }
     
     @Test public void test_rt18339_onlyEditWhenTableViewIsEditable_tableEditableIsFalse_columnEditableIsFalse() {
@@ -408,8 +412,8 @@
     
     @Test public void test_rt14451() {
         table.getItems().addAll("Apple", "Orange", "Banana");
-        table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
-        table.getSelectionModel().selectRange(0, 2); // select from 0 (inclusive) to 2 (exclusive)
-        assertEquals(2, table.getSelectionModel().getSelectedIndices().size());
+        sm.setSelectionMode(SelectionMode.MULTIPLE);
+        sm.selectRange(0, 2); // select from 0 (inclusive) to 2 (exclusive)
+        assertEquals(2, sm.getSelectedIndices().size());
     }
 }