diff options
author | Leif Åstrand <leif@vaadin.com> | 2014-12-04 15:43:48 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2014-12-04 14:35:39 +0000 |
commit | ca061119cabe564c5d2205865d95a5e5ed496c6a (patch) | |
tree | 261d7e569353c3315c5b3ba90f1d558bf74711d6 /client/src | |
parent | c817f2c578839db70011889533f4c666638685cf (diff) | |
download | vaadin-framework-ca061119cabe564c5d2205865d95a5e5ed496c6a.tar.gz vaadin-framework-ca061119cabe564c5d2205865d95a5e5ed496c6a.zip |
Add server-side CellStyleGenerator (#13334)
Change-Id: Id12f1135673d93fddd0a59d26b1c546a0ef0ee1d
Diffstat (limited to 'client/src')
-rw-r--r-- | client/src/com/vaadin/client/ui/grid/GridConnector.java | 39 |
1 files changed, 39 insertions, 0 deletions
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<JSONObject> { + @Override + public String getStyle(Grid<JSONObject> grid, JSONObject row, + int rowIndex, GridColumn<?, JSONObject> 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; |