From 0404d39ac566c83c6d8127945f9dcf1e73958938 Mon Sep 17 00:00:00 2001 From: Teemu Suo-Anttila Date: Tue, 1 Dec 2015 13:54:29 +0200 Subject: 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 --- .../connectors/MultiSelectionModelConnector.java | 1 - client/src/com/vaadin/client/widgets/Grid.java | 30 +++++++++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) (limited to 'client/src/com') 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 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 extends ResizeComposite implements if (renderer instanceof WidgetRenderer) { try { Widget w = WidgetUtil.findWidget(cell.getElement() - .getFirstChildElement(), Widget.class); + .getFirstChildElement(), null); if (w != null) { // Logical detach -- cgit v1.2.3