FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add Ordered interface · patternfly-java/patternfly-java@a67e9d4 · GitHub

Commit a67e9d4

Browse files
committed
Add Ordered interface
1 parent 7fa221b commit a67e9d4

2 files changed

Lines changed: 18 additions & 5 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
88

99
### Added
1010

11-
- Add [`Ordered`](https://patternfly-java.github.io/patternfly-java/org/patternfly/component/Ordered.html) interface and implementations for `List`, and `DataList`.
11+
- Add [`Ordered`](https://patternfly-java.github.io/patternfly-java/org/patternfly/component/Ordered.html) interface and implementations for `List`, `DataList`, and `Tbody`.
1212

1313
## [0.4.16] - 2026-02-05
1414

‎components/src/main/java/org/patternfly/component/table/Tbody.java‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
package org.patternfly.component.table;
1717

1818
import java.util.ArrayList;
19+
import java.util.Comparator;
1920
import java.util.Iterator;
2021
import java.util.LinkedHashMap;
2122
import java.util.List;
@@ -26,8 +27,8 @@
2627
import org.jboss.elemento.Elements;
2728
import org.jboss.elemento.Id;
2829
import org.patternfly.component.HasItems;
30+
import org.patternfly.component.Ordered;
2931
import org.patternfly.component.emptystate.EmptyState;
30-
3132
import elemental2.dom.HTMLTableSectionElement;
3233

3334
import static org.jboss.elemento.Elements.failSafeRemoveFromParent;
@@ -42,6 +43,7 @@
4243
import static org.patternfly.style.Classes.tbody;
4344

4445
public class Tbody extends TableSubComponent<HTMLTableSectionElement, Tbody> implements
46+
Ordered<HTMLTableSectionElement, Tbody, Tr>,
4547
HasItems<HTMLTableSectionElement, Tbody, Tr> {
4648

4749
// ------------------------------------------------------ factory
@@ -57,9 +59,10 @@ public static Tbody tbody() {
5759

5860
public static final String SUB_COMPONENT_NAME = "tbd";
5961
final Map<String, Tr> items;
60-
private Tr emptyRow;
6162
private final List<BiConsumer<Tbody, Tr>> onAdd;
6263
private final List<BiConsumer<Tbody, Tr>> onRemove;
64+
private Tr emptyRow;
65+
private Comparator<Tr> comparator;
6366

6467
Tbody() {
6568
super(SUB_COMPONENT_NAME, Elements.tbody().css(component(table, tbody))
@@ -83,15 +86,25 @@ public Tbody addRow(Tr row) {
8386
}
8487

8588
public Tbody add(Tr row) {
86-
items.put(row.identifier(), row);
89+
if (comparator != null) {
90+
addOrdered(this, this, row, comparator);
91+
} else {
92+
add(row.element());
93+
}
8794
row.tbody = this;
88-
add(row.element());
95+
items.put(row.identifier(), row);
8996
onAdd.forEach(bc -> bc.accept(this, row));
9097
return this;
9198
}
9299

93100
// ------------------------------------------------------ builder
94101

102+
@Override
103+
public Tbody ordered(Comparator<Tr> comparator) {
104+
this.comparator = comparator;
105+
return this;
106+
}
107+
95108
@Override
96109
public Tbody that() {
97110
return this;

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL