]> source.dussan.org Git - vaadin-framework.git/commitdiff
More work on ComponentLocator
authorJohn Ahlroos <john@vaadin.com>
Tue, 4 Sep 2012 11:04:23 +0000 (14:04 +0300)
committerJohn Ahlroos <john@vaadin.com>
Tue, 4 Sep 2012 11:04:23 +0000 (14:04 +0300)
client/src/com/vaadin/client/ComponentLocator.java

index a6ee4cf8b2ff843d806d202435f0fe7dd075cba1..f22dbc422dd3c6fff6711f1406505be1937459b8 100644 (file)
 package com.vaadin.client;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
-import java.util.Map;
 
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Element;
 import com.google.gwt.user.client.ui.HasWidgets;
 import com.google.gwt.user.client.ui.RootPanel;
-import com.google.gwt.user.client.ui.SimplePanel;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.client.ui.SubPartAware;
 import com.vaadin.client.ui.UI.VUI;
@@ -437,13 +434,6 @@ public class ComponentLocator {
         return null;
     }
 
-    private static final Map<String, String> replacementMap = new HashMap<String, String>();
-    static {
-        replacementMap.put("VVerticalLayout", "VBoxLayout");
-        replacementMap.put("VHorizontalLayout", "VBoxLayout");
-        replacementMap.put("ChildComponentContainer", "VBoxLayout$Slot");
-    }
-
     /**
      * Locates the widget based on a String locator.
      * 
@@ -494,10 +484,6 @@ public class ComponentLocator {
                 // VVerticalLayout and 0
                 String[] split = part.split("\\[", 2);
                 String widgetClassName = split[0];
-                if (replacementMap.containsKey(widgetClassName)) {
-                    widgetClassName = replacementMap.get(widgetClassName);
-                }
-
                 String indexString = split[1];
                 int widgetPosition = Integer.parseInt(indexString.substring(0,
                         indexString.length() - 1));
@@ -508,6 +494,16 @@ public class ComponentLocator {
                     continue;
                 }
 
+                if ("VVerticalLayout".equals(widgetClassName)
+                        || "VHorizontalLayout".equals(widgetClassName)) {
+                    widgetClassName = "VBoxLayout";
+                }
+
+                if (w instanceof VBoxLayout
+                        && "ChildComponentContainer".equals(widgetClassName)) {
+                    widgetClassName = "VBoxLayout$Slot";
+                }
+
                 if (w instanceof VTabsheetPanel && widgetPosition != 0) {
                     // TabSheetPanel now only contains 1 connector => the index
                     // is always 0 which indicates the widget in the active tab
@@ -522,9 +518,8 @@ public class ComponentLocator {
                  * (which would originally have found the widget inside the
                  * ChildComponentContainer)
                  */
-                if ((w instanceof VMeasuringOrderedLayout
-                        || w instanceof VBoxLayout || w instanceof VGridLayout)
-                        && "VBoxLayout$Slot".equals(widgetClassName)
+                if ((w instanceof VMeasuringOrderedLayout || w instanceof VGridLayout)
+                        && "ChildComponentContainer".equals(widgetClassName)
                         && i + 1 < parts.length) {
 
                     HasWidgets layout = (HasWidgets) w;
@@ -532,24 +527,13 @@ public class ComponentLocator {
                     String nextPart = parts[i + 1];
                     String[] nextSplit = nextPart.split("\\[", 2);
                     String nextWidgetClassName = nextSplit[0];
-                    if (replacementMap.containsKey(nextWidgetClassName)) {
-                        nextWidgetClassName = replacementMap
-                                .get(nextWidgetClassName);
-                    }
 
                     // Find the n:th child and count the number of children with
                     // the same type before it
                     int nextIndex = 0;
                     for (Widget child : layout) {
-                        String childName = Util.getSimpleName(child);
-
-                        if (childName.equals("VBoxLayout$Slot")) {
-                            child = ((SimplePanel) child).getWidget();
-                            childName = Util.getSimpleName(child);
-                        }
-
-                        boolean matchingType = nextWidgetClassName
-                                .equals(childName);
+                        boolean matchingType = nextWidgetClassName.equals(Util
+                                .getSimpleName(child));
                         if (matchingType && widgetPosition == 0) {
                             // This is the n:th child that we looked for
                             break;
@@ -557,7 +541,6 @@ public class ComponentLocator {
                             // Error if we're past the desired position without
                             // a match
                             return null;
-                        } else if (matchingType) {
                         } else if (matchingType) {
                             // If this was another child of the expected type,
                             // increase the count for the next step
@@ -604,14 +587,8 @@ public class ComponentLocator {
                 while (iterator.hasNext()) {
 
                     Widget child = iterator.next();
-
                     String simpleName2 = Util.getSimpleName(child);
 
-                    if (simpleName2.equals("VBoxLayout$Slot")) {
-                        child = ((SimplePanel) child).getWidget();
-                        simpleName2 = Util.getSimpleName(child);
-                    }
-
                     if (widgetClassName.equals(simpleName2)) {
                         if (widgetPosition == 0) {
                             w = child;