summaryrefslogtreecommitdiffstats
path: root/client
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <tsuoanttila@users.noreply.github.com>2018-09-07 12:10:16 +0300
committerIlia Motornyi <elmot@vaadin.com>2018-09-07 12:10:15 +0300
commitb2745dc14f17b510df7321ab3f6285ed317da3b3 (patch)
tree23c85cae1d7b98ed318aa7539ce87b1603404f9a /client
parent77a921791a318c60d25f5bb19823d8c2850732b0 (diff)
downloadvaadin-framework-b2745dc14f17b510df7321ab3f6285ed317da3b3.tar.gz
vaadin-framework-b2745dc14f17b510df7321ab3f6285ed317da3b3.zip
Fix handler creation to happen on init (#11172)
Fix handler creation to happen on init
Diffstat (limited to 'client')
-rw-r--r--client/src/main/java/com/vaadin/client/connectors/grid/ComponentRendererConnector.java46
1 files changed, 28 insertions, 18 deletions
diff --git a/client/src/main/java/com/vaadin/client/connectors/grid/ComponentRendererConnector.java b/client/src/main/java/com/vaadin/client/connectors/grid/ComponentRendererConnector.java
index 649cec0b36..df8ace1a4e 100644
--- a/client/src/main/java/com/vaadin/client/connectors/grid/ComponentRendererConnector.java
+++ b/client/src/main/java/com/vaadin/client/connectors/grid/ComponentRendererConnector.java
@@ -25,6 +25,7 @@ import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;
import com.vaadin.client.ComponentConnector;
import com.vaadin.client.ConnectorMap;
+import com.vaadin.client.ServerConnector;
import com.vaadin.client.renderers.Renderer;
import com.vaadin.client.renderers.WidgetRenderer;
import com.vaadin.client.ui.AbstractComponentConnector;
@@ -43,12 +44,18 @@ import com.vaadin.ui.renderers.ComponentRenderer;
*/
@Connect(ComponentRenderer.class)
public class ComponentRendererConnector
- extends AbstractGridRendererConnector<String> {
+ extends AbstractGridRendererConnector<String> {
private HashSet<String> knownConnectors = new HashSet<>();
private HandlerRegistration handlerRegistration;
@Override
+ public void setParent(ServerConnector parent) {
+ super.setParent(parent);
+ createConnectorHierarchyChangeHandler();
+ }
+
+ @Override
protected Renderer<String> createRenderer() {
return new WidgetRenderer<String, SimplePanel>() {
@@ -61,12 +68,12 @@ public class ComponentRendererConnector
@Override
public void render(RendererCellReference cell, String connectorId,
- SimplePanel widget) {
- createConnectorHierarchyChangeHandler();
+ SimplePanel widget) {
+ assert handlerRegistration != null : "HirarchyChangeHandler should not be null when rendering.";
Widget connectorWidget = null;
if (connectorId != null) {
ComponentConnector connector = (ComponentConnector) ConnectorMap
- .get(getConnection()).getConnector(connectorId);
+ .get(getConnection()).getConnector(connectorId);
if (connector != null) {
connectorWidget = connector.getWidget();
knownConnectors.add(connectorId);
@@ -95,23 +102,26 @@ public class ComponentRendererConnector
/**
* Adds a listener for grid hierarchy changes to find detached connectors
- * previously handled by this renderer in order to detach from DOM their widgets
- * before {@link AbstractComponentConnector#onUnregister()} is invoked
- * otherwise an error message is logged.
+ * previously handled by this renderer in order to detach from DOM their
+ * widgets before {@link AbstractComponentConnector#onUnregister()} is
+ * invoked otherwise an error message is logged.
*/
private void createConnectorHierarchyChangeHandler() {
- if (handlerRegistration == null) {
- handlerRegistration = getGridConnector().addConnectorHierarchyChangeHandler(event -> {
- Iterator<String> iterator = knownConnectors.iterator();
- while (iterator.hasNext()) {
- ComponentConnector connector = (ComponentConnector) ConnectorMap.get(getConnection()).getConnector(iterator.next());
- if (connector != null && connector.getParent() == null) {
- connector.getWidget().removeFromParent();
- iterator.remove();
+ assert handlerRegistration == null : "Trying to re-initialize HierarchyChangeHandler";
+ handlerRegistration = getGridConnector()
+ .addConnectorHierarchyChangeHandler(event -> {
+ Iterator<String> iterator = knownConnectors.iterator();
+ while (iterator.hasNext()) {
+ ComponentConnector connector = (ComponentConnector) ConnectorMap
+ .get(getConnection())
+ .getConnector(iterator.next());
+ if (connector != null
+ && connector.getParent() == null) {
+ connector.getWidget().removeFromParent();
+ iterator.remove();
+ }
}
- }
- });
- }
+ });
}
private void unregisterHierarchyHandler() {