diff options
author | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-12-01 13:54:29 +0200 |
---|---|---|
committer | Teemu Suo-Anttila <teemusa@vaadin.com> | 2015-12-22 11:24:43 +0000 |
commit | 0404d39ac566c83c6d8127945f9dcf1e73958938 (patch) | |
tree | 48baf5bc2307c41fc154477d1e60905b28c5f1e9 /client | |
parent | 5bed76664451af587f39a3d548f11ec210e38167 (diff) | |
download | vaadin-framework-0404d39ac566c83c6d8127945f9dcf1e73958938.tar.gz vaadin-framework-0404d39ac566c83c6d8127945f9dcf1e73958938.zip |
Fix WidgetRenderer column cells not correctly init on change (#19086)
When changing to a widget renderer with an existing column, the widget
renderer expects that the cells would be initialized to have a correct
widget for it. Because of original design where you could not change
renderers, this was not taken into account and cells did not get
reinitialized when changing the renderer.
This patch showed another underlying detach problem from removing a
widget renderer and destroying complex renderers. These both are also
addressed to make this bug possible to test correctly.
Patch includes a client-side test that verifies the integrity of the
renderer state in different stages of its lifecycle.
Change-Id: I67330e5d07c95047cb69040e8355a17dc8a96f08
Diffstat (limited to 'client')
-rw-r--r-- | client/src/com/vaadin/client/connectors/MultiSelectionModelConnector.java | 1 | ||||
-rw-r--r-- | client/src/com/vaadin/client/widgets/Grid.java | 30 |
2 files changed, 29 insertions, 2 deletions
diff --git a/client/src/com/vaadin/client/connectors/MultiSelectionModelConnector.java b/client/src/com/vaadin/client/connectors/MultiSelectionModelConnector.java index 04c56a5b44..5d00619995 100644 --- a/client/src/com/vaadin/client/connectors/MultiSelectionModelConnector.java +++ b/client/src/com/vaadin/client/connectors/MultiSelectionModelConnector.java @@ -128,7 +128,6 @@ public class MultiSelectionModelConnector extends } }); } else if (renderer != null) { - renderer.destroy(); selectAll.removeHandler(); dataAvailable.removeHandler(); renderer = null; diff --git a/client/src/com/vaadin/client/widgets/Grid.java b/client/src/com/vaadin/client/widgets/Grid.java index f96ee69010..806bc6a220 100644 --- a/client/src/com/vaadin/client/widgets/Grid.java +++ b/client/src/com/vaadin/client/widgets/Grid.java @@ -4791,8 +4791,36 @@ public class Grid<T> extends ResizeComposite implements } if (renderer != bodyRenderer) { + // Variables used to restore removed column. + boolean columnRemoved = false; + double widthInConfiguration = 0.0d; + ColumnConfiguration conf = null; + int index = 0; + + if (grid != null + && (bodyRenderer instanceof WidgetRenderer || renderer instanceof WidgetRenderer)) { + // Column needs to be recreated. + index = grid.getColumns().indexOf(this); + conf = grid.escalator.getColumnConfiguration(); + widthInConfiguration = conf.getColumnWidth(index); + + conf.removeColumns(index, 1); + columnRemoved = true; + } + + // Complex renderers need to be destroyed. + if (bodyRenderer instanceof ComplexRenderer) { + ((ComplexRenderer) bodyRenderer).destroy(); + } + bodyRenderer = renderer; + if (columnRemoved) { + // Restore the column. + conf.insertColumns(index, 1); + conf.setColumnWidth(index, widthInConfiguration); + } + if (grid != null) { grid.refreshBody(); } @@ -5486,7 +5514,7 @@ public class Grid<T> extends ResizeComposite implements if (renderer instanceof WidgetRenderer) { try { Widget w = WidgetUtil.findWidget(cell.getElement() - .getFirstChildElement(), Widget.class); + .getFirstChildElement(), null); if (w != null) { // Logical detach |