diff options
author | Henri Sara <henri.sara@itmill.com> | 2011-06-13 11:15:49 +0000 |
---|---|---|
committer | Henri Sara <henri.sara@itmill.com> | 2011-06-13 11:15:49 +0000 |
commit | 8727670c7a90267ad4d2bceb69d18aee5c6f4615 (patch) | |
tree | 5cd033998eb9f6892b050d973ee3999a0a35d416 | |
parent | 354be78fb0cbd147085ef11f88fe3c1c3cdb99b7 (diff) | |
download | vaadin-framework-8727670c7a90267ad4d2bceb69d18aee5c6f4615.tar.gz vaadin-framework-8727670c7a90267ad4d2bceb69d18aee5c6f4615.zip |
#4125 MenuBar supports selectable items
svn changeset:19348/svn branch:6.6
-rw-r--r-- | WebContent/VAADIN/themes/base/menubar/img/check.gif | bin | 0 -> 57 bytes | |||
-rw-r--r-- | WebContent/VAADIN/themes/base/menubar/menubar.css | 13 | ||||
-rw-r--r-- | WebContent/VAADIN/themes/reindeer/menubar/img/checked-selected.png | bin | 0 -> 508 bytes | |||
-rw-r--r-- | WebContent/VAADIN/themes/reindeer/menubar/img/checked.png | bin | 0 -> 393 bytes | |||
-rw-r--r-- | WebContent/VAADIN/themes/reindeer/menubar/img/unchecked-selected.png | bin | 0 -> 320 bytes | |||
-rw-r--r-- | WebContent/VAADIN/themes/reindeer/menubar/img/unchecked.png | bin | 0 -> 261 bytes | |||
-rw-r--r-- | WebContent/VAADIN/themes/reindeer/menubar/menubar.css | 22 | ||||
-rw-r--r-- | WebContent/VAADIN/themes/sampler/icons/sampleicons/75-MenuBarSelectableItems.gif | bin | 0 -> 3139 bytes | |||
-rw-r--r-- | src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java | 188 | ||||
-rw-r--r-- | src/com/vaadin/ui/MenuBar.java | 126 | ||||
-rw-r--r-- | tests/src/com/vaadin/tests/components/menubar/MenuBarItemsSelectable.html | 141 | ||||
-rw-r--r-- | tests/src/com/vaadin/tests/components/menubar/MenuBarTest.java | 25 |
12 files changed, 469 insertions, 46 deletions
diff --git a/WebContent/VAADIN/themes/base/menubar/img/check.gif b/WebContent/VAADIN/themes/base/menubar/img/check.gif Binary files differnew file mode 100644 index 0000000000..0a89195168 --- /dev/null +++ b/WebContent/VAADIN/themes/base/menubar/img/check.gif diff --git a/WebContent/VAADIN/themes/base/menubar/menubar.css b/WebContent/VAADIN/themes/base/menubar/menubar.css index d1972ac4ec..042ec15d1d 100644 --- a/WebContent/VAADIN/themes/base/menubar/menubar.css +++ b/WebContent/VAADIN/themes/base/menubar/menubar.css @@ -79,4 +79,15 @@ .v-menubar-popup .popupContent:focus, .v-menubar-popup .popupContent .v-menubar-submenu:focus{ outline: none; -}
\ No newline at end of file +} +/* Checkboxes for checkable/checked menu items */ +/* Checked/unchecked requires combined style selected-(un)checked for IE6 */ +.v-menubar-submenu-check-column .v-menubar-menuitem { + padding-left: 6px; +} +.v-menubar-submenu-check-column .v-menubar-menuitem-caption { + padding-left: 18px; +} +.v-menubar-submenu .v-menubar-menuitem-checked .v-menubar-menuitem-caption { + background: transparent url(img/check.gif) no-repeat left; +} diff --git a/WebContent/VAADIN/themes/reindeer/menubar/img/checked-selected.png b/WebContent/VAADIN/themes/reindeer/menubar/img/checked-selected.png Binary files differnew file mode 100644 index 0000000000..192c404617 --- /dev/null +++ b/WebContent/VAADIN/themes/reindeer/menubar/img/checked-selected.png diff --git a/WebContent/VAADIN/themes/reindeer/menubar/img/checked.png b/WebContent/VAADIN/themes/reindeer/menubar/img/checked.png Binary files differnew file mode 100644 index 0000000000..418e951166 --- /dev/null +++ b/WebContent/VAADIN/themes/reindeer/menubar/img/checked.png diff --git a/WebContent/VAADIN/themes/reindeer/menubar/img/unchecked-selected.png b/WebContent/VAADIN/themes/reindeer/menubar/img/unchecked-selected.png Binary files differnew file mode 100644 index 0000000000..bac6587c20 --- /dev/null +++ b/WebContent/VAADIN/themes/reindeer/menubar/img/unchecked-selected.png diff --git a/WebContent/VAADIN/themes/reindeer/menubar/img/unchecked.png b/WebContent/VAADIN/themes/reindeer/menubar/img/unchecked.png Binary files differnew file mode 100644 index 0000000000..92a2b582c5 --- /dev/null +++ b/WebContent/VAADIN/themes/reindeer/menubar/img/unchecked.png diff --git a/WebContent/VAADIN/themes/reindeer/menubar/menubar.css b/WebContent/VAADIN/themes/reindeer/menubar/menubar.css index f3e620353a..e5e337725e 100644 --- a/WebContent/VAADIN/themes/reindeer/menubar/menubar.css +++ b/WebContent/VAADIN/themes/reindeer/menubar/menubar.css @@ -49,4 +49,24 @@ } .v-menubar-submenu .v-menubar-menuitem-selected .v-menubar-submenu-indicator { background-image: url(img/submenu-icon-hover.png); -}
\ No newline at end of file +} + +/* Checkboxes for checkable/checked menu items */ +.v-menubar-submenu-check-column .v-menubar-menuitem { + padding-left: 6px; +} +.v-menubar-submenu-check-column .v-menubar-menuitem-caption { + padding-left: 18px; +} +.v-menubar-submenu .v-menubar-menuitem-checked .v-menubar-menuitem-caption { + background: transparent url(img/checked.png) no-repeat left; +} +.v-menubar-submenu .v-menubar-menuitem-unchecked .v-menubar-menuitem-caption { + background: transparent url(img/unchecked.png) no-repeat left; +} +.v-menubar-submenu .v-menubar-menuitem-selected-checked .v-menubar-menuitem-caption { + background: transparent url(img/checked-selected.png) no-repeat left; +} +.v-menubar-submenu .v-menubar-menuitem-selected-unchecked .v-menubar-menuitem-caption { + background: transparent url(img/unchecked-selected.png) no-repeat left; +} diff --git a/WebContent/VAADIN/themes/sampler/icons/sampleicons/75-MenuBarSelectableItems.gif b/WebContent/VAADIN/themes/sampler/icons/sampleicons/75-MenuBarSelectableItems.gif Binary files differnew file mode 100644 index 0000000000..f59714cc62 --- /dev/null +++ b/WebContent/VAADIN/themes/sampler/icons/sampleicons/75-MenuBarSelectableItems.gif diff --git a/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java b/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java index 44870ef350..cab37e7c70 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VMenuBar.java @@ -8,6 +8,7 @@ import java.util.Iterator; import java.util.List; import java.util.Stack; +import com.google.gwt.core.client.GWT; import com.google.gwt.core.client.Scheduler; import com.google.gwt.core.client.Scheduler.ScheduledCommand; import com.google.gwt.dom.client.NodeList; @@ -66,6 +67,8 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, public static final String OPEN_ROOT_MENU_ON_HOWER = "ormoh"; + public static final String ATTRIBUTE_CHECKED = "checked"; + /** Widget fields **/ protected boolean subMenu; protected ArrayList<CustomMenuItem> items; @@ -228,7 +231,10 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, } itemHTML.append(moreItemText); - moreItem = new CustomMenuItem(itemHTML.toString(), emptyCommand); + moreItem = GWT.create(CustomMenuItem.class); + moreItem.setHTML(itemHTML.toString()); + moreItem.setCommand(emptyCommand); + collapsedRootItems = new VMenuBar(true, (VMenuBar) client.getPaintable(uidlId)); moreItem.setSubMenu(collapsedRootItems); @@ -245,43 +251,16 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, UIDL item = (UIDL) itr.next(); CustomMenuItem currentItem = null; - String itemText = item.getStringAttribute("text"); final int itemId = item.getIntAttribute("id"); boolean itemHasCommand = item.hasAttribute("command"); + boolean itemIsCheckable = item.hasAttribute(ATTRIBUTE_CHECKED); - // Construct html from the text and the optional icon - StringBuffer itemHTML = new StringBuffer(); - Command cmd = null; - - if (item.hasAttribute("separator")) { - itemHTML.append("<span>---</span>"); - } else { - // Add submenu indicator - if (item.getChildCount() > 0) { - // FIXME For compatibility reasons: remove in version 7 - String bgStyle = ""; - if (submenuIcon != null) { - bgStyle = " style=\"background-image: url(" - + submenuIcon - + "); text-indent: -999px; width: 1em;\""; - } - itemHTML.append("<span class=\"" + CLASSNAME - + "-submenu-indicator\"" + bgStyle - + ">►</span>"); - } - - itemHTML.append("<span class=\"" + CLASSNAME - + "-menuitem-caption\">"); - if (item.hasAttribute("icon")) { - itemHTML.append("<img src=\"" - + client.translateVaadinUri(item - .getStringAttribute("icon")) - + "\" class=\"" + Icon.CLASSNAME + "\" alt=\"\" />"); - } - itemHTML.append(Util.escapeHTML(itemText) + "</span>"); + String itemHTML = buildItemHTML(item); - if (itemHasCommand) { + Command cmd = null; + if (!item.hasAttribute("separator")) { + if (itemHasCommand || itemIsCheckable) { // Construct a command that fires onMenuClick(int) with the // item's id-number cmd = new Command() { @@ -309,6 +288,19 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, currentItem.setSubMenu(currentMenu); } + if (!itr.hasNext()) { + boolean hasCheckableItem = false; + for (CustomMenuItem menuItem : currentMenu.getItems()) { + hasCheckableItem = hasCheckableItem + || menuItem.isCheckable(); + } + if (hasCheckableItem) { + currentMenu.addStyleDependentName("check-column"); + } else { + currentMenu.removeStyleDependentName("check-column"); + } + } + while (!itr.hasNext() && !iteratorStack.empty()) { itr = iteratorStack.pop(); currentMenu = menuStack.pop(); @@ -320,6 +312,45 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, }// updateFromUIDL /** + * Build the HTML content for a menu item. + * + * @param item + * @return + */ + protected String buildItemHTML(UIDL item) { + // Construct html from the text and the optional icon + StringBuffer itemHTML = new StringBuffer(); + if (item.hasAttribute("separator")) { + itemHTML.append("<span>---</span>"); + } else { + // Add submenu indicator + if (item.getChildCount() > 0) { + // FIXME For compatibility reasons: remove in version 7 + String bgStyle = ""; + if (submenuIcon != null) { + bgStyle = " style=\"background-image: url(" + submenuIcon + + "); text-indent: -999px; width: 1em;\""; + } + itemHTML.append("<span class=\"" + CLASSNAME + + "-submenu-indicator\"" + bgStyle + ">►</span>"); + } + + itemHTML.append("<span class=\"" + CLASSNAME + + "-menuitem-caption\">"); + if (item.hasAttribute("icon")) { + itemHTML.append("<img src=\"" + + client.translateVaadinUri(item + .getStringAttribute("icon")) + "\" class=\"" + + Icon.CLASSNAME + "\" alt=\"\" />"); + } + String itemText = item.getStringAttribute("text"); + itemHTML.append(Util.escapeHTML(itemText)); + itemHTML.append("</span>"); + } + return itemHTML.toString(); + } + + /** * This is called by the items in the menu and it communicates the * information to the server * @@ -377,7 +408,10 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, * @return the item created */ public CustomMenuItem addItem(String html, Command cmd) { - CustomMenuItem item = new CustomMenuItem(html, cmd); + CustomMenuItem item = GWT.create(CustomMenuItem.class); + item.setHTML(html); + item.setCommand(cmd); + addItem(item); return item; } @@ -832,7 +866,28 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, protected VMenuBar parentMenu = null; protected boolean enabled = true; protected boolean isSeparator = false; + protected boolean checkable = false; + protected boolean checked = false; + + /** + * Default menu item {@link Widget} constructor for GWT.create(). + * + * Use {@link #setHTML(String)} and {@link #setCommand(Command)} after + * constructing a menu item. + */ + public CustomMenuItem() { + this("", null); + } + /** + * Creates a menu item {@link Widget}. + * + * @param html + * @param cmd + * @deprecated use the default constructor and {@link #setHTML(String)} + * and {@link #setCommand(Command)} instead + */ + @Deprecated public CustomMenuItem(String html, Command cmd) { // We need spans to allow inline-block in IE setElement(DOM.createSpan()); @@ -843,20 +898,64 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, setStyleName(CLASSNAME + "-menuitem"); sinkEvents(VTooltip.TOOLTIP_EVENTS); - - // Sink the onload event for any icons. The onload - // events are handled by the parent VMenuBar. - Util.sinkOnloadForImages(getElement()); } public void setSelected(boolean selected) { if (selected && !isSeparator) { addStyleDependentName("selected"); + // needed for IE6 to have a single style name to match for an + // element + if (checkable) { + if (checked) { + removeStyleDependentName("selected-unchecked"); + addStyleDependentName("selected-checked"); + } else { + removeStyleDependentName("selected-checked"); + addStyleDependentName("selected-unchecked"); + } + } } else { removeStyleDependentName("selected"); + // needed for IE6 to have a single style name to match for an + // element + removeStyleDependentName("selected-checked"); + removeStyleDependentName("selected-unchecked"); } } + public void setChecked(boolean checked) { + if (checkable && !isSeparator) { + this.checked = checked; + + if (checked) { + addStyleDependentName("checked"); + removeStyleDependentName("unchecked"); + } else { + addStyleDependentName("unchecked"); + removeStyleDependentName("checked"); + } + } else { + this.checked = false; + } + } + + public boolean isChecked() { + return checked; + } + + public void setCheckable(boolean checkable) { + if (checkable && !isSeparator) { + this.checkable = true; + } else { + setChecked(false); + this.checkable = false; + } + } + + public boolean isCheckable() { + return checkable; + } + /* * setters and getters for the fields */ @@ -892,6 +991,10 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, public void setHTML(String html) { this.html = html; DOM.setInnerHTML(getElement(), html); + + // Sink the onload event for any icons. The onload + // events are handled by the parent VMenuBar. + Util.sinkOnloadForImages(getElement()); } public String getText() { @@ -934,6 +1037,15 @@ public class VMenuBar extends SimpleFocusablePanel implements Paintable, setSeparator(uidl.hasAttribute("separator")); setEnabled(!uidl.hasAttribute("disabled")); + if (!isSeparator() && uidl.hasAttribute(ATTRIBUTE_CHECKED)) { + // if the selected attribute is present (either true or false), + // the item is selectable + setCheckable(true); + setChecked(uidl.getBooleanAttribute(ATTRIBUTE_CHECKED)); + } else { + setCheckable(false); + } + if (uidl.hasAttribute("style")) { String itemStyle = uidl.getStringAttribute("style"); addStyleDependentName(itemStyle); diff --git a/src/com/vaadin/ui/MenuBar.java b/src/com/vaadin/ui/MenuBar.java index d79e070fca..493870bf82 100644 --- a/src/com/vaadin/ui/MenuBar.java +++ b/src/com/vaadin/ui/MenuBar.java @@ -123,7 +123,12 @@ public class MenuBar extends AbstractComponent { if (description != null && description.length() > 0) { target.addAttribute("description", description); } - + if (item.isSelectable()) { + // if the "checked" attribute is present (either true or false), + // the item is selectable + target.addAttribute(VMenuBar.ATTRIBUTE_CHECKED, + item.isSelected()); + } if (item.hasChildren()) { for (MenuItem child : item.getChildren()) { paintItem(target, child); @@ -167,7 +172,12 @@ public class MenuBar extends AbstractComponent { // If we got the clicked item, launch the command. if (found && tmpItem.isEnabled()) { - tmpItem.getCommand().menuSelected(tmpItem); + if (tmpItem.isSelectable()) { + tmpItem.setSelected(!tmpItem.isSelected()); + } + if (null != tmpItem.getCommand()) { + tmpItem.getCommand().menuSelected(tmpItem); + } } }// if }// changeVariables @@ -431,6 +441,8 @@ public class MenuBar extends AbstractComponent { private boolean isSeparator = false; private String styleName; private String description; + private boolean selectable = false; + private boolean selected = false; /** * Constructs a new menu item that can optionally have an icon and a @@ -505,13 +517,19 @@ public class MenuBar extends AbstractComponent { * the icon for the menu item * @param command * the command for the menu item + * @throws IllegalStateException + * If the item is selectable and thus cannot have children. */ public MenuBar.MenuItem addItem(String caption, Resource icon, - MenuBar.Command command) { + MenuBar.Command command) throws IllegalStateException { if (isSeparator()) { throw new UnsupportedOperationException( "Cannot add items to a separator"); } + if (isSelectable()) { + throw new IllegalStateException( + "A selectable item cannot have children"); + } if (caption == null) { throw new IllegalArgumentException("Caption cannot be null"); } @@ -544,11 +562,16 @@ public class MenuBar extends AbstractComponent { * the command for the menu item * @param itemToAddBefore * the item that will be after the new item - * + * @throws IllegalStateException + * If the item is selectable and thus cannot have children. */ public MenuBar.MenuItem addItemBefore(String caption, Resource icon, - MenuBar.Command command, MenuBar.MenuItem itemToAddBefore) { - + MenuBar.Command command, MenuBar.MenuItem itemToAddBefore) + throws IllegalStateException { + if (isSelectable()) { + throw new IllegalStateException( + "A selectable item cannot have children"); + } MenuItem newItem = null; if (hasChildren() && itsChildren.contains(itemToAddBefore)) { @@ -814,6 +837,97 @@ public class MenuBar extends AbstractComponent { return description; } + /** + * Gets the selectable state of the item. If an item is selectable its + * selected state (as returned by {@link #isSelected()}) is indicated in + * the UI. + * + * <p> + * An item is not selectable by default. + * </p> + * + * @return true if the item is selectable, false otherwise + * @since 6.6.2 + */ + public boolean isSelectable() { + return selectable; + } + + /** + * Sets the selectable state of the item. If an item is selectable its + * selected state (as returned by {@link #isSelected()}) is indicated in + * the UI. + * + * <p> + * An item is not selectable by default. + * </p> + * + * <p> + * Items with sub items cannot be selectable. + * </p> + * + * @param selectable + * true if the item should be selectable, false otherwise + * @throws IllegalStateException + * If the item has children + * @since 6.6.2 + */ + public void setSelectable(boolean selectable) + throws IllegalStateException { + if (hasChildren()) { + throw new IllegalStateException( + "A menu item with children cannot be selectable"); + } + this.selectable = selectable; + requestRepaint(); + } + + /** + * Gets the selected state of the item. Only used if the item is + * selectable (as indicated by {@link #isSelectable()}). The selected + * state is indicated in the UI with the item, if the item is + * selectable. + * + * <p> + * An item is not selected by default. + * </p> + * + * <p> + * Note that the CSS style corresponding to selection is "-checked". The + * style "-selected" refers to the focused menu item (mouse hover or + * keyboard selection). + * </p> + * + * @return true if the item is selected, false otherwise + * @since 6.6.2 + */ + public boolean isSelected() { + return selected; + } + + /** + * Sets the selected state of the item. Only used if the item is + * selectable (indicated by {@link #isSelectable()}). The selected state + * is indicated in the UI with the item, if the item is selectable. + * + * <p> + * An item is not selected by default. + * </p> + * + * <p> + * Note that the CSS style corresponding to selection is "-checked". The + * style "-selected" refers to the focused menu item (mouse hover or + * keyboard selection). + * </p> + * + * @return true if the item is selected, false otherwise + * @since 6.6.2 + */ + public void setSelected(boolean selected) { + this.selected = selected; + requestRepaint(); + } + }// class MenuItem }// class MenuBar diff --git a/tests/src/com/vaadin/tests/components/menubar/MenuBarItemsSelectable.html b/tests/src/com/vaadin/tests/components/menubar/MenuBarItemsSelectable.html new file mode 100644 index 0000000000..d1e8865499 --- /dev/null +++ b/tests/src/com/vaadin/tests/components/menubar/MenuBarItemsSelectable.html @@ -0,0 +1,141 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> +<head profile="http://selenium-ide.openqa.org/profiles/test-case"> +<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> +<link rel="selenium.base" href="" /> +<title>MenuBarItemsSelectable</title> +</head> +<body> +<table cellpadding="1" cellspacing="1" border="1"> +<thead> +<tr><td rowspan="1" colspan="3">MenuBarItemsSelectable</td></tr> +</thead><tbody> +<tr> + <td>open</td> + <td>/run/com.vaadin.tests.components.menubar.MenuBarTest?restartApplication</td> + <td></td> +</tr> +<!--Hide event log to be able to compare screenshots--> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::PID_Smenu#item1</td> + <td>30,7</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::Root/VOverlay[0]/VMenuBar[0]#item0</td> + <td>27,3</td> +</tr> +<!--Make some items selectable--> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::PID_Smenu#item0</td> + <td>43,12</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::Root/VOverlay[0]/VMenuBar[0]#item5</td> + <td>47,9</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::Root/VOverlay[1]/VMenuBar[0]#item4</td> + <td>48,5</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::Root/VOverlay[2]/VMenuBar[0]#item2</td> + <td>90,11</td> +</tr> +<!--Show icons on some items--> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::PID_Smenu#item0</td> + <td>13,1</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::Root/VOverlay[0]/VMenuBar[0]#item5</td> + <td>47,3</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::Root/VOverlay[1]/VMenuBar[0]#item0</td> + <td>26,4</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::Root/VOverlay[2]/VMenuBar[0]#item3</td> + <td>39,7</td> +</tr> +<!--Set width to 100%--> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::PID_Smenu#item0</td> + <td>23,9</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::Root/VOverlay[0]/VMenuBar[0]#item2</td> + <td>36,6</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::Root/VOverlay[1]/VMenuBar[0]#item0</td> + <td>27,7</td> +</tr> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::Root/VOverlay[2]/VMenuBar[0]#item2</td> + <td>23,3</td> +</tr> +<!--Open sub menu 1--> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::PID_StestComponent#item0</td> + <td>51,10</td> +</tr> +<!--Open sub menu 1-1--> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::Root/VOverlay[0]/VMenuBar[0]#item0</td> + <td>51,10</td> +</tr> +<tr> + <td>pause</td> + <td>3000</td> + <td></td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>submenu-1-1-selectable-items</td> +</tr> +<!--Select item--> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::Root/VOverlay[1]/VMenuBar[0]#item0</td> + <td>51,10</td> +</tr> +<!--Open sub menu 1--> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::PID_StestComponent#item0</td> + <td>51,10</td> +</tr> +<!--Open sub menu 1-1--> +<tr> + <td>mouseClick</td> + <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarTest::Root/VOverlay[0]/VMenuBar[0]#item0</td> + <td>51,10</td> +</tr> +<tr> + <td>screenCapture</td> + <td></td> + <td>submenu-1-1-selected-items</td> +</tr> + +</tbody></table> +</body> +</html> diff --git a/tests/src/com/vaadin/tests/components/menubar/MenuBarTest.java b/tests/src/com/vaadin/tests/components/menubar/MenuBarTest.java index 31121a8d37..6bc1e7d272 100644 --- a/tests/src/com/vaadin/tests/components/menubar/MenuBarTest.java +++ b/tests/src/com/vaadin/tests/components/menubar/MenuBarTest.java @@ -24,6 +24,7 @@ public class MenuBarTest extends AbstractComponentTest<MenuBar> { private Integer iconSize;
private Integer disabledDensity;
private Integer invisibleDensity;
+ private Integer selectableDensity;
@Override
protected Class<MenuBar> getTestClass() {
@@ -46,6 +47,7 @@ public class MenuBarTest extends AbstractComponentTest<MenuBar> { createMenuIconsSizeSelect(CATEGORY_MENU_ITEM_STATES);
createMenuItemDisabledDensitySelect(CATEGORY_MENU_ITEM_STATES);
createMenuItemInvisibleDensitySelect(CATEGORY_MENU_ITEM_STATES);
+ createMenuItemSelectableDensitySelect(CATEGORY_MENU_ITEM_STATES);
}
@@ -125,6 +127,17 @@ public class MenuBarTest extends AbstractComponentTest<MenuBar> { setMenuItemInvisibleDensity);
}
+ private void createMenuItemSelectableDensitySelect(String category) {
+ LinkedHashMap<String, Integer> options = new LinkedHashMap<String, Integer>();
+ options.put("No items selectable", null);
+ options.put("All selectable", 1);
+ options.put("Every second", 2);
+ options.put("Every third", 3);
+
+ createSelectAction("Selectable", category, options,
+ "No items selectable", setMenuItemSelectableDensity);
+ }
+
/* COMMANDS */
Command<MenuBar, Integer> createRootMenuItems = new Command<MenuBar, Integer>() {
@@ -181,6 +194,14 @@ public class MenuBarTest extends AbstractComponentTest<MenuBar> { }
};
+ private Command<MenuBar, Integer> setMenuItemSelectableDensity = new Command<MenuBar, Integer>() {
+
+ public void execute(MenuBar c, Integer value, Object data) {
+ selectableDensity = value;
+ createRootItems(c);
+ }
+ };
+
private Command<MenuBar, Integer> setSubMenuSeparatorDensity = new Command<MenuBar, Integer>() {
public void execute(MenuBar c, Integer value, Object data) {
@@ -245,6 +266,10 @@ public class MenuBarTest extends AbstractComponentTest<MenuBar> { if (invisibleDensity != null && i % invisibleDensity == 0) {
subMenuItem.setVisible(false);
}
+ if (level == subLevels && selectableDensity != null
+ && i % selectableDensity == 0) {
+ subMenuItem.setSelectable(true);
+ }
if (i % subMenuDensity == 0 && level < subLevels) {
subMenuItem.setCommand(null);
|