Example usage for com.google.gwt.user.client.ui MenuBar addCloseHandler

List of usage examples for com.google.gwt.user.client.ui MenuBar addCloseHandler

Introduction

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

Prototype

public HandlerRegistration addCloseHandler(CloseHandler<PopupPanel> handler) 

Source Link

Usage

From source file:com.ephesoft.gxt.core.client.ui.widget.CustomMenuBar.java

License:Open Source License

/**
 * Adds a menu item to the bar, that will open the specified menu when it is selected.
 * //  ww w  . java  2 s  .  com
 * @param text the item's text
 * @param asHTML <code>true</code> to treat the specified text as html
 * @param popup the menu to be cascaded from it
 * @return the {@link MenuItem} object created
 */
public MenuItem addItem(String text, boolean asHTML, MenuBar popup) {
    final Element parentElement = Document.get().createDivElement();
    final Element element = Document.get().createDivElement();
    element.setInnerHTML(text);
    parentElement.appendChild(element);
    final MenuItem addedItem = super.addItem(parentElement.getInnerHTML(), asHTML, popup);
    if (null != popup && null != addedItem) {
        popup.addCloseHandler(new CloseHandler<PopupPanel>() {

            @Override
            public void onClose(final CloseEvent<PopupPanel> event) {
                addedItem.removeStyleDependentName("selected");
            }
        });
    }
    return addedItem;
}