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

ListView: EditEvent on start has incorrect index

    XMLWordPrintable

Details

    Description

      the index of the startEditEvent must be the index where editing is started. As demonstrated in the failing test below, it is -1.

      The reason seems to be in ListCell.startEdit where the event is created using list.editingIndex which still is -1 when the start is triggered from the cell (vs. triggered by someone else doing a list.editCell(someIndex)):

              super.startEdit();

               // Inform the ListView of the edit starting.
              if (list != null) {
                  list.fireEvent(new ListView.EditEvent<T>(list,
                          ListView.<T>editStartEvent(),
                          null,
                          list.getEditingIndex()));
                  list.edit(getIndex());
                  list.requestFocus();
              }

      A fix would be to use cell's index in the event.

      The failing test:

          @Test
          public void testListEditStartOnCellStandalone() {
              ListView<String> control = new ListView<>(FXCollections
                      .observableArrayList("Item1", "Item2", "Item3", "Item4"));
              control.setEditable(true);
              control.setCellFactory(TextFieldListCell.forListView());
              new StageLoader(control);
              int editIndex = 1;
              // cell retrieved via VirtualFlowTestUtils
              IndexedCell cell = getCell(control, editIndex);
              ObjectProperty<ListView.EditEvent> editEvent = new SimpleObjectProperty<>();
              control.addEventHandler(ListView.editStartEvent(), e -> editEvent.set(e));
              // start edit on cell
              cell.startEdit();
              // test cell state
              assertTrue(cell.isEditing());
              assertEquals(editIndex, cell.getIndex());
              // test editEvent
              assertNotNull(editEvent.get());
              assertEquals("type is startEdit", ListView.editStartEvent(), editEvent.get().getEventType());
              assertEquals("index on start event", editIndex, editEvent.get().getIndex());
          }
          

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved: