diff options
author | Artur Signell <artur.signell@itmill.com> | 2010-04-22 11:11:18 +0000 |
---|---|---|
committer | Artur Signell <artur.signell@itmill.com> | 2010-04-22 11:11:18 +0000 |
commit | d8d4cbafb4d33994e9baedebceb8cbb7bebab791 (patch) | |
tree | 6eb50d9a9dcbfc8cff08c55c645ead7a4fbbc139 /src | |
parent | fa29940ad16e912f3faeef9b096573cd91be3f4c (diff) | |
download | vaadin-framework-d8d4cbafb4d33994e9baedebceb8cbb7bebab791.tar.gz vaadin-framework-d8d4cbafb4d33994e9baedebceb8cbb7bebab791.zip |
Test case and fix for #4528 - PaintException if the last menuItem of a sub menu is invisible
svn changeset:12765/svn branch:6.3
Diffstat (limited to 'src')
-rw-r--r-- | src/com/vaadin/ui/MenuBar.java | 77 |
1 files changed, 35 insertions, 42 deletions
diff --git a/src/com/vaadin/ui/MenuBar.java b/src/com/vaadin/ui/MenuBar.java index 03057c6207..036aa1b718 100644 --- a/src/com/vaadin/ui/MenuBar.java +++ b/src/com/vaadin/ui/MenuBar.java @@ -76,63 +76,56 @@ public class MenuBar extends AbstractComponent { target.endTag("options"); target.startTag("items"); - Iterator<MenuItem> itr = menuItems.iterator(); - // This generates the tree from the contents of the menu - while (itr.hasNext()) { - - MenuItem item = itr.next(); - if (!item.isVisible()) { - continue; - } + for (MenuItem item : menuItems) { + paintItem(target, item); + } - target.startTag("item"); - target.addAttribute("id", item.getId()); + target.endTag("items"); + } - if (item.getStyleName() != null) { - target.addAttribute("style", item.getStyleName()); - } + private void paintItem(PaintTarget target, MenuItem item) + throws PaintException { + if (!item.isVisible()) { + return; + } - if (item.isSeparator()) { - target.addAttribute("separator", true); - target.endTag("item"); - } else { - target.addAttribute("text", item.getText()); + target.startTag("item"); - Command command = item.getCommand(); - if (command != null) { - target.addAttribute("command", true); - } + target.addAttribute("id", item.getId()); - Resource icon = item.getIcon(); - if (icon != null) { - target.addAttribute("icon", icon); - } + if (item.getStyleName() != null) { + target.addAttribute("style", item.getStyleName()); + } - if (!item.isEnabled()) { - target.addAttribute("disabled", true); - } + if (item.isSeparator()) { + target.addAttribute("separator", true); + } else { + target.addAttribute("text", item.getText()); - if (item.hasChildren()) { - iteratorStack.push(itr); // For later use + Command command = item.getCommand(); + if (command != null) { + target.addAttribute("command", true); + } - // Go through the children - itr = item.getChildren().iterator(); - } else { - target.endTag("item"); // Item had no children, end - // description - } + Resource icon = item.getIcon(); + if (icon != null) { + target.addAttribute("icon", icon); + } + if (!item.isEnabled()) { + target.addAttribute("disabled", true); } - // The end submenu. More than one submenu may end at once. - while (!itr.hasNext() && !iteratorStack.empty()) { - itr = iteratorStack.pop(); - target.endTag("item"); + if (item.hasChildren()) { + for (MenuItem child : item.getChildren()) { + paintItem(target, child); + } } + } - target.endTag("items"); + target.endTag("item"); } /** Deserialize changes received from client. */ |