]> source.dussan.org Git - vaadin-framework.git/commitdiff
Made debug id:s work again
authorArtur Signell <artur@vaadin.com>
Fri, 16 Mar 2012 18:43:34 +0000 (20:43 +0200)
committerArtur Signell <artur@vaadin.com>
Wed, 21 Mar 2012 13:27:38 +0000 (15:27 +0200)
src/com/vaadin/terminal/gwt/client/ComponentLocator.java
src/com/vaadin/terminal/gwt/client/ComponentState.java
src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java
src/com/vaadin/ui/AbstractComponent.java

index fa8b3fc179bb481ddfb1351f87bb0322df1ee690..f954105120b90046001fae4d6d7954e72b3abcab 100644 (file)
@@ -440,9 +440,23 @@ public class ComponentLocator {
             } else if (part.equals("")) {
                 w = client.getView().getWidget();
             } else if (w == null) {
-                // Must be static pid (PID_S*)
-                w = ((ComponentConnector) ConnectorMap.get(client)
-                        .getConnector(part)).getWidget();
+                String id = part;
+                // Must be old static pid (PID_S*)
+                ComponentConnector connector = (ComponentConnector) ConnectorMap
+                        .get(client).getConnector(id);
+                if (connector == null) {
+                    // Lookup by debugId
+                    // TODO Optimize this
+                    connector = findConnectorById(client.getView(),
+                            id.substring(5));
+                }
+
+                if (connector != null) {
+                    w = connector.getWidget();
+                } else {
+                    // Not found
+                    return null;
+                }
             } else if (part.startsWith("domChild[")) {
                 // The target widget has been found and the rest identifies the
                 // element
@@ -570,6 +584,25 @@ public class ComponentLocator {
         return w;
     }
 
+    private ComponentConnector findConnectorById(ComponentConnector root,
+            String id) {
+        if (root instanceof ComponentConnector
+                && id.equals(root.getState().getDebugId())) {
+            return root;
+        }
+        if (root instanceof ComponentContainerConnector) {
+            ComponentContainerConnector ccc = (ComponentContainerConnector) root;
+            for (ComponentConnector child : ccc.getChildren()) {
+                ComponentConnector found = findConnectorById(child, id);
+                if (found != null) {
+                    return found;
+                }
+            }
+        }
+
+        return null;
+    }
+
     /**
      * Checks if the given pid is a static pid.
      * 
index 371b8dc358d44d9a582be81c6ad1534c2ca1b9fc..407782756f3549aba912d207c7e42967a488c010 100644 (file)
@@ -30,6 +30,7 @@ public class ComponentState extends SharedState {
     private boolean visible = true;
     private URLReference icon = null;
     private List<String> styles = null;
+    private String debugId = null;
 
     /**
      * Returns the component height as set by the server.
@@ -296,4 +297,26 @@ public class ComponentState extends SharedState {
         this.styles = styles;
     }
 
+    /**
+     * Gets the debug id for the component. The debugId is added as DOM id for
+     * the component.
+     * 
+     * @return The debug id for the component or null if not set
+     */
+    public String getDebugId() {
+        return debugId;
+    }
+
+    /**
+     * Sets the debug id for the component. The debugId is added as DOM id for
+     * the component.
+     * 
+     * @param debugId
+     *            The new debugId for the component or null for no debug id
+     * 
+     */
+    public void setDebugId(String debugId) {
+        this.debugId = debugId;
+    }
+
 }
index c7f58df835a173fb62dae06deb91944d993f6c5e..f1529c0087f6a11fdfb62a2700eddb07998a502c 100644 (file)
@@ -4,7 +4,6 @@
 package com.vaadin.terminal.gwt.client.ui;
 
 import com.google.gwt.core.client.GWT;
-import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.ui.FocusWidget;
 import com.google.gwt.user.client.ui.Focusable;
 import com.google.gwt.user.client.ui.Widget;
@@ -132,9 +131,11 @@ public abstract class AbstractComponentConnector extends AbstractConnector
         // Visibility
         setVisible(!uidl.getBooleanAttribute("invisible"), uidl);
 
-        if (uidl.getId().startsWith("PID_S")) {
-            DOM.setElementProperty(getWidget().getElement(), "id", uidl.getId()
-                    .substring(5));
+        if (getState().getDebugId() != null) {
+            getWidget().getElement().setId(getState().getDebugId());
+        } else {
+            getWidget().getElement().setId(null);
+
         }
 
         if (!isVisible()) {
index 2c5dfbe6f32bcc0612fa25ab36723ec81e4448cd..cc5ec68ecce69ea75c343bde126d89e19a9790a3 100644 (file)
@@ -100,8 +100,6 @@ public abstract class AbstractComponent implements Component, MethodEventSource
      */
     private LinkedList<RepaintRequestListener> repaintRequestListeners = null;
 
-    private String testingId;
-
     /* Sizeable fields */
 
     private float width = SIZE_UNDEFINED;
@@ -156,11 +154,11 @@ public abstract class AbstractComponent implements Component, MethodEventSource
     /* Get/Set component properties */
 
     public void setDebugId(String id) {
-        testingId = id;
+        getState().setDebugId(id);
     }
 
     public String getDebugId() {
-        return testingId;
+        return getState().getDebugId();
     }
 
     /**