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

Tree/Item/ModificationEvent: must fully support list changes

    Details

      Description

      missing support:

      - changes with subchanged (f.i. discontinous removes/adds)
      - permutations

      Without, there's no way interested client code can keep state related to current locations of items. Examples of how internal code suffers from the omissing is selectedIndices/selectedItems of TreeView. (Which currently might not be claringly obvious because all internal implementations of selection models are incorrect in respect to multiple subchanges, tree selection bugs show the same symptoms). While the list-based models can be implemented correctly (see f.i. IndicesList/IndexedItems in my git), the tree-based can't.

      Some pseudo-code snippets:

          // expect a single notification because ...
          @Test
          public void testChildEventDiscontinousRemoved() {
              IntegerProperty p = new SimpleIntegerProperty(0);
              EventHandler<TreeModificationEvent> l = e -> {
                  assertTrue(e.wasRemoved());
                  p.set(p.get() + 1);
              };
              treeItem.addEventHandler(TreeItem.childrenModificationEvent(), l);
              children.removeAll(children.get(2), children.get(5));
              assertEquals("received singe removed", 1, p.get());
          }

          // without single notification can't safely update stored indices
          @Test
          public void testChildEventSubChanges() {
              // simulate external storage of last index
              IntegerProperty p = new SimpleIntegerProperty(children.size()-1);
              EventHandler<TreeModificationEvent> l = e -> {
                  assertTrue("sanity: got a removed", e.wasRemoved());
                  // adjust index: fine for single subChange
                  p.set(p.get() - e.getRemovedSize());
                  // this must be valid but isn't because it's the first
                  // of a sequence of separate notifications
                  children.get(p.get());
              };
              treeItem.addEventHandler(TreeItem.childrenModificationEvent(), l);
              children.removeAll(children.get(2), children.get(5));
          }

          // no way to update index-based state after sorting
          @Test
          public void testChildEventPermutated() {
              EventHandler<TreeModificationEvent> l = e -> {
                  assertTrue("sanity: got a permutated", e.wasPermutated());
                  // now how to get the permutation indices?
              };
              treeItem.addEventHandler(TreeItem.childrenModificationEvent(), l);
              Comparator<TreeItem<String>> c = (TreeItem<String> o1, TreeItem<String> o2)
                      -> o1.getValue().compareTo(o2.getValue());
              children.sort((Comparator<? super TreeItem>) c);
          }
          

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                fastegal Jeanette Winzenburg
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Imported: