]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add API for getting the parent connector's id (#8888)
authorLeif Åstrand <leif@vaadin.com>
Fri, 15 Jun 2012 10:56:10 +0000 (13:56 +0300)
committerLeif Åstrand <leif@vaadin.com>
Fri, 15 Jun 2012 10:56:10 +0000 (13:56 +0300)
src/com/vaadin/terminal/gwt/client/JavaScriptConnectorHelper.java

index 006105fed61b27d3a9167e16ed5ef5cd2676dcdc..bd62a759cbd9adb9677f23035b4ffaf38c24b7fb 100644 (file)
@@ -173,6 +173,9 @@ public class JavaScriptConnectorHelper {
             'getConnectorId': function() {
                 return connectorId;
             },
+            'getParentId': $entry(function(connectorId) {
+                return h.@com.vaadin.terminal.gwt.client.JavaScriptConnectorHelper::getParentId(Ljava/lang/String;)(connectorId);
+            }),
             'getState': function() {
                 return nativeState;
             },
@@ -208,13 +211,21 @@ public class JavaScriptConnectorHelper {
         });
     }-*/;
 
-    private Element getWidgetElement(String connectorId) {
-        if (connectorId == null) {
-            connectorId = connector.getConnectorId();
+    private String getParentId(String connectorId) {
+        ServerConnector target = getConnector(connectorId);
+        if (target == null) {
+            return null;
         }
+        ServerConnector parent = target.getParent();
+        if (parent == null) {
+            return null;
+        } else {
+            return parent.getConnectorId();
+        }
+    }
 
-        ServerConnector target = ConnectorMap.get(connector.getConnection())
-                .getConnector(connectorId);
+    private Element getWidgetElement(String connectorId) {
+        ServerConnector target = getConnector(connectorId);
         if (target instanceof ComponentConnector) {
             return ((ComponentConnector) target).getWidget().getElement();
         } else {
@@ -222,6 +233,15 @@ public class JavaScriptConnectorHelper {
         }
     }
 
+    private ServerConnector getConnector(String connectorId) {
+        if (connectorId == null || connectorId.length() == 0) {
+            return connector;
+        }
+
+        return ConnectorMap.get(connector.getConnection())
+                .getConnector(connectorId);
+    }
+
     private void fireRpc(String iface, String method,
             JsArray<JavaScriptObject> arguments) {
         if (iface == null) {