}
root.setSelected(selected);
- root.showChildMenu(selected);
- VMenuBar submenu = selected.getSubMenu();
-
- // Select the first item in the newly open submenu
- submenu.setSelected(submenu.getItems().get(0));
-
+ openMenuAndFocusFirstIfPossible(selected);
} else {
getParentMenu().getSelected().getSubMenu().setSelected(null);
getParentMenu().hideChildren();
}
root.setSelected(selected);
- root.showChildMenu(selected);
- VMenuBar submenu = selected.getSubMenu();
-
- // Select the first item in the newly open submenu
- submenu.setSelected(submenu.getItems().get(0));
-
+ openMenuAndFocusFirstIfPossible(selected);
} else if (visibleChildMenu != null) {
// Redirect all navigation to the submenu
visibleChildMenu.handleNavigation(keycode, ctrl, shift);
if (getSelected() == null) {
// If nothing is selected then select the first item
- setSelected(items.get(0));
- if (!getSelected().isSelectable()) {
- handleNavigation(keycode, ctrl, shift);
- }
+ selectFirstItem();
} else if (visibleChildMenu == null && getParentMenu() == null) {
// If this is the root menu the show the child menu with arrow
- // down
- showChildMenu(getSelected());
- menuVisible = true;
- visibleChildMenu.handleNavigation(keycode, ctrl, shift);
+ // down, if there is a child menu
+ openMenuAndFocusFirstIfPossible(getSelected());
} else if (visibleChildMenu != null) {
// Redirect all navigation to the submenu
visibleChildMenu.handleNavigation(keycode, ctrl, shift);
menuVisible = false;
} else if (keycode == getNavigationSelectKey()) {
- if (visibleChildMenu != null) {
+ if (getSelected() == null) {
+ // If nothing is selected then select the first item
+ selectFirstItem();
+ } else if (visibleChildMenu != null) {
// Redirect all navigation to the submenu
visibleChildMenu.handleNavigation(keycode, ctrl, shift);
menuVisible = false;
} else if (visibleChildMenu == null
&& getSelected().getSubMenu() != null) {
- // If the item has a submenu then show it and move the selection
- // there
- showChildMenu(getSelected());
- menuVisible = true;
- visibleChildMenu.handleNavigation(keycode, ctrl, shift);
+ // If the item has a sub menu then show it and move the
+ // selection there
+ openMenuAndFocusFirstIfPossible(getSelected());
} else {
Command command = getSelected().getCommand();
if (command != null) {
return false;
}
+ private void selectFirstItem() {
+ for (int i = 0; i < items.size(); i++) {
+ CustomMenuItem item = items.get(i);
+ if (!item.isSelectable()) {
+ continue;
+ }
+
+ setSelected(item);
+ break;
+ }
+ }
+
+ private void openMenuAndFocusFirstIfPossible(CustomMenuItem menuItem) {
+ VMenuBar subMenu = menuItem.getSubMenu();
+ if (subMenu == null) {
+ // No child menu? Nothing to do
+ return;
+ }
+
+ VMenuBar parentMenu = menuItem.getParentMenu();
+ parentMenu.showChildMenu(menuItem);
+
+ menuVisible = true;
+ // Select the first item in the newly open submenu
+ subMenu.setSelected(subMenu.getItems().get(0));
+
+ }
+
/*
* (non-Javadoc)
*
<td>/run/com.vaadin.tests.components.menubar.MenuBarNavigation?restartApplication</td>
<td></td>
</tr>
-<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
-</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]#menu0</td>
<td>3,10</td>
</tr>
-<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
-</tr>
<tr>
<td>pressSpecialKey</td>
<td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
<td>down</td>
</tr>
-<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
-</tr>
<tr>
<td>pressSpecialKey</td>
<td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
<td>down</td>
</tr>
-<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
-</tr>
<tr>
<td>pressSpecialKey</td>
<td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
<td>down</td>
</tr>
-<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
-</tr>
<tr>
<td>pressSpecialKey</td>
<td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
<td>down</td>
</tr>
-<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
-</tr>
<tr>
<td>pressSpecialKey</td>
<td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
<td>right</td>
</tr>
-<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
-</tr>
<tr>
<td>pressSpecialKey</td>
<td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
<td>enter</td>
</tr>
-<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
-</tr>
<tr>
<td>assertText</td>
<td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
- <td>MenuItem File/Export../As PDF... selected</td>
+ <td>1. MenuItem File/Export../As PDF... selected</td>
</tr>
<tr>
<td>mouseClick</td>
<td>0,7</td>
</tr>
<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
+ <td>right</td>
</tr>
<tr>
<td>pressSpecialKey</td>
<td>right</td>
</tr>
<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
+ <td>right</td>
</tr>
<tr>
<td>pressSpecialKey</td>
<td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
- <td>right</td>
+ <td>enter</td>
</tr>
<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
+ <td>2. MenuItem Help selected</td>
+</tr>
+<tr>
+ <td>mouseClick</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]#menu1</td>
+ <td>4,7</td>
</tr>
<tr>
<td>pressSpecialKey</td>
<td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
- <td>right</td>
+ <td>left</td>
</tr>
<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
+ <td>down</td>
</tr>
<tr>
<td>pressSpecialKey</td>
<td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
- <td>enter</td>
+ <td>down</td>
</tr>
<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
+ <td>enter</td>
</tr>
<tr>
<td>assertText</td>
<td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
- <td>MenuItem Help selected</td>
+ <td>3. MenuItem Edit/Cut selected</td>
</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]#menu1</td>
<td>4,7</td>
</tr>
-<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
-</tr>
<tr>
<td>pressSpecialKey</td>
- <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
- <td>left</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/VVerticalLayout[0]/VMenuBar[0]</td>
+ <td>enter</td>
</tr>
<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0]</td>
+ <td>3. MenuItem Edit/Cut selected</td>
</tr>
<tr>
<td>pressSpecialKey</td>
- <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
- <td>down</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/VVerticalLayout[0]/VMenuBar[0]</td>
+ <td>enter</td>
</tr>
<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0]</td>
+ <td>4. MenuItem Edit/Copy selected</td>
</tr>
+<!--Enter while menubar has focus but no selection should focus "File"-->
<tr>
<td>pressSpecialKey</td>
- <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
- <td>down</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/VVerticalLayout[0]/VMenuBar[0]</td>
+ <td>enter</td>
</tr>
<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0]</td>
+ <td>4. MenuItem Edit/Copy selected</td>
</tr>
+<!--Enter again should open File and focus Open-->
<tr>
<td>pressSpecialKey</td>
- <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VMenuBar[0]</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/VVerticalLayout[0]/VMenuBar[0]</td>
<td>enter</td>
</tr>
<tr>
- <td>waitForVaadin</td>
- <td></td>
- <td></td>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0]</td>
+ <td>4. MenuItem Edit/Copy selected</td>
+</tr>
+<tr>
+ <td>pressSpecialKey</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/VVerticalLayout[0]/VMenuBar[0]</td>
+ <td>enter</td>
</tr>
<tr>
<td>assertText</td>
- <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[0]/VLabel[0]</td>
- <td>MenuItem Edit/Cut selected</td>
+ <td>vaadin=runcomvaadintestscomponentsmenubarMenuBarNavigation::/VVerticalLayout[0]/VVerticalLayout[0]/VVerticalLayout[0]/VLabel[0]</td>
+ <td>5. MenuItem File/Open selected</td>
</tr>
-
</tbody></table>
</body>
</html>