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

Tree-/TableView: incorrect notification from selectedIndices

    XMLWordPrintable

    Details

      Description

      happens when cell selection is enabled with multiple mode

      failing test:

          @Test public void selectRowWhenInMultipleCellSelectionModeNotification() {
              model.setSelectionMode(SelectionMode.MULTIPLE);
              model.setCellSelectionEnabled(true);
              model.clearSelection();
              List<Change> changes = new ArrayList<>();
              model.getSelectedIndices().addListener((Change<? extends Integer> c) -> {
                  changes.add(c);
                  // Note: simple logging points to the reason for the error:
                  // System.out.println(c);
              });
              model.select(1);
              assertEquals("indices must fire single change: ", 1, changes.size());
          }

      The underlying reason is ControlUtils.updateSelectedIndices: its task is to map the notifications received from selectedCells to notifications of selectedIndices. It fails by sending multiple notifications for the same row (probably with incorrect to/from coordinates)

      Yeah, the change coordinates fired by updateSelectedIndices are definitely wrong:

          // the change originated in selectedCells, coordinates in a flat list
          public static <S> void updateSelectedIndices(MultipleSelectionModelBase<S> sm, ListChangeListener.Change<? extends TablePositionBase<?>> c) {
              sm.selectedIndices._beginChange();

              while (c.next()) {
                  // [.. ] do some magic to change the indices under their feet ..

                  // error: c.getFrom is in coordinates of the list of cells
                  final int to = c.getFrom() ... ;
                 // error: mark a change multiple time (for each next)
                   if (c.wasReplaced()) {
                      sm.selectedIndices._nextReplace(c.getFrom(), to, removed);
                  } ...
              }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              aghaisas Ajit Ghaisas
              Reporter:
              fastegal Jeanette Winzenburg
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated: