summaryrefslogtreecommitdiffstats
path: root/server/src/com/vaadin/data/RpcDataProviderExtension.java
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2014-12-12 01:14:46 +0200
committerTeemu Suo-Anttila <teemusa@vaadin.com>2014-12-12 14:41:58 +0000
commitc9fe985fc34788d197417715d8d439c2ce0bc26b (patch)
tree65ef10961e662299b89443fc78fd2676f70fdab2 /server/src/com/vaadin/data/RpcDataProviderExtension.java
parent643ccd9e6a9ca6bb1d4960aa1642fa790edc9ac1 (diff)
downloadvaadin-framework-c9fe985fc34788d197417715d8d439c2ce0bc26b.tar.gz
vaadin-framework-c9fe985fc34788d197417715d8d439c2ce0bc26b.zip
Split CellStyleGenerator into separate cell and row style generators
(#13334) Change-Id: If07018b6f74ff1a4c616705f61b6118647d64342
Diffstat (limited to 'server/src/com/vaadin/data/RpcDataProviderExtension.java')
-rw-r--r--server/src/com/vaadin/data/RpcDataProviderExtension.java36
1 files changed, 29 insertions, 7 deletions
diff --git a/server/src/com/vaadin/data/RpcDataProviderExtension.java b/server/src/com/vaadin/data/RpcDataProviderExtension.java
index f28d95f610..5e56643d6e 100644
--- a/server/src/com/vaadin/data/RpcDataProviderExtension.java
+++ b/server/src/com/vaadin/data/RpcDataProviderExtension.java
@@ -49,8 +49,11 @@ import com.vaadin.shared.data.DataRequestRpc;
import com.vaadin.shared.ui.grid.GridState;
import com.vaadin.shared.ui.grid.Range;
import com.vaadin.ui.Grid;
+import com.vaadin.ui.Grid.CellReference;
import com.vaadin.ui.Grid.CellStyleGenerator;
import com.vaadin.ui.Grid.Column;
+import com.vaadin.ui.Grid.RowReference;
+import com.vaadin.ui.Grid.RowStyleGenerator;
import com.vaadin.ui.renderer.Renderer;
import elemental.json.Json;
@@ -648,6 +651,9 @@ public class RpcDataProviderExtension extends AbstractExtension {
/* Has client been initialized */
private boolean clientInitialized = false;
+ private RowReference rowReference;
+ private CellReference cellReference;
+
/**
* Creates a new data provider using the given container.
*
@@ -753,22 +759,27 @@ public class RpcDataProviderExtension extends AbstractExtension {
rowObject.put(GridState.JSONKEY_DATA, rowData);
rowObject.put(GridState.JSONKEY_ROWKEY, keyMapper.getKey(itemId));
+ rowReference.set(itemId);
+
CellStyleGenerator cellStyleGenerator = grid.getCellStyleGenerator();
if (cellStyleGenerator != null) {
- setGeneratedStyles(cellStyleGenerator, rowObject, columns, itemId);
+ setGeneratedCellStyles(cellStyleGenerator, rowObject, columns);
+ }
+ RowStyleGenerator rowStyleGenerator = grid.getRowStyleGenerator();
+ if (rowStyleGenerator != null) {
+ setGeneratedRowStyles(rowStyleGenerator, rowObject);
}
return rowObject;
}
- private void setGeneratedStyles(CellStyleGenerator generator,
- JsonObject rowObject, Collection<Column> columns, Object itemId) {
- Grid grid = getGrid();
-
+ private void setGeneratedCellStyles(CellStyleGenerator generator,
+ JsonObject rowObject, Collection<Column> columns) {
JsonObject cellStyles = null;
for (Column column : columns) {
Object propertyId = column.getColumnProperty();
- String style = generator.getStyle(grid, itemId, propertyId);
+ cellReference.set(propertyId);
+ String style = generator.getStyle(cellReference);
if (style != null) {
if (cellStyles == null) {
cellStyles = Json.createObject();
@@ -782,7 +793,11 @@ public class RpcDataProviderExtension extends AbstractExtension {
rowObject.put(GridState.JSONKEY_CELLSTYLES, cellStyles);
}
- String rowStyle = generator.getStyle(grid, itemId, null);
+ }
+
+ private void setGeneratedRowStyles(RowStyleGenerator generator,
+ JsonObject rowObject) {
+ String rowStyle = generator.getStyle(rowReference);
if (rowStyle != null) {
rowObject.put(GridState.JSONKEY_ROWSTYLE, rowStyle);
}
@@ -886,6 +901,13 @@ public class RpcDataProviderExtension extends AbstractExtension {
.removeItemSetChangeListener(itemListener);
}
+ } else if (parent instanceof Grid) {
+ Grid grid = (Grid) parent;
+ rowReference = new RowReference(grid);
+ cellReference = new CellReference(rowReference);
+ } else {
+ throw new IllegalStateException(
+ "Grid is the only accepted parent type");
}
}