void itemOver(MenuItem item) { if (item == null) { // Don't clear selection if the currently selected item's menu is // showing. if ((selectedItem != null) && (shownChildMenu == selectedItem.getSubMenu())) { return; } } // Style the item selected when the mouse enters. selectItem(item); // If child menus are being shown, or this menu is itself // a child menu, automatically show an item's child menu // when the mouse enters. if (item != null) { if ((shownChildMenu != null) || (parentMenu != null) || autoOpen) { doItemAction(item, false); } } }
/* * Performs the action associated with the given menu item. If the item has * a popup associated with it, the popup will be shown. If it has a command * associated with it, and 'fireCommand' is true, then the command will be * fired. Popups associated with other items will be hidden. * * @param item the item whose popup is to be shown. @param fireCommand * <code>true</code> if the item's command should be fired, * <code>false</code> otherwise. */ protected void doItemAction(final MenuItem item, boolean fireCommand) { // If the given item is already showing its menu, we're done. if ((shownChildMenu != null) && (item.getSubMenu() == shownChildMenu)) { return; } // If another item is showing its menu, then hide it. if (shownChildMenu != null) { shownChildMenu.onHide(); popup.hide(); } // If the item has no popup, optionally fire its command. if (item.getSubMenu() == null) { if (fireCommand) { // Close this menu and all of its parents. closeAllParents(); // Fire the item's command. final Command cmd = item.getCommand(); if (cmd != null) { Scheduler.get().scheduleDeferred(cmd); } } return; } // Ensure that the item is selected. selectItem(item); // Create a new popup for this item, and position it next to // the item (below if this is a horizontal menu bar, to the // right if it's a vertical bar). popup = new VOverlay(true) { { setWidget(item.getSubMenu()); item.getSubMenu().onShow(); setOwner(MenuBar.this); } @Override public boolean onEventPreview(Event event) { // Hook the popup panel's event preview. We use this to keep it // from // auto-hiding when the parent menu is clicked. switch (DOM.eventGetType(event)) { case Event.ONCLICK: // If the event target is part of the parent menu, suppress // the // event altogether. final Element target = DOM.eventGetTarget(event); final Element parentMenuElement = item.getParentMenu().getElement(); if (DOM.isOrHasChild(parentMenuElement, target)) { return false; } break; } return super.onEventPreview(event); } }; popup.addPopupListener(this); if (vertical) { popup.setPopupPosition(item.getAbsoluteLeft() + item.getOffsetWidth(), item.getAbsoluteTop()); } else { popup.setPopupPosition( item.getAbsoluteLeft(), item.getAbsoluteTop() + item.getOffsetHeight()); } shownChildMenu = item.getSubMenu(); item.getSubMenu().parentMenu = this; // Show the popup, ensuring that the menubar's event preview remains on // top // of the popup's. popup.show(); }