Skip to content

Commit

Permalink
8285700: [TreeTableView] graphic property of TreeItem is still visibl…
Browse files Browse the repository at this point in the history
…e after collapsing tree

Reviewed-by: angorya, mhanl
  • Loading branch information
karthikpandelu committed Jul 20, 2023
1 parent ad5e66a commit 600cee7
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ private void updateTreeItem() {
unregisterInvalidationListeners(graphicProperty());
treeItem = getSkinnable().getTreeItem();
registerInvalidationListener(graphicProperty(), e -> updateTreeItemGraphic());
updateDisclosureNodeAndGraphic();
}

private TreeTableView<T> getTreeTableView() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.lang.ref.WeakReference;
import javafx.collections.FXCollections;
Expand All @@ -45,6 +46,7 @@
import javafx.scene.control.skin.TableColumnHeader;
import javafx.scene.control.skin.TableColumnHeaderShim;
import javafx.scene.control.skin.TreeTableRowSkin;
import javafx.scene.shape.Rectangle;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -356,9 +358,57 @@ public void cellsMustBeCollectableAfterRowFactoryChange() {
JMemoryBuddy.assertCollectable(ref);
}

// See JDK-8285700
@Test
public void testGraphicVisibilityOfTreeItem() {
TreeTableView<String> tree = new TreeTableView<>();
stageLoader = new StageLoader(tree);

TreeTableColumn<String, String> column = new TreeTableColumn<>("Column");
tree.getColumns().add(column);
tree.setRoot(new TreeItem("Root"));

for (int i = 0; i < 4; i++) {
TreeItem<String> parent = new TreeItem<>("item - " + i, new Rectangle(10, 10));
TreeItem<String> subNode = new TreeItem<>("sub-node - " + i, new Rectangle(10, 10));
parent.getChildren().addAll(subNode);
tree.getRoot().getChildren().add(parent);
}
tree.getRoot().setExpanded(true);

int itemNodeSize = tree.getRoot().getChildren().size();
TreeItem treeItem = tree.getRoot().getChildren().get(itemNodeSize - 2);
TreeItem treeItemSubNode = tree.getRoot().getChildren().get(itemNodeSize - 2).getChildren().get(0);
TreeItem lastItem = tree.getRoot().getChildren().get(itemNodeSize - 1);

Toolkit.getToolkit().firePulse();
assertFalse(treeItem.isExpanded());
double lastItemBeforeExpand = lastItem.getGraphic().localToScene(lastItem.getGraphic().getBoundsInLocal()).getMinY();

treeItem.setExpanded(true);
Toolkit.getToolkit().firePulse();
assertTrue(treeItem.isExpanded());
assertNotEquals(lastItemBeforeExpand, lastItem.getGraphic().localToScene(lastItem.getGraphic().getBoundsInLocal()).getMinY());
double treeItemSubNodeAfterExpand = treeItemSubNode.getGraphic().localToScene(treeItemSubNode.getGraphic().getBoundsInLocal()).getMinY();

treeItem.setExpanded(false);
Toolkit.getToolkit().firePulse();
assertFalse(treeItem.isExpanded());
assertEquals(lastItemBeforeExpand, lastItem.getGraphic().localToScene(lastItem.getGraphic().getBoundsInLocal()).getMinY());
assertNotEquals(treeItemSubNodeAfterExpand, treeItemSubNode.getGraphic().localToScene(treeItemSubNode.getGraphic().getBoundsInLocal()).getMinY());

treeItem.setExpanded(true);
Toolkit.getToolkit().firePulse();
assertTrue(treeItem.isExpanded());
assertEquals(treeItemSubNodeAfterExpand, treeItemSubNode.getGraphic().localToScene(treeItemSubNode.getGraphic().getBoundsInLocal()).getMinY());
}

@AfterEach
public void after() {
stageLoader.dispose();
if (stageLoader != null) {
stageLoader.dispose();
stageLoader = null;
}
}

private void invisibleColumnsShouldRemoveCorrespondingCellsInRowImpl() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
import javafx.scene.control.TreeTableView.ResizeFeatures;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;
import javafx.scene.text.Text;
import javafx.util.Callback;
import com.oracle.tools.fx.monkey.util.OptionPane;
Expand Down Expand Up @@ -114,6 +116,8 @@ public enum Cmd {
protected final ComboBox<ResizePolicy> policySelector;
protected final ComboBox<Selection> selectionSelector;
protected final CheckBox nullFocusModel;
protected final CheckBox addGraphics;
protected final CheckBox addSubNodes;
protected TreeTableView<String> tree;

public TreeTableViewPage() {
Expand Down Expand Up @@ -150,6 +154,18 @@ public TreeTableViewPage() {
updatePane();
});

addGraphics = new CheckBox("add graphics");
addGraphics.setId("addGraphics");
addGraphics.selectedProperty().addListener((s, p, c) -> {
updatePane();
});

addSubNodes = new CheckBox("add sub-nodes");
addSubNodes.setId("addSubNodes");
addSubNodes.selectedProperty().addListener((s, p, c) -> {
updatePane();
});

Button clearButton = new Button("Clear Items");
clearButton.setOnAction((ev) -> {
tree.setRoot(new TreeItem(null));
Expand All @@ -167,6 +183,8 @@ public TreeTableViewPage() {
p.label("Selection Model:");
p.option(selectionSelector);
p.option(nullFocusModel);
p.option(addGraphics);
p.option(addSubNodes);
setOptions(p);

demoSelector.getSelectionModel().selectFirst();
Expand Down Expand Up @@ -563,8 +581,20 @@ protected void updateItem(String item, boolean empty) {
case ROWS:
{
int n = (int)(spec[i++]);
TreeItem subNodeTreeItem = null;
for (int j = 0; j < n; j++) {
tree.getRoot().getChildren().add(new TreeItem(newItem()));
TreeItem treeItem = new TreeItem(newItem());
if (addSubNodes.isSelected()) {
subNodeTreeItem = new TreeItem(newItem());
treeItem.getChildren().add(subNodeTreeItem);
}
if (addGraphics.isSelected()) {
treeItem.setGraphic(new Rectangle(10, 10, Color.RED));
if (subNodeTreeItem != null) {
subNodeTreeItem.setGraphic(new Rectangle(10, 10));
}
}
tree.getRoot().getChildren().add(treeItem);
}
}
break;
Expand Down

3 comments on commit 600cee7

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

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

@kevinrushforth
Copy link
Member

Choose a reason for hiding this comment

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

/tag 22+1

@openjdk
Copy link

@openjdk openjdk bot commented on 600cee7 Jul 20, 2023

Choose a reason for hiding this comment

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

@kevinrushforth The tag 22+1 was successfully created.

Please sign in to comment.