From 3ff57aaa66c1910eca584621c46166a330bffd7f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Wed, 15 Feb 2012 18:06:16 +0200 Subject: [PATCH] Simulate ChildComponentContainer in the new OrderedLayouts (#8313) --- .../terminal/gwt/client/ComponentLocator.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/com/vaadin/terminal/gwt/client/ComponentLocator.java b/src/com/vaadin/terminal/gwt/client/ComponentLocator.java index f49f99a477..0a35c2d32c 100644 --- a/src/com/vaadin/terminal/gwt/client/ComponentLocator.java +++ b/src/com/vaadin/terminal/gwt/client/ComponentLocator.java @@ -12,6 +12,7 @@ import com.google.gwt.user.client.ui.HasWidgets; import com.google.gwt.user.client.ui.RootPanel; import com.google.gwt.user.client.ui.Widget; import com.vaadin.terminal.gwt.client.ui.SubPartAware; +import com.vaadin.terminal.gwt.client.ui.VMeasuringOrderedLayout; import com.vaadin.terminal.gwt.client.ui.VView; import com.vaadin.terminal.gwt.client.ui.VWindow; @@ -457,6 +458,57 @@ public class ComponentLocator { int widgetPosition = Integer.parseInt(indexString.substring(0, indexString.length() - 1)); + /* + * The new ordered layotus do not contain + * ChildComponentContainer widgets. This is instead simulated by + * constructing a path step that would find the desired widget + * from the layout and injecting it as the next search step + * (which would originally have found the widget inside the + * ChildComponentContainer) + */ + if (w instanceof VMeasuringOrderedLayout + && "ChildComponentContainer".equals(widgetClassName) + && i + 1 < parts.length) { + + VMeasuringOrderedLayout layout = (VMeasuringOrderedLayout) w; + + String nextPart = parts[i + 1]; + String[] nextSplit = nextPart.split("\\[", 2); + String nextWidgetClassName = nextSplit[0]; + + // Find the n:th child and count the number of children with + // the same type before it + int nextIndex = 0; + for (Widget child : layout) { + // Don't count captions + if (child instanceof VCaption) { + continue; + } + + boolean matchingType = nextWidgetClassName.equals(Util + .getSimpleName(child)); + if (widgetPosition == 0) { + // This is the n:th child + + // Error if not the expected type + if (!matchingType) { + return null; + } + break; + } else if (matchingType) { + // If this was another child of the expected type, + // increase the count for the next step + nextIndex++; + } + widgetPosition--; + } + + // Advance to the next step, this time checking for the + // actual child widget + parts[i + 1] = nextWidgetClassName + '[' + nextIndex + ']'; + continue; + } + // Locate the child Iterator iterator; -- 2.39.5