Skip to content

Commit

Permalink
8284676: TreeTableView loses sort ordering when applied on empty table
Browse files Browse the repository at this point in the history
Reviewed-by: kcr, jpereda
  • Loading branch information
arapte committed Jul 13, 2022
1 parent 8d5d3ca commit 0132ac8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -582,11 +582,13 @@ public static int getNodeLevel(TreeItem<?> node) {
@Override public Boolean call(TreeTableView table) {
try {
TreeItem rootItem = table.getRoot();
if (rootItem == null || rootItem.getChildren().isEmpty()) return false;
if (rootItem == null) return false;

TreeSortMode sortMode = table.getSortMode();
if (sortMode == null) return false;

if (rootItem.getChildren().isEmpty()) return true;

rootItem.lastSortMode = sortMode;
rootItem.lastComparator = table.getComparator();
rootItem.sort();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,18 @@ private void verifySelectionAfterPermutation() {
});
}

@Test public void testSetSortOrderRetainsWhenRootHasNoChildren() {
TreeTableView<String> ttv = new TreeTableView<>();
TreeItem<String> root = new TreeItem<>("root");
root.setExpanded(true);
ttv.setRoot(root);
assertEquals(0, ttv.getSortOrder().size());

TreeTableColumn<String, String> ttc = new TreeTableColumn<>("Column");
ttv.getSortOrder().add(ttc);
assertEquals(1, ttv.getSortOrder().size());
}

@Test public void testNPEWhenRootItemIsNull() {
TreeTableView<String> ttv = new TreeTableView<>();
ControlTestUtils.runWithExceptionHandler(() -> {
Expand Down

1 comment on commit 0132ac8

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.