]> source.dussan.org Git - vaadin-framework.git/commitdiff
Allow referencing ComboBox menu items as VFilterSelect$SuggestionMenu[0]#itemX
authorArtur Signell <artur.signell@itmill.com>
Thu, 24 Jun 2010 11:38:41 +0000 (11:38 +0000)
committerArtur Signell <artur.signell@itmill.com>
Thu, 24 Jun 2010 11:38:41 +0000 (11:38 +0000)
svn changeset:13908/svn branch:6.4

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

index eb8dc857053cfd1c7d60730bc583db1d486bcb9e..bcda91266c075ef696fa2cc648316b9fa7d2f695 100644 (file)
@@ -491,7 +491,7 @@ public class VFilterSelect extends Composite implements Paintable, Field,
     /**
      * The menu where the suggestions are rendered
      */
-    public class SuggestionMenu extends MenuBar {
+    public class SuggestionMenu extends MenuBar implements SubPartAware {
 
         /**
          * Default constructor
@@ -659,6 +659,39 @@ public class VFilterSelect extends Composite implements Paintable, Field,
             }
             super.onBrowserEvent(event);
         }
+
+        private static final String SUBPART_PREFIX = "item";
+
+        public Element getSubPartElement(String subPart) {
+            int index = Integer.parseInt(subPart.substring(SUBPART_PREFIX
+                    .length()));
+
+            MenuItem item = (MenuItem) getItems().get(index);
+
+            return item.getElement();
+        }
+
+        public String getSubPartName(Element subElement) {
+            if (!getElement().isOrHasChild(subElement)) {
+                return null;
+            }
+
+            Element menuItemRoot = subElement;
+            while (menuItemRoot != null
+                    && !menuItemRoot.getTagName().equalsIgnoreCase("td")) {
+                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 (((MenuItem) getItems().get(i)).getElement() == menuItemRoot) {
+                    String name = SUBPART_PREFIX + i;
+                    return name;
+                }
+            }
+            return null;
+        }
     }
 
     public static final int FILTERINGMODE_OFF = 0;