Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sheet): Optimize SheetRenderer for many Rows and Columns #5805

Merged
merged 2 commits into from
Dec 14, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -483,12 +483,10 @@ public void encodeEndInternal(final FacesContext facesContext, final T component
insideEnd(facesContext, HtmlElements.TOBAGO_SHEET);
}

private void encodeTableBody(
final FacesContext facesContext, final AbstractUISheet sheet, final TobagoResponseWriter writer,
final String sheetId,
final Selectable selectable, final List<Integer> columnWidths, final List<Integer> selectedRows,
final List<AbstractUIColumnBase> columns, final boolean autoLayout, final List<Integer> expandedValue)
throws IOException {
private void encodeTableBody(final FacesContext facesContext, final AbstractUISheet sheet,
final TobagoResponseWriter writer, final String sheetId, final Selectable selectable,
final List<Integer> columnWidths, final List<Integer> selectedRows, final List<AbstractUIColumnBase> columns,
final boolean autoLayout, final List<Integer> expandedValue) throws IOException {

final boolean showHeader = sheet.isShowHeader();
final Markup sheetMarkup = sheet.getMarkup() != null ? sheet.getMarkup() : Markup.NULL;
Expand All @@ -501,7 +499,6 @@ private void encodeTableBody(

if (showHeader && !autoLayout) {
// if no autoLayout, we render the header in a separate table.

writer.startElement(HtmlElements.HEADER);
writer.startElement(HtmlElements.TABLE);
writer.writeAttribute(HtmlAttributes.CELLSPACING, "0", false);
Expand All @@ -515,7 +512,6 @@ private void encodeTableBody(
TobagoClass.TABLE_LAYOUT__FIXED);

writeColgroup(writer, columnWidths, columns, true);

writer.startElement(HtmlElements.THEAD);
encodeHeaderRows(facesContext, sheet, writer, columns);
writer.endElement(HtmlElements.THEAD);
Expand Down Expand Up @@ -544,13 +540,10 @@ private void encodeTableBody(
encodeHeaderRows(facesContext, sheet, writer, columns);
writer.endElement(HtmlElements.THEAD);
}

if (!autoLayout) {
writeColgroup(writer, columnWidths, columns, false);
}

// Print the Content

if (LOG.isDebugEnabled()) {
LOG.debug("first = " + sheet.getFirst() + " rows = " + sheet.getRows());
}
Expand All @@ -565,6 +558,19 @@ private void encodeTableBody(
final int last = (sheet.isLazy() && sheet.isRowsUnlimited()) ? sheet.getLazyFirstRow() + sheet.getLazyRows()
: sheet.isRowsUnlimited() ? Integer.MAX_VALUE : sheet.getFirst() + sheet.getRows();

AbstractUIRow row = null;
boolean[] columnRendered = new boolean[columns.size()];
for (int i = 0; i < columns.size(); i++) {
UIColumn column = columns.get(i);
if (column.isRendered()) {
columnRendered[i] = true;
if (column instanceof AbstractUIRow) {
row = (AbstractUIRow) column;
// todo: Markup.CLICKABLE ???
}
}
}

for (int rowIndex = first; rowIndex < last; rowIndex++) {
sheet.setRowIndex(rowIndex);
if (!sheet.isRowAvailable()) {
Expand Down Expand Up @@ -600,17 +606,7 @@ private void encodeTableBody(
// todo like in TreeListboxRenderer
writer.writeAttribute(DataAttributes.TREE_PARENT, parentId, false);
}

AbstractUIRow row = null;
for (final UIColumn column : columns) {
if (column.isRendered()) {
if (column instanceof AbstractUIRow) {
row = (AbstractUIRow) column;
// todo: Markup.CLICKABLE ???
}
}
}
// the row client id depends from the existence of an UIRow component! TBD: is this good?
// the row client id depends on from the existence of an UIRow component! TBD: is this good?
bohmber marked this conversation as resolved.
Show resolved Hide resolved
writer.writeIdAttribute(row != null ? row.getClientId(facesContext) : sheet.getRowClientId());
writer.writeClassAttribute(
selected ? TobagoClass.SELECTED : null,
Expand All @@ -621,8 +617,9 @@ private void encodeTableBody(
int colSpan = 0;
AbstractUIColumnPanel panel = null;

for (final AbstractUIColumnBase column : columns) {
if (column.isRendered()) {
for (int i = 0; i < columns.size(); i++) {
AbstractUIColumnBase column = columns.get(i);
if (columnRendered[i]) {
if (column instanceof AbstractUIColumn || column instanceof AbstractUIColumnSelector
|| column instanceof AbstractUIColumnNode) {
colSpan++;
Expand Down Expand Up @@ -659,7 +656,11 @@ private void encodeTableBody(
TobagoClass.SELECTED);
writer.endElement(HtmlElements.INPUT);
} else /*if (normalColumn instanceof AbstractUIColumnNode)*/ {
column.encodeAll(facesContext);
if (column.getChildCount() > 0) {
for (int k = 0; k < column.getChildCount(); k++) {
column.getChildren().get(k).encodeAll(facesContext);
}
}
} /*else {
final List<UIComponent> children = sheet.getRenderedChildrenOf(normalColumn);
for (final UIComponent grandKid : children) {
Expand All @@ -684,7 +685,6 @@ private void encodeTableBody(
writer.writeClassAttribute(TobagoClass.BEHAVIOR__CONTAINER);
encodeBehavior(writer, facesContext, row);
writer.endElement(HtmlElements.TD);

writer.endElement(HtmlElements.TR);

if (panel != null) {
Expand All @@ -698,7 +698,6 @@ private void encodeTableBody(
writer.endElement(HtmlElements.TR);
}
}

sheet.setRowIndex(-1);

if (emptySheet && showHeader) {
Expand Down Expand Up @@ -732,10 +731,8 @@ private void encodeTableBody(
}

writer.endElement(HtmlElements.TBODY);

writer.endElement(HtmlElements.TABLE);
writer.endElement(HtmlElements.DIV);

// END RENDER BODY CONTENT
}

Expand Down
Loading