From ca061119cabe564c5d2205865d95a5e5ed496c6a Mon Sep 17 00:00:00 2001 From: Leif Åstrand Date: Thu, 4 Dec 2014 15:43:48 +0200 Subject: Add server-side CellStyleGenerator (#13334) Change-Id: Id12f1135673d93fddd0a59d26b1c546a0ef0ee1d --- .../com/vaadin/client/ui/grid/GridConnector.java | 39 ++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'client/src') diff --git a/client/src/com/vaadin/client/ui/grid/GridConnector.java b/client/src/com/vaadin/client/ui/grid/GridConnector.java index 2388516a2d..671fd259d6 100644 --- a/client/src/com/vaadin/client/ui/grid/GridConnector.java +++ b/client/src/com/vaadin/client/ui/grid/GridConnector.java @@ -41,6 +41,7 @@ import com.vaadin.client.data.RpcDataSourceConnector.RpcDataSource; import com.vaadin.client.ui.AbstractFieldConnector; import com.vaadin.client.ui.AbstractHasComponentsConnector; import com.vaadin.client.ui.SimpleManagedLayout; +import com.vaadin.client.ui.grid.Grid.CellStyleGenerator; import com.vaadin.client.ui.grid.GridHeader.HeaderRow; import com.vaadin.client.ui.grid.renderers.AbstractRendererConnector; import com.vaadin.client.ui.grid.selection.AbstractRowHandleSelectionModel; @@ -81,6 +82,35 @@ import com.vaadin.shared.ui.grid.SortDirection; public class GridConnector extends AbstractHasComponentsConnector implements SimpleManagedLayout { + private static final class CustomCellStyleGenerator implements + CellStyleGenerator { + @Override + public String getStyle(Grid grid, JSONObject row, + int rowIndex, GridColumn column, int columnIndex) { + if (column == null) { + JSONValue styleValue = row.get(GridState.JSONKEY_ROWSTYLE); + if (styleValue != null) { + return styleValue.isString().stringValue(); + } else { + return null; + } + } else { + JSONValue cellstyles = row.get(GridState.JSONKEY_CELLSTYLES); + if (cellstyles == null) { + return null; + } + + CustomGridColumn c = (CustomGridColumn) column; + JSONValue styleValue = cellstyles.isObject().get(c.id); + if (styleValue != null) { + return styleValue.isString().stringValue(); + } else { + return null; + } + } + } + } + /** * Custom implementation of the custom grid column using a JSONObject to * represent the cell value and String as a column type. @@ -644,6 +674,15 @@ public class GridConnector extends AbstractHasComponentsConnector implements } } + @OnStateChange("hasCellStyleGenerator") + private void onCellStyleGeneratorChange() { + if (getState().hasCellStyleGenerator) { + getWidget().setCellStyleGenerator(new CustomCellStyleGenerator()); + } else { + getWidget().setCellStyleGenerator(null); + } + } + @OnStateChange("selectedKeys") private void updateSelectionFromState() { boolean changed = false; -- cgit v1.2.3