]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add SubPart support to VaadinFinderLocatorStrategy (#13980)
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Thu, 28 Aug 2014 11:54:21 +0000 (14:54 +0300)
committerVaadin Code Review <review@vaadin.com>
Tue, 2 Sep 2014 10:55:20 +0000 (10:55 +0000)
This also fixes recorder issues with negative indices

Change-Id: I1d3fceaf11aed743a957fe72e7ab60c13d7fc5e1

client/src/com/vaadin/client/componentlocator/ComponentLocator.java
client/src/com/vaadin/client/componentlocator/VaadinFinderLocatorStrategy.java
client/src/com/vaadin/client/debug/internal/SelectorPath.java

index 8d257f09b4bf0a61dd6776f1d178e09e6e4ca24c..52c7b57d1d1c92ec831737148041e9388299cf5b 100644 (file)
@@ -108,7 +108,10 @@ public class ComponentLocator {
      *         String locator could not be created.
      */
     public String getPathForElement(Element targetElement) {
-        return getPathForElement(DOM.asOld(targetElement));
+        if (targetElement != null) {
+            return getPathForElement(DOM.asOld(targetElement));
+        }
+        return null;
     }
 
     /**
index 6075d1bf48b7a2fa5a95cac12b905be4a27afa43..9ed071c38fd8943016dfd6800bb9a469bc3e4722 100644 (file)
@@ -20,6 +20,7 @@ import java.util.Arrays;
 import java.util.List;
 
 import com.google.gwt.dom.client.Element;
+import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.ui.RootPanel;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.client.ApplicationConnection;
@@ -72,8 +73,24 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy {
      */
     @Override
     public String getPathForElement(Element targetElement) {
-        if (targetElement == null) {
-            return "";
+        Element oldTarget = targetElement;
+        Widget targetWidget = Util.findPaintable(client, targetElement)
+                .getWidget();
+        targetElement = targetWidget.getElement();
+
+        // Find SubPart name if needed.
+        String subPart = null;
+        boolean hasSubParts = targetWidget instanceof SubPartAware;
+        if (oldTarget != targetElement) {
+            if (hasSubParts) {
+                subPart = ((SubPartAware) targetWidget).getSubPartName(DOM
+                        .asOld(oldTarget));
+            }
+
+            if (!hasSubParts || subPart == null) {
+                // Couldn't find SubPart name for element.
+                return null;
+            }
         }
 
         List<ConnectorPath> hierarchy = getConnectorHierarchyForElement(targetElement);
@@ -102,7 +119,7 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy {
             return null;
         }
 
-        return getBestSelector(generateQueries(path), targetElement);
+        return getBestSelector(generateQueries(path), targetElement, subPart);
     }
 
     /**
@@ -114,9 +131,12 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy {
      *            List of selectors
      * @param target
      *            Target element
+     * @param subPart
+     *            sub part selector string for actual target
      * @return Best selector string formatted with a post filter
      */
-    private String getBestSelector(List<String> selectors, Element target) {
+    private String getBestSelector(List<String> selectors, Element target,
+            String subPart) {
         // The last selector gives us smallest list index for target element.
         String bestSelector = selectors.get(selectors.size() - 1);
         int min = getElementsByPath(bestSelector).indexOf(target);
@@ -141,7 +161,8 @@ public class VaadinFinderLocatorStrategy implements LocatorStrategy {
 
             }
         }
-        return "(" + bestSelector + ")[" + min + "]";
+        return "(" + bestSelector + (subPart != null ? "#" + subPart : "")
+                + ")[" + min + "]";
 
     }
 
index 5627bf0250a4688e25098e4dea3f22afdc11d6ae..3f21e46a969b82c6208ff135217be83d231cc438 100644 (file)
@@ -82,6 +82,10 @@ public class SelectorPath {
                 .extractPostFilterPredicates(path);
         if (postFilters.size() > 0) {
             tmpPath = tmpPath.substring(1, tmpPath.lastIndexOf(')'));
+            if (tmpPath.contains("#")) {
+                // FIXME: SubParts should be handled.
+                tmpPath = tmpPath.split("#")[0];
+            }
         }
 
         // Generate an ElementQuery