From 86dbe3f2b39c84b5b2697997b813cc85ce33ce10 Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Fri, 16 Mar 2012 20:43:34 +0200 Subject: [PATCH] Made debug id:s work again --- .../terminal/gwt/client/ComponentLocator.java | 39 +++++++++++++++++-- .../terminal/gwt/client/ComponentState.java | 23 +++++++++++ .../client/ui/AbstractComponentConnector.java | 9 +++-- src/com/vaadin/ui/AbstractComponent.java | 6 +-- 4 files changed, 66 insertions(+), 11 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ComponentLocator.java b/src/com/vaadin/terminal/gwt/client/ComponentLocator.java index fa8b3fc179..f954105120 100644 --- a/src/com/vaadin/terminal/gwt/client/ComponentLocator.java +++ b/src/com/vaadin/terminal/gwt/client/ComponentLocator.java @@ -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. * diff --git a/src/com/vaadin/terminal/gwt/client/ComponentState.java b/src/com/vaadin/terminal/gwt/client/ComponentState.java index 371b8dc358..407782756f 100644 --- a/src/com/vaadin/terminal/gwt/client/ComponentState.java +++ b/src/com/vaadin/terminal/gwt/client/ComponentState.java @@ -30,6 +30,7 @@ public class ComponentState extends SharedState { private boolean visible = true; private URLReference icon = null; private List 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; + } + } diff --git a/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java b/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java index c7f58df835..f1529c0087 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java +++ b/src/com/vaadin/terminal/gwt/client/ui/AbstractComponentConnector.java @@ -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()) { diff --git a/src/com/vaadin/ui/AbstractComponent.java b/src/com/vaadin/ui/AbstractComponent.java index 2c5dfbe6f3..cc5ec68ecc 100644 --- a/src/com/vaadin/ui/AbstractComponent.java +++ b/src/com/vaadin/ui/AbstractComponent.java @@ -100,8 +100,6 @@ public abstract class AbstractComponent implements Component, MethodEventSource */ private LinkedList 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(); } /** -- 2.39.5