Example usage for com.google.gwt.user.client.ui MenuItem getSubMenu

List of usage examples for com.google.gwt.user.client.ui MenuItem getSubMenu

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui MenuItem getSubMenu.

Prototype

public MenuBar getSubMenu() 

Source Link

Document

Gets the sub-menu associated with this item.

Usage

From source file:com.qualogy.qafe.gwt.client.component.QMenuBar.java

License:Apache License

public void removeMenu(MenuBar menuBar) {
    MenuItem wrapper = null;// w ww.j av  a2s.  co m
    for (MenuItem menuItem : getItems()) {

        if (menuItem.getSubMenu() == menuBar) {
            wrapper = menuItem;
        }
    }
    if (null != wrapper) {
        this.removeItem(wrapper);
    }
}

From source file:com.sencha.gxt.widget.core.client.menu.Menu.java

License:sencha.com license

/**
 * Provides information about external events occurring in the DOM, allow the menu to decide to hide if necessary
 *///from   w w w  . ja  v  a2  s. c o m
protected void onPreviewEvent(NativePreviewEvent pe) {
    int type = pe.getTypeInt();
    switch (type) {
    case Event.ONMOUSEDOWN:
    case Event.ONMOUSEWHEEL:
    case Event.ONSCROLL:
    case Event.ONKEYPRESS:
    case Event.ONTOUCHSTART:
        XElement target = pe.getNativeEvent().getEventTarget().cast();

        // ignore targets within a parent with x-ignore, such as the listview in
        // a combo
        if (target.findParent(".x-ignore", 10) != null) {
            return;
        }

        // is the target part of the sub menu chain, if yes, dont out hide
        Item active = activeItem != null ? activeItem : getParentItem();
        while (active != null) {
            if (active instanceof MenuItem) {
                MenuItem menuItem = (MenuItem) active;
                if (menuItem.getParent().getElement().isOrHasChild(target)) {
                    return;
                }
                if (menuItem.getSubMenu() != null && menuItem.getSubMenu().isVisible()) {
                    if (menuItem.getSubMenu().getElement().isOrHasChild(target)) {
                        return;
                    }
                    active = menuItem.getSubMenu().activeItem;
                } else {
                    active = null;
                }
            } else {
                active = null;
            }
        }

        if (!getElement().isOrHasChild(target)) {
            hide(true);
            return;
        }
        break;
    }
}

From source file:com.vaadin.client.ui.menubar.MenuBar.java

License:Apache License

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;//  w w  w .j  a  v a  2 s . co  m
    }

    // 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();
}

From source file:com.vaadin.terminal.gwt.client.ui.MenuBar.java

License:Open Source License

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;//from   w  w w .j  a  va  2 s  .c om
    }

    // 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();
        }

        @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();
}

From source file:org.pentaho.mantle.client.MantleMenuBar.java

License:Open Source License

private void hidePDFFrames(MenuItem item) {
    Frame frame = getActiveBrowserPerspectiveFrame();
    if (frame == null) {
        return;//  ww  w. j  a v a  2  s  . c om
    }
    if (item.getSubMenu() != null && item.getSubMenu().isVisible()) {
        if (ElementUtils.elementsOverlap(item.getSubMenu().getElement(),
                getActiveBrowserPerspectiveFrame().getElement())) {
            FrameUtils.setEmbedVisibility(getActiveBrowserPerspectiveFrame(), false);
        }
    } else if (item.getParentMenu() != null) { // popups
        if (ElementUtils.elementsOverlap(item.getParentMenu().getElement(),
                getActiveBrowserPerspectiveFrame().getElement())) {
            FrameUtils.setEmbedVisibility(getActiveBrowserPerspectiveFrame(), false);
        }
    }
}

From source file:org.pentaho.ui.xul.gwt.tags.GwtMenubar.java

License:Open Source License

private void hide() {
    XulComponent parentComponent = getParent();
    if (parentComponent instanceof GwtMenubar) {
        if (!isMouseOver()) {
            MenuItem child = getSelectedItem();
            if (child != null) {
                MenuBar subMenu = (MenuBar) child.getSubMenu();
                if (subMenu != null) {
                    if (subMenu.getGwtMenubar().isMouseOver()) {
                        return;
                    }/*from w  w w .ja v  a2s .  c  o  m*/
                }
            }
            GwtMenubar parentMenu = ((GwtMenubar) parentComponent);
            if (!parentMenu.isMouseOver()) {
                parentMenu.closeAllChildren(false);
                parentMenu.hide();
            }
        }
    }
}

From source file:org.rstudio.core.client.command.BaseMenuBar.java

License:Open Source License

@Override
protected void onLoad() {
    if (vertical_ && glass++ == 0)
        eventBus_.fireEvent(new GlassVisibilityEvent(true));
    super.onLoad();
    for (MenuItem child : getItems()) {
        if (child instanceof AppMenuItem)
            ((AppMenuItem) child).onShow();
        else {//w w w  .ja  v a  2s  . c o  m
            // if this is a submenu that consists entirely of hidden commands, 
            // hide the submenu and its flyout icon 
            MenuBar submenu = child.getSubMenu();
            if (submenu != null && submenu instanceof AppMenuBar) {
                boolean visible = child.isVisible();
                boolean newVisible = !((AppMenuBar) submenu).allInvisibleCmds();
                if (visible != newVisible) {
                    child.setVisible(newVisible);
                    updateSubmenuIcon(child);
                }
            }
        }
    }
    if (autoHideRedundantSeparators_)
        manageSeparators();
}

From source file:org.rstudio.studio.client.application.ui.impl.WebApplicationHeader.java

License:Open Source License

/**
 * Without this fixup, the main menu doesn't properly deselect its items
 * when the mouse takes focus away./*from  w w  w .j  ava  2s . co  m*/
 */
private void fixup(final AppMenuBar mainMenu) {
    mainMenu.addCloseHandler(new CloseHandler<PopupPanel>() {
        public void onClose(CloseEvent<PopupPanel> popupPanelCloseEvent) {
            // Only dismiss the selection if the panel that just closed belongs
            // to the currently selected item. Otherwise, the selected item
            // has already changed and we don't want to mess with it. (This is
            // NOT an edge case, it is very common.)
            MenuItem menuItem = mainMenu.getSelectedItem();
            if (menuItem != null) {
                MenuBar subMenu = menuItem.getSubMenu();
                if (subMenu != null && popupPanelCloseEvent.getTarget() != null
                        && subMenu.equals(popupPanelCloseEvent.getTarget().getWidget())) {
                    Scheduler.get().scheduleDeferred(new ScheduledCommand() {
                        public void execute() {
                            mainMenu.selectItem(null);
                        }
                    });
                }
            }
        }
    });
}

From source file:org.xwiki.gwt.wysiwyg.client.MenuBarController.java

License:Open Source License

/**
 * Fills the given menu bar with items matching the given list of descriptors.
 * /*from  w  w w  . j av a  2 s .c o  m*/
 * @param menuBar the menu bar to be filled
 * @param descriptors the list of menu item descriptors
 * @param pluginManager the object used to access the menu bar {@link UIExtension}s
 */
private void fillMenuBar(MenuBar menuBar, List<MenuItemDescriptor> descriptors, PluginManager pluginManager) {
    for (MenuItemDescriptor descriptor : descriptors) {
        UIExtension uie = pluginManager.getUIExtension(MENU_ROLE, descriptor.getFeature());
        if (uie != null) {
            // We have to handle menu items and menu item separators differently because MenuItemSeparator doesn't
            // extends MenuItem.
            UIObject uiObject = uie.getUIObject(descriptor.getFeature());
            if (uiObject instanceof MenuItemSeparator) {
                menuBar.addSeparator((MenuItemSeparator) uiObject);
            } else if (uiObject instanceof MenuItem) {
                MenuItem menuItem = (MenuItem) uiObject;
                if (!descriptor.getSubMenu().isEmpty()) {
                    menuItem.setSubMenu(new MenuBar(true));
                    fillMenuBar((MenuBar) menuItem.getSubMenu(), descriptor.getSubMenu(), pluginManager);
                }
                menuBar.addItem(menuItem);
            }
        }
    }
}