summaryrefslogtreecommitdiffstats
path: root/compatibility-server
diff options
context:
space:
mode:
authorAndrey B. Panfilov <andrew@panfilov.tel>2020-08-12 15:20:02 +0300
committerGitHub <noreply@github.com>2020-08-12 15:20:02 +0300
commitb31ed94eaef94e989c70ea57bb8b8ecdca2e7fc4 (patch)
tree3048dbeca1d535214b270ae698b4fdd8f5786711 /compatibility-server
parent7406f478b9186b75b7f3b8c5df27c5a8de17f9e1 (diff)
downloadvaadin-framework-b31ed94eaef94e989c70ea57bb8b8ecdca2e7fc4.tar.gz
vaadin-framework-b31ed94eaef94e989c70ea57bb8b8ecdca2e7fc4.zip
Row Generator fixes (#12027)
NOTE: components within row generator are not an officially supported feature and can cause issues within your application.
Diffstat (limited to 'compatibility-server')
-rw-r--r--compatibility-server/src/main/java/com/vaadin/v7/ui/Table.java100
1 files changed, 67 insertions, 33 deletions
diff --git a/compatibility-server/src/main/java/com/vaadin/v7/ui/Table.java b/compatibility-server/src/main/java/com/vaadin/v7/ui/Table.java
index 2cd3ad075e..872f70feae 100644
--- a/compatibility-server/src/main/java/com/vaadin/v7/ui/Table.java
+++ b/compatibility-server/src/main/java/com/vaadin/v7/ui/Table.java
@@ -2282,20 +2282,33 @@ public class Table extends AbstractSelect implements Action.Container,
}
}
- GeneratedRow generatedRow = rowGenerator != null
- ? rowGenerator.generateRow(this, id)
- : null;
- cells[CELL_GENERATED_ROW][i] = generatedRow;
+ int index = firstIndex + i;
+ int indexInOldBuffer = index - pageBufferFirstIndex;
+ boolean inPageBuffer = index < firstIndexNotInCache
+ && index >= pageBufferFirstIndex
+ && id.equals(pageBuffer[CELL_ITEMID][indexInOldBuffer]);
+
+ GeneratedRow generatedRow = null;
+ if (rowGenerator != null) {
+ if (inPageBuffer) {
+ generatedRow = (GeneratedRow) pageBuffer[CELL_GENERATED_ROW][indexInOldBuffer];
+ } else {
+ generatedRow = rowGenerator.generateRow(this, cells[CELL_ITEMID][i]);
+ }
+ cells[CELL_GENERATED_ROW][i] = generatedRow;
+ }
+ int firstNotCollapsed = -1;
for (int j = 0; j < cols; j++) {
if (isColumnCollapsed(colids[j])) {
continue;
+ } else if (firstNotCollapsed == -1) {
+ firstNotCollapsed = j;
}
Property<?> p = null;
Object value = "";
- boolean isGeneratedRow = generatedRow != null;
boolean isGeneratedColumn = columnGenerators.containsKey(colids[j]);
- boolean isGenerated = isGeneratedRow || isGeneratedColumn;
+ boolean isGenerated = isGeneratedColumn || generatedRow != null;
if (!isGenerated) {
try {
@@ -2306,33 +2319,24 @@ public class Table extends AbstractSelect implements Action.Container,
}
}
- if (isGeneratedRow) {
- if (generatedRow.isSpanColumns() && j > 0) {
- value = null;
- } else if (generatedRow.isSpanColumns() && j == 0
- && generatedRow.getValue() instanceof Component) {
- value = generatedRow.getValue();
- } else if (generatedRow.getText().length > j) {
- value = generatedRow.getText()[j];
- }
- } else {
- // check if current pageBuffer already has row
- int index = firstIndex + i;
- if (p != null || isGenerated) {
- int indexInOldBuffer = index - pageBufferFirstIndex;
- if (index < firstIndexNotInCache
- && index >= pageBufferFirstIndex
- && pageBuffer[CELL_GENERATED_ROW][indexInOldBuffer] == null
- && id.equals(
- pageBuffer[CELL_ITEMID][indexInOldBuffer])) {
- // we already have data in our cache,
- // recycle it instead of fetching it via
- // getValue/getPropertyValue
+ // check if current pageBuffer already has row
+ if (p != null || isGenerated) {
+ if (inPageBuffer) {
+ // we already have data in our cache,
+ // recycle it instead of fetching it via
+ // getValue/getPropertyValue
+ if (generatedRow != null) {
+ value = extractGeneratedValue(generatedRow, j, j == firstNotCollapsed);
+ } else {
value = pageBuffer[CELL_FIRSTCOL + j][indexInOldBuffer];
- if (!isGeneratedColumn && iscomponent[j]
- || !(value instanceof Component)) {
- listenProperty(p, oldListenedProperties);
- }
+ }
+ if (!isGeneratedColumn && iscomponent[j]
+ || !(value instanceof Component)) {
+ listenProperty(p, oldListenedProperties);
+ }
+ } else {
+ if (generatedRow != null) {
+ value = extractGeneratedValue(generatedRow, j, j == firstNotCollapsed);
} else {
if (isGeneratedColumn) {
ColumnGenerator cg = columnGenerators
@@ -2395,6 +2399,35 @@ public class Table extends AbstractSelect implements Action.Container,
}
}
+ /**
+ * Extracts cell value from generated row
+ *
+ * @param generatedRow generated row
+ * @param index column index
+ * @param firstVisibleColumn whether the column is first visible column in the table (i.e. previous columns are hidden)
+ * @return cell value
+ */
+ private Object extractGeneratedValue(GeneratedRow generatedRow, int index, boolean firstVisibleColumn) {
+ Object value = generatedRow.getValue();
+ String[] text = generatedRow.getText();
+ if (generatedRow.isSpanColumns()) {
+ if (firstVisibleColumn) {
+ if (value instanceof Component) {
+ return value;
+ }
+ if (text != null && text.length > 0) {
+ return text[0];
+ }
+ }
+ return null;
+ }
+
+ if (text != null && text.length > index) {
+ return text[index];
+ }
+ return null;
+ }
+
protected void registerComponent(Component component) {
getLogger().log(Level.FINEST, "Registered {0}: {1}", new Object[] {
component.getClass().getSimpleName(), component.getCaption() });
@@ -3990,8 +4023,9 @@ public class Table extends AbstractSelect implements Action.Container,
target.addAttribute("gen_html",
generatedRow.isHtmlContentAllowed());
target.addAttribute("gen_span", generatedRow.isSpanColumns());
+ // todo: actually gen_widget is never used
target.addAttribute("gen_widget",
- generatedRow.getValue() instanceof Component);
+ cells[CELL_FIRSTCOL][indexInRowBuffer] instanceof Component);
}
}