Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8088530

SelectedIndex/Item: incorrect notification on selecting uncontained item

XMLWordPrintable

      Below are two failing tests:
      when listening to selectedIndex the item is null: expected is the external item
      when listening to selectedItem, there are two notifications fired, the first notifying a null vs. the expected external item

      The technical reason is the internal invalidationListener registered (by MultipleSelectionModelBase, similar though untested in SingleSelectionModel) to selectedIndex that auto-updates the item - when updating by -1 there's no item found, causing the null. Further processing sets the real uncontained.

      There's a principal issue with correlated properties, though (see http://stackoverflow.com/q/27186755/203657): currently no way to defere notification of a property until internal state update of the bean is complete. Could be addressed ad-hoc in SelectionModel (custom properties, that extending classes can block in their firing) or by general support in core classes, as done f.i. in ReactFX.

          @Test
          public void testSyncItemToIndex() {
              Object uncontained = "uncontained";
              // prepare state, single select
              int start = 3;
              getSelectionModel().select(start);
              ChangeListener l = (p, old, value) -> assertEquals(uncontained,
                      getSelectionModel().getSelectedItem());
              getSelectionModel().selectedIndexProperty().addListener(l);
              getSelectionModel().select(uncontained);
          }
        
          @Test
          public void testSyncItemNotificationCount() {
              Object uncontained = "uncontained";
              // prepare state, single select
              int start = 3;
              getSelectionModel().select(start);
              List values = new ArrayList();
              ChangeListener l = (p, old, value) -> values.add(value);
              getSelectionModel().selectedItemProperty().addListener(l);
              getSelectionModel().select(uncontained);
              assertEquals("expected single event", 1, values.size());
              assertEquals("expected newvalue is uncontained", uncontained, values.get(0));
              
          }
       

            Unassigned Unassigned
            fastegal Jeanette Winzenburg
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Imported: