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

Items changes in ListView always trigger a null selection

    XMLWordPrintable

    Details

    • Subcomponent:
    • CPU:
      generic
    • OS:
      generic

      Description

      ADDITIONAL SYSTEM INFORMATION :
      OpenJFX 15.0.1

      A DESCRIPTION OF THE PROBLEM :
      When changing the ObservableList items in a ListView it always triggers selection changes, even if neither the order nor the items, but only properties of the single objects, change. These selection changes include a null selection followed by a reselection of the original selection.

      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Create a ListView with an ObservableList that includes an Extractor that propagates object's property changes. Change a property of an object that is part of the ObservableList. Observe the selection changes, even though the items of the ObservableList are still the same.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      Selections should only change when the ObservableList items that affect the selections change.
      ACTUAL -
      Every ObservableList change triggers a null selection and a reselection afterwards

      ---------- BEGIN SOURCE ----------
      The problem is this code in ListView.java (lines 1495 following). Especially content of old an new lists are not compared and the default selection is always updated.

      private void updateItemsObserver(ObservableList<T> oldList, ObservableList<T> newList) {
                  // update listeners
                  if (oldList != null) {
                      oldList.removeListener(weakItemsContentObserver);
                  }
                  if (newList != null) {
                      newList.addListener(weakItemsContentObserver);
                  }

                  updateItemCount();
                  updateDefaultSelection();
              }

              private void updateDefaultSelection() {
                  // when the items list totally changes, we should clear out
                  // the selection and focus
                  int newSelectionIndex = -1;
                  int newFocusIndex = -1;
                  if (listView.getItems() != null) {
                      T selectedItem = getSelectedItem();
                      if (selectedItem != null) {
                          newSelectionIndex = listView.getItems().indexOf(selectedItem);
                          newFocusIndex = newSelectionIndex;
                      }

                      // we put focus onto the first item, if there is at least
                      // one item in the list
                      if (listView.selectFirstRowByDefault && newFocusIndex == -1) {
                          newFocusIndex = listView.getItems().size() > 0 ? 0 : -1;
                      }
                  }

                  clearSelection();
                  select(newSelectionIndex);
      // focus(newFocusIndex);
              }
      ---------- END SOURCE ----------

      CUSTOMER SUBMITTED WORKAROUND :
      Ignore null changes in selection listeners, but this makes certain programms impossible.

      FREQUENCY : always


        Attachments

          Activity

            People

            Assignee:
            aghaisas Ajit Ghaisas
            Reporter:
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated: