Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Emm...</p> <p>It is an interesting question...</p> <p>Looking at the <a href="http://code.google.com/p/google-web-toolkit/source/browse/trunk/user/src/com/google/gwt/user/client/ui/MenuBar.java?spec=svn8746&amp;r=5308" rel="nofollow">MenuBar</a> source code... especially the method <strong>openPopup</strong></p> <pre><code> private void openPopup(final MenuItem item) { // Only the last popup to be opened should preview all event if (parentMenu != null &amp;&amp; parentMenu.popup != null) { parentMenu.popup.setPreviewingAllNativeEvents(false); } // 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 DecoratedPopupPanel(true, false, "menuPopup") { { setWidget(item.getSubMenu()); setPreviewingAllNativeEvents(true); item.getSubMenu().onShow(); } @Override protected void onPreviewNativeEvent(NativePreviewEvent event) { // Hook the popup panel's event preview. We use this to keep it from // auto-hiding when the parent menu is clicked. if (!event.isCanceled()) { switch (event.getTypeInt()) { case Event.ONMOUSEDOWN: // If the event target is part of the parent menu, suppress the // event altogether. EventTarget target = event.getNativeEvent().getEventTarget(); Element parentMenuElement = item.getParentMenu().getElement(); if (parentMenuElement.isOrHasChild(Element.as(target))) { event.cancel(); return; } super.onPreviewNativeEvent(event); if (event.isCanceled()) { selectItem(null); } return; } } super.onPreviewNativeEvent(event); } }; popup.setAnimationType(AnimationType.ONE_WAY_CORNER); popup.setAnimationEnabled(isAnimationEnabled); popup.setStyleName(STYLENAME_DEFAULT + "Popup"); String primaryStyleName = getStylePrimaryName(); if (!STYLENAME_DEFAULT.equals(primaryStyleName)) { popup.addStyleName(primaryStyleName + "Popup"); } popup.addPopupListener(this); 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.setPopupPositionAndShow(new PopupPanel.PositionCallback() { public void setPosition(int offsetWidth, int offsetHeight) { // depending on the bidi direction position a menu on the left or right // of its base item if (LocaleInfo.getCurrentLocale().isRTL()) { if (vertical) { popup.setPopupPosition(MenuBar.this.getAbsoluteLeft() - offsetWidth + 1, item.getAbsoluteTop()); } else { popup.setPopupPosition(item.getAbsoluteLeft() + item.getOffsetWidth() - offsetWidth, MenuBar.this.getAbsoluteTop() + MenuBar.this.getOffsetHeight() - 1); } } else { if (vertical) { popup.setPopupPosition(MenuBar.this.getAbsoluteLeft() + MenuBar.this.getOffsetWidth() - 1, item.getAbsoluteTop()); } else { popup.setPopupPosition(item.getAbsoluteLeft(), MenuBar.this.getAbsoluteTop() + MenuBar.this.getOffsetHeight() - 1); } } } }); } </code></pre> <p>It is interesting to point the snippet as</p> <pre><code>... popup.setPopupPositionAndShow(new PopupPanel.PositionCallback() { public void setPosition(int offsetWidth, int offsetHeight) { // depending on the bidi direction position a menu on the left or right // of its base item if (LocaleInfo.getCurrentLocale().isRTL()) { if (vertical) { popup.setPopupPosition(MenuBar.this.getAbsoluteLeft() - offsetWidth + 1, item.getAbsoluteTop()); } else { popup.setPopupPosition(item.getAbsoluteLeft() + item.getOffsetWidth() - offsetWidth, MenuBar.this.getAbsoluteTop() + MenuBar.this.getOffsetHeight() - 1); } } else { if (vertical) { popup.setPopupPosition(MenuBar.this.getAbsoluteLeft() + MenuBar.this.getOffsetWidth() - 1, item.getAbsoluteTop()); } else { popup.setPopupPosition(item.getAbsoluteLeft(), MenuBar.this.getAbsoluteTop() + MenuBar.this.getOffsetHeight() - 1); } } } }); ... </code></pre> <p>... so I may suppose there is a sense to play around MenuItem object especially its UIObject inherited methods like getAbsoluteLeft() and getAbsoluteTop(), of course ...</p> <p>I would recommend to extend MenuItem something in this way</p> <pre><code> //not tested public class MyMenuItem extends MenuItem { private MenuBar aSubMenuBar;//ItemMenu's submenu //... @Override public int getAbsoluteTop() { // TODO Auto-generated method stub return super.getAbsoluteTop()+movePopupTo(); } private int movePopupTo() { int moveTo=0; int bottom=RootPanel.getBodyElement().getAbsoluteBottom(); int rest=bottom -(super.getAbsoluteTop()+this.getaSubMenuBar().getOffsetHeight()); if(rest&lt;0) { moveTo=rest; } return moveTo; } public MenuBar getaSubMenuBar() { return aSubMenuBar; } public void setaSubMenuBar(MenuBar aSubMenuBar) { this.aSubMenuBar = aSubMenuBar; } //... } </code></pre> <p>It is not the final solution but a basic conception. </p> <hr> <p>Report if that helped</p> <p>Good luck</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload