diff options
author | Patrik Lindström <patrik@vaadin.com> | 2015-03-24 12:58:25 +0200 |
---|---|---|
committer | Anna Koskinen <anna@vaadin.com> | 2015-03-26 15:27:36 +0000 |
commit | aaae44fe637a5416a25655510379bb215c9de7b5 (patch) | |
tree | 8e3c6f1b797c28af07fef0013e88317169e854c3 /client | |
parent | b96861c1809d12f2d1339fd64f825a3c513977d2 (diff) | |
download | vaadin-framework-aaae44fe637a5416a25655510379bb215c9de7b5.tar.gz vaadin-framework-aaae44fe637a5416a25655510379bb215c9de7b5.zip |
Make Grid update column renderers (#16552)
Change-Id: I3adf9d0cc32f800a535a82ffe5d6ba503a36e746
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/connectors/GridConnector.java | 32 | ||||
-rw-r--r-- | client/src/com/vaadin/client/widgets/Grid.java | 10 |
2 files changed, 22 insertions, 20 deletions
diff --git a/client/src/com/vaadin/client/connectors/GridConnector.java b/client/src/com/vaadin/client/connectors/GridConnector.java index 55f07ecf85..5e9dfc6101 100644 --- a/client/src/com/vaadin/client/connectors/GridConnector.java +++ b/client/src/com/vaadin/client/connectors/GridConnector.java @@ -165,6 +165,18 @@ public class GridConnector extends AbstractHasComponentsConnector implements this.id = id; } + /** + * Sets a new renderer for this column object + * + * @param rendererConnector + * a renderer connector object + */ + public void setRenderer( + AbstractRendererConnector<Object> rendererConnector) { + setRenderer(rendererConnector.getRenderer()); + this.rendererConnector = rendererConnector; + } + @Override public Object getValue(final JsonObject obj) { final JsonObject rowData = obj.getObject(GridState.JSONKEY_DATA); @@ -178,16 +190,6 @@ public class GridConnector extends AbstractHasComponentsConnector implements return null; } - /* - * Only used to check that the renderer connector will not change during - * the column lifetime. - * - * TODO remove once support for changing renderers is implemented - */ - private AbstractRendererConnector<Object> getRendererConnector() { - return rendererConnector; - } - private AbstractFieldConnector getEditorConnector() { return editorConnector; } @@ -730,13 +732,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements */ private void updateColumnFromStateChangeEvent(GridColumnState columnState) { CustomGridColumn column = columnIdToColumn.get(columnState.id); - updateColumnFromState(column, columnState); - - if (columnState.rendererConnector != column.getRendererConnector()) { - throw new UnsupportedOperationException( - "Changing column renderer after initialization is currently unsupported"); - } } /** @@ -780,6 +776,7 @@ public class GridConnector extends AbstractHasComponentsConnector implements * @param state * The state to get the data from */ + @SuppressWarnings("unchecked") private static void updateColumnFromState(CustomGridColumn column, GridColumnState state) { column.setWidth(state.width); @@ -787,6 +784,9 @@ public class GridConnector extends AbstractHasComponentsConnector implements column.setMaximumWidth(state.maxWidth); column.setExpandRatio(state.expandRatio); + assert state.rendererConnector instanceof AbstractRendererConnector : "GridColumnState.rendererConnector is invalid (not subclass of AbstractRendererConnector)"; + column.setRenderer((AbstractRendererConnector<Object>) state.rendererConnector); + column.setSortable(state.sortable); column.setEditable(state.editable); column.setEditorConnector((AbstractFieldConnector) state.editorConnector); diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index d9845bcdc8..31cf4ec866 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -3115,12 +3115,14 @@ public class Grid<T> extends ResizeComposite implements if (renderer == null) { throw new IllegalArgumentException("Renderer cannot be null."); } - bodyRenderer = renderer; - if (grid != null) { - grid.refreshBody(); - } + if (renderer != bodyRenderer) { + bodyRenderer = renderer; + if (grid != null) { + grid.refreshBody(); + } + } return this; } |