summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDmitrii Rogozin <dmitrii@vaadin.com>2014-09-11 14:57:02 +0300
committerMarkus Koivisto <markus@vaadin.com>2014-11-03 09:45:26 +0200
commit31c16901d8fa31f079110956393642c150e5abaf (patch)
tree18d0b0bd4ffcea3f7456951f4550238d95210720
parentb483d2a6e4b3267655920c0baf1e90f8de63d519 (diff)
downloadvaadin-framework-31c16901d8fa31f079110956393642c150e5abaf.tar.gz
vaadin-framework-31c16901d8fa31f079110956393642c150e5abaf.zip
Add SubPartAware to VMenuBar (#13364)
Change-Id: Ibf8b82dff19736d5e2519638db50a26148f0e750
-rw-r--r--client/src/com/vaadin/client/ui/VMenuBar.java49
1 files changed, 45 insertions, 4 deletions
diff --git a/client/src/com/vaadin/client/ui/VMenuBar.java b/client/src/com/vaadin/client/ui/VMenuBar.java
index 909b25f7fb..4a090899f9 100644
--- a/client/src/com/vaadin/client/ui/VMenuBar.java
+++ b/client/src/com/vaadin/client/ui/VMenuBar.java
@@ -16,7 +16,9 @@
package com.vaadin.client.ui;
import java.util.ArrayList;
+import java.util.LinkedList;
import java.util.List;
+import java.util.Queue;
import com.google.gwt.core.client.GWT;
import com.google.gwt.core.client.Scheduler;
@@ -1531,11 +1533,50 @@ public class VMenuBar extends SimpleFocusablePanel implements
@Override
public com.google.gwt.user.client.Element getSubPartElement(String subPart) {
- int index = Integer
- .parseInt(subPart.substring(SUBPART_PREFIX.length()));
- CustomMenuItem item = getItems().get(index);
+ if (subPart.startsWith(SUBPART_PREFIX)) {
+ int index = Integer.parseInt(subPart.substring(SUBPART_PREFIX
+ .length()));
+ CustomMenuItem item = getItems().get(index);
- return item.getElement();
+ return item.getElement();
+ } else {
+ Queue<CustomMenuItem> submenuItems = new LinkedList<CustomMenuItem>();
+ for (CustomMenuItem item : getItems()) {
+ if (isItemNamed(item, subPart)) {
+ return item.getElement();
+ }
+ if (item.getSubMenu() != null) {
+ submenuItems.addAll(item.getSubMenu().getItems());
+ }
+ }
+ while (!submenuItems.isEmpty()) {
+ CustomMenuItem item = submenuItems.poll();
+ if (!item.isSeparator() && isItemNamed(item, subPart)) {
+ return item.getElement();
+ }
+ if (item.getSubMenu() != null && item.getSubMenu().menuVisible) {
+ submenuItems.addAll(item.getSubMenu().getItems());
+ }
+
+ }
+ return null;
+ }
+ }
+
+ private boolean isItemNamed(CustomMenuItem item, String name) {
+ Element lastChildElement = getLastChildElement(item);
+ if (lastChildElement.getInnerText().equals(name)) {
+ return true;
+ }
+ return false;
+ }
+
+ private Element getLastChildElement(CustomMenuItem item) {
+ Element lastChildElement = item.getElement().getFirstChildElement();
+ while (lastChildElement.getNextSiblingElement() != null) {
+ lastChildElement = lastChildElement.getNextSiblingElement();
+ }
+ return lastChildElement;
}
@Override