Skip to content

Commit 42da68a

Browse files
committed
fix #999 Tree selection of subitems does not work when tree was not collapsed before
1 parent 2e3315a commit 42da68a

File tree

4 files changed

+41
-26
lines changed

4 files changed

+41
-26
lines changed

domino-ui/src/main/java/org/dominokit/domino/ui/cards/Card.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,12 +519,12 @@ public Card appendChild(PrefixAddOn<?> prefix) {
519519

520520
@Override
521521
public PostfixElement getPostfixElement() {
522-
return PostfixElement.of(header.get().getMainHeader().element());
522+
return header.get().getPostfixElement();
523523
}
524524

525525
@Override
526526
public PrefixElement getPrefixElement() {
527-
return PrefixElement.of(header.get().getMainHeader().element());
527+
return header.get().getPrefixElement();
528528
}
529529

530530
/**

domino-ui/src/main/java/org/dominokit/domino/ui/tree/TreeItem.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,8 +199,12 @@ public void setActiveNode(TreeItem<V> activeItem, boolean silent) {
199199
this.activeNode.deactivate();
200200
}
201201
this.activeNode = activeItem;
202-
this.activeNode.activate();
203-
getParent().ifPresent(itemParent -> itemParent.setActiveNode(this, true));
202+
this.activeNode.doActivate();
203+
if (getParent().isPresent()) {
204+
getParent().get().setActiveNode(this, true);
205+
} else {
206+
getRootNode().setActiveNode(this, true);
207+
}
204208
if (!silent) {
205209
triggerSelectionListeners(activeItem, getSelection());
206210
getRootNode().onActiveNodeChanged(activeItem, getSelection(), silent);

domino-ui/src/main/java/org/dominokit/domino/ui/tree/TreeNode.java

Lines changed: 32 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -88,21 +88,22 @@ public abstract class TreeNode<V, N extends TreeNode<V, N, S>, S>
8888
evt -> {
8989
if (ToggleTarget.ANY.equals(this.toggleTarget)) {
9090
evt.stopPropagation();
91-
if (isParent()) {
92-
toggle();
93-
}
94-
activateNode();
91+
onActivation();
9592
}
9693
};
9794

95+
private void onActivation() {
96+
if (isParent()) {
97+
toggle();
98+
}
99+
activateNode();
100+
}
101+
98102
private final EventListener iconListener =
99103
evt -> {
100104
if (ToggleTarget.ICON.equals(this.toggleTarget)) {
101105
evt.stopPropagation();
102-
if (isParent()) {
103-
toggle();
104-
}
105-
activateNode();
106+
onActivation();
106107
}
107108
};
108109

@@ -433,19 +434,12 @@ public List<N> getSubNodes() {
433434
return subNodes;
434435
}
435436

436-
/**
437-
* Expands (shows and activates) this tree item. This method expands the item and activates it.
438-
*/
439-
public void expandAndActivate() {
440-
this.show(true).activate(true);
441-
}
442-
443437
/**
444438
* Activates (selects) this tree item without activating its parent items. This method returns
445439
* void.
446440
*/
447-
public void activate() {
448-
activate(false);
441+
public void doActivate() {
442+
doActivate(false);
449443
}
450444

451445
/**
@@ -454,14 +448,30 @@ public void activate() {
454448
*
455449
* @param activateParent True to activate parent items, false to activate only this item.
456450
*/
457-
public void activate(boolean activateParent) {
451+
protected void doActivate(boolean activateParent) {
458452
addCss(dui_active);
459453
if (activateParent) {
460454
getParent().ifPresent(parent -> parent.setActiveNode((N) this));
461455
}
462456
updateIcon(isCollapsed());
463457
}
464458

459+
public N activate() {
460+
this.show(true);
461+
onActivation();
462+
return (N) this;
463+
}
464+
465+
/**
466+
* @return same instance
467+
* @deprecated use {@link #activate()}
468+
*/
469+
@Deprecated
470+
public N select() {
471+
activate();
472+
return (N) this;
473+
}
474+
465475
/**
466476
* Returns the currently active (selected) tree item within the tree structure.
467477
*
@@ -638,12 +648,13 @@ public N expandNode(boolean expandParent) {
638648
* @return This tree item with the node shown.
639649
*/
640650
public N show(boolean expandParent) {
641-
if (isParent()) {
642-
super.expand();
643-
}
644651
if (expandParent) {
645652
getParent().ifPresent(itemParent -> itemParent.expandNode(true));
646653
}
654+
655+
if (isParent()) {
656+
super.expand();
657+
}
647658
return (N) this;
648659
}
649660

domino-ui/src/main/java/org/dominokit/domino/ui/tree/TreeRoot.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ public void setActiveNode(N node, boolean silent) {
264264
}
265265

266266
this.activeNode = node;
267-
this.activeNode.activate();
267+
this.activeNode.doActivate();
268268
if (!silent) {
269269
triggerSelectionListeners(node, getSelection());
270270
this.activeNode.triggerSelectionListeners(node, getSelection());

0 commit comments

Comments
 (0)