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

TreeView: unexpected behaviour of getRow(TreeItem)

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 8u40
    • Fix Version/s: 8u60
    • Component/s: javafx
    • Labels:
    • Environment:

      8u40b15

      Description

      my expectations are that getRow returns a non-negative index if contained in the expandedDescendants of the root, or -1 if not. Something like:

           if (tree.getRow(item) > -1) {
                assertTrue(tree.getRow(item) < tree.getExpandedItemCount();
           }

      Implying that the method is kind-of invers of getTreeItem, such that:

           int row = tree.getRow(item);
           if (row > -1) {
               assertSame(item, tree.getTreeItem(row));
           }

      Actual behaviour seems to be to return the row where it would be if its parent were expanded . While not entirely certain if my expectations are correct (doc is a bit vague), can't think of a use-case where the actual behaviour would be useful. Or the other way round: if this is the intended behaviour, the api is incomplete, as we need some means to convert between tree row coordinates (== rows that can be selected) and the tree structure.

      Test snippets (complete test at: https://github.com/kleopatra/swingempire-fx/blob/master/fx8-swingempire/src/test/de/swingempire/fx/scene/control/TreeViewTest.java)

          @Test
          public void testRowLessThanExpandedItemCount() {
              TreeItem child = createSubTree("child");
              TreeItem grandChild = (TreeItem) child.getChildren().get(rawItems.size() - 1);
              root.getChildren().add(child);
              assertTrue("row of item must be less than expandedItemCount, but was: " + tree.getRow(grandChild),
                      tree.getRow(grandChild) < tree.getExpandedItemCount());
          }

          @Test
          public void testRowOfGrandChildInCollapsedChild() {
              // create a collapsed new child to insert into the root
              TreeItem newChild = createSubTree("added-child");
              TreeItem grandChild = (TreeItem) newChild.getChildren().get(2);
              root.getChildren().add(6, newChild);
              // query the row of a grand-child
              int row = tree.getRow(grandChild);
              // grandChild not visible, row coordinate in tree is not available
              assertEquals("grandChild not visible", -1, row);
              // the other way round: if we get a row, expect the item at the row be the grandChild
              assertEquals(grandChild, tree.getTreeItem(row));
          }

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:
                Imported: