]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fixed NPE when a connector is no longer available (#11015)
authorArtur Signell <artur@vaadin.com>
Tue, 12 Feb 2013 09:04:01 +0000 (11:04 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 13 Feb 2013 10:12:10 +0000 (12:12 +0200)
Change-Id: Ie057beb80474546e08bb27a540773ae9f89b55a2

client/src/com/vaadin/client/ui/layout/LayoutDependencyTree.java

index 4c46846d14bb3cf0f4dd78927ecb6ae71d0cdaf4..2ce45623d09bad3ce24fad3a18f736fa6f9427f7 100644 (file)
@@ -410,41 +410,73 @@ public class LayoutDependencyTree {
 
     public void setNeedsMeasure(ComponentConnector connector,
             boolean needsMeasure) {
-        setNeedsMeasure(connector.getConnectorId(), needsMeasure);
+        setNeedsHorizontalMeasure(connector, needsMeasure);
+        setNeedsVerticalMeasure(connector, needsMeasure);
     }
 
     public void setNeedsMeasure(String connectorId, boolean needsMeasure) {
-        setNeedsHorizontalMeasure(connectorId, needsMeasure);
-        setNeedsVerticalMeasure(connectorId, needsMeasure);
+        ComponentConnector connector = (ComponentConnector) ConnectorMap.get(
+                connection).getConnector(connectorId);
+        if (connector == null) {
+            return;
+        }
+
+        setNeedsMeasure(connector, needsMeasure);
     }
 
     public void setNeedsHorizontalMeasure(ComponentConnector connector,
             boolean needsMeasure) {
-        setNeedsHorizontalMeasure(connector.getConnectorId(), needsMeasure);
+        LayoutDependency dependency = getDependency(connector, HORIZONTAL);
+        dependency.setNeedsMeasure(needsMeasure);
     }
 
     public void setNeedsHorizontalMeasure(String connectorId,
             boolean needsMeasure) {
-        LayoutDependency dependency = getDependency(connectorId, HORIZONTAL);
-        dependency.setNeedsMeasure(needsMeasure);
+        // Ensure connector exists
+        ComponentConnector connector = (ComponentConnector) ConnectorMap.get(
+                connection).getConnector(connectorId);
+        if (connector == null) {
+            return;
+        }
+
+        setNeedsHorizontalMeasure(connector, needsMeasure);
     }
 
     public void setNeedsVerticalMeasure(ComponentConnector connector,
             boolean needsMeasure) {
-        setNeedsVerticalMeasure(connector.getConnectorId(), needsMeasure);
+        LayoutDependency dependency = getDependency(connector, VERTICAL);
+        dependency.setNeedsMeasure(needsMeasure);
     }
 
     public void setNeedsVerticalMeasure(String connectorId, boolean needsMeasure) {
-        LayoutDependency dependency = getDependency(connectorId, VERTICAL);
-        dependency.setNeedsMeasure(needsMeasure);
+        // Ensure connector exists
+        ComponentConnector connector = (ComponentConnector) ConnectorMap.get(
+                connection).getConnector(connectorId);
+        if (connector == null) {
+            return;
+        }
+
+        setNeedsVerticalMeasure(connector, needsMeasure);
+    }
+
+    private LayoutDependency getDependency(ComponentConnector connector,
+            int direction) {
+        return getDependency(connector.getConnectorId(), connector, direction);
     }
 
     private LayoutDependency getDependency(String connectorId, int direction) {
+        return getDependency(connectorId, null, direction);
+    }
+
+    private LayoutDependency getDependency(String connectorId,
+            ComponentConnector connector, int direction) {
         FastStringMap<LayoutDependency> dependencies = dependenciesInDirection[direction];
         LayoutDependency dependency = dependencies.get(connectorId);
         if (dependency == null) {
-            ComponentConnector connector = (ComponentConnector) ConnectorMap
-                    .get(connection).getConnector(connectorId);
+            if (connector == null) {
+                connector = (ComponentConnector) ConnectorMap.get(connection)
+                        .getConnector(connectorId);
+            }
             dependency = new LayoutDependency(connector, direction);
             dependencies.put(connectorId, dependency);
         }