]> source.dussan.org Git - vaadin-framework.git/commitdiff
Added better support for menu identification for TestBench
authorArtur Signell <artur.signell@itmill.com>
Wed, 16 Jun 2010 10:29:11 +0000 (10:29 +0000)
committerArtur Signell <artur.signell@itmill.com>
Wed, 16 Jun 2010 10:29:11 +0000 (10:29 +0000)
svn changeset:13695/svn branch:6.4

src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java

index 0721e8e238bcd9c545b9baf5dceb5ffc3b3b32e4..3f25579291f5bcc3e6d18b88fcceb80a297e0731 100644 (file)
@@ -39,7 +39,7 @@ import com.vaadin.terminal.gwt.client.Util;
 
 public class VMenuBar extends SimpleFocusablePanel implements Paintable,
         CloseHandler<PopupPanel>, ContainerResizedListener, KeyPressHandler,
-        KeyDownHandler, BlurHandler, FocusHandler {
+        KeyDownHandler, BlurHandler, FocusHandler, SubPartAware {
 
     /** Set the CSS class name to allow styling. */
     public static final String CLASSNAME = "v-menubar";
@@ -1288,4 +1288,36 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable,
 
         focusDelayTimer.schedule(100);
     }
+
+    private final String SUBPART_PREFIX = "item";
+
+    public Element getSubPartElement(String subPart) {
+        int index = Integer
+                .parseInt(subPart.substring(SUBPART_PREFIX.length()));
+        CustomMenuItem item = getItems().get(index);
+
+        return item.getElement();
+    }
+
+    public String getSubPartName(Element subElement) {
+        if (!getElement().isOrHasChild(subElement)) {
+            return null;
+        }
+
+        Element menuItemRoot = subElement;
+        while (menuItemRoot != null && menuItemRoot.getParentElement() != null
+                && menuItemRoot.getParentElement() != getElement()) {
+            menuItemRoot = menuItemRoot.getParentElement().cast();
+        }
+        // "menuItemRoot" is now the root of the menu item
+
+        final int itemCount = getItems().size();
+        for (int i = 0; i < itemCount; i++) {
+            if (getItems().get(i).getElement() == menuItemRoot) {
+                String name = SUBPART_PREFIX + i;
+                return name;
+            }
+        }
+        return null;
+    }
 }