Renames and API improvements for html table wrappers#24264
Open
Renames and API improvements for html table wrappers#24264
Conversation
Adds a new Table component family (Table, TableBody, TableHead, TableFoot, TableRow, TableHeaderCell, TableDataCell, TableCaption, TableRowContainer) that exposes only spec-compliant operations, replacing the NativeTable family which inherited a generic add(Component) API allowing structurally invalid tables. The NativeTable* classes are deprecated in favor of the new types. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Addresses gaps surfaced from early Table API use: - Adds TableColumn (`<col>`) and TableColumnGroup (`<colgroup>`), wired into Table at the spec-correct position (after caption, before head). Multiple groups are supported. - Introduces an abstract TableCell base class so colspan/rowspan now apply to TableHeaderCell as well as TableDataCell, matching the HTML spec (both `<td>` and `<th>` accept these attributes). - Adds Table#addCaption(Component...) for richer captions and TableRow#addRowHeaderCell(String) shortcut for `<th scope="row">`, the most common row-label pattern in tutorials. - Adds COL/COLGROUP Tag constants. - Filters abstract HtmlComponent subclasses out of the smoke test so TableCell does not need a synthetic instantiation path. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The HTML headers attribute lets a cell point at the ids of the header
cells that label it — assistive technologies use it to announce the
right headers when reading complex tables (MDN's accessibility section
relies on it). Until now users had to fall back to
getElement().setAttribute("headers", "…").
Adds to TableCell:
- setHeaders(String... ids) primary form, space-joins ids
- setHeaders(TableHeaderCell... cells) resolves ids from header cells
- getHeaders() returning Optional<String[]>
- resetHeaders()
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The previous Scope enum doc said only "specifies which cells the header relates to" — useful but thin. MDN gives meaningful per-value semantics, so this commit adopts that level of detail and adds @see references to MDN element pages where appropriate. - TableHeaderCell.Scope: per-value javadocs explaining what each scope keyword means (row/col/rowgroup/colgroup) and a note that AUTO writes the literal "auto" string which browsers treat as if the attribute were absent. - TableHeaderCell, TableCell, TableColumn, TableColumnGroup, Table: richer class-level descriptions including accessibility purpose, CSS limitations on col/colgroup, browser limits for colspan/rowspan, and links to MDN. - TableCell#setHeaders: spell out the accessibility role and how it complements the scope attribute. - TableHeaderCell#setScope: emphasize accessibility impact. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Mostly line-wrapping touch-ups from spotless on files left over from
the original Table-API commit. Three files (TableBody, TableFoot,
TableHead) also needed a manual fix where spotless mangled
{@code <tr>} into a multi-line block with an orphan <tr> outside
the inline-code wrapper; rewritten as <code><tr></code> to be
robust to the formatter.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
Did the component team gave up? :D #18553 (comment) |
Member
Author
|
@knoobie, referring to the "naming" part ("Native" prefix)? |
Member
Author
|
I would rename all other "Native*" things to "Html*" if there are conclicts. (I'm probably the one to blame of that original invention of "Native" prefix in V6 era and I don't like it 😊). If there are no conflicts, then package name is enough. Now, after some many years after Table in V7 & 8, I think there is no more reason for avoiding conclicts with those two. |
Contributor
|
I personally don't care :D All I want is consistency |
The new TableRow API inherited the getAllCells() name from the deprecated NativeTableRow, but the "All" prefix is asymmetric with its singular pair getCell(int) and with the kind-specific pairs (getDataCell/getDataCells, getHeaderCell/getHeaderCells). Plain getCells() matches the standard Java collection naming and is unambiguous since the cell types are already distinct classes. Safe to rename since the new Table API is unreleased on this branch. NativeTableRow.getAllCells() is unchanged. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Both walk every section in document order — head, then bodies in order, then foot — matching the browser DOM's HTMLTableElement.rows. Convenience for "iterate/count all rows" or "clear the table" cases without forcing the caller to merge section-specific lists. The section elements themselves are kept by removeAllRows(); use removeHead/removeBody/removeFoot to drop them. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Now that TableCell is the shared abstract superclass of TableDataCell and TableHeaderCell, the row's getCells/getCell return types and the constructor / addCells parameter types can be narrowed: - getCells(): List<Component> → List<TableCell> - getCell(int): Optional<Component> → Optional<TableCell> - TableRow(...): Component... → TableCell... - addCells(...): Component... → TableCell... The runtime instanceof checks (and IllegalArgumentException paths) in the constructor and addCells become unnecessary — the type system enforces the constraint at compile time. Removed the two tests that exercised those runtime guards. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The indexed get/remove methods duplicated what the corresponding list accessors already provide via List.get(i): - getCell(int), getDataCell(int), getHeaderCell(int) removed - removeCell(int), removeDataCell(int), removeHeaderCell(int) removed - removeDataCell(TableDataCell), removeHeaderCell(TableHeaderCell) collapsed into a single removeCell(TableCell) The only behavioral difference removed is Optional<T> on out-of-bounds vs List.get's IndexOutOfBoundsException — minor, and List.get's behavior is the standard one. Net effect: API is smaller and more uniform; callers index into getCells() / getDataCells() / getHeaderCells() directly. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…tainer Following the same trim applied to TableRow, removed methods that duplicate what list accessors already provide: TableRowContainer (TableHead/TableBody/TableFoot): - getRow(int) → getRows().get(i) - removeRow(int) → removeRows(getRows().get(i)) - getRowIndex(row) → getRows().indexOf(row) - getRowCount() → getRows().size() (the long return type was an oddity vs List.size's int) Table: - getBody(int) → getBodies().get(i) Also drops the surprising overload contract where getBody(0) *created* a body if none existed; the no-arg getBody() remains the documented "first or create" entry point used by addRow, addHeaderRow, addFooterRow and friends. - removeBody(int) → removeBody(getBodies().get(i)) - removeBody() (no-arg, "remove first") — minor convenience Tests updated to call the list equivalents; the obviously-redundant test methods (getBodyByIndex, getNonExistentBodyByIndex, removeBody, removeBodyByIndex, getRow, getNonExistentRow, getRowIndex, removeRowByIndex, getRowCount) removed since their behavior is now the standard List contract. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Relax the parameter type from TableCell... back to Component...,
but with smart handling: TableCell instances (TableDataCell or
TableHeaderCell) are placed as-is, anything else is wrapped in a
new TableDataCell. The structural invariant that <tr> only contains
<td>/<th> is still preserved at runtime — wrapping is a one-line
ergonomic shortcut so callers don't have to write
new TableDataCell(component) for every non-cell child.
Now this works:
new TableRow(new Span("hi"), new TableHeaderCell("h"))
producing <tr><td><span>hi</span></td><th>h</th></tr>.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Each varargs method and constructor in the new Table API now has a matching List overload, so callers holding a List<T> don't have to convert it via toArray. The varargs version delegates to the List version via Arrays.asList for a single source of truth. Affected: - Table: addCaption, addColumnGroup(TableColumn...), addRow, addRows, addHeaderRow, addHeaderRows, addFooterRow, addFooterRows - TableRow: constructor, addDataCells, addHeaderCells, addCells - TableRowContainer: addRows, removeRows - TableColumnGroup: constructor, addColumns - TableHead/Body/Foot: constructors - TableDataCell, TableHeaderCell, TableCell (protected): constructors - TableCell: setHeaders(String...) gains setHeaders(List<String>); setHeaders(TableHeaderCell...) gains setHeadersByCells( List<? extends TableHeaderCell>) — different name due to type erasure (List<String> and List<TableHeaderCell> share the same erased signature). Smoke test special-cases the new setHeaders/setHeadersByCells overloads since their parameter types don't match the Optional<String[]> return of getHeaders. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Brings the API to the level of the original html-table add-on + some naming improvements.
Type of change
Usage example for the new API