public class Menu extends com.google.gwt.user.client.ui.HTMLPanel implements IMenu
Menu is a wrapper for the
MaterialMenu component. It enables the user to select an option from a
list of items presented in a dialog. It is activated when its associated
button is clicked.Button| Modifier and Type | Class and Description |
|---|---|
static interface |
Menu.ItemClickListener
Objects that need to be notified when an
MenuItem is clicked should
implement this interface and register themselves to the Menu using
the addItemClickListener(ItemClickListener) method. |
com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled| Modifier and Type | Field and Description |
|---|---|
static String |
CSS_JS_MENU
css flag intended for component upgrade.
|
static String |
CSS_MDL_MENU
The
Menu material style. |
| Constructor and Description |
|---|
Menu()
Creates the menu component and associates it with an action button.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addItem(String item)
Has the same effect as Menu.addItem(item , true).
|
void |
addItem(String item,
boolean enabled)
Adds a new item to the menu.
|
void |
addItem(String value,
String text)
Shortcut for
addItem(String, boolean) that adds an enabled
item to the menu. |
void |
addItem(String text,
String value,
boolean enabled)
Adds a new option to the list of options in the menu.
|
void |
addItemClickListener(Menu.ItemClickListener listener)
When an object needs to be notified upon a
MenuItem click, it must
be be registered to the Menu as an Menu.ItemClickListener . |
protected void |
afterItemClicked(com.google.gwt.event.dom.client.ClickEvent event)
This method should be extended when additional behavior is required.
|
void |
clearMenu()
Remove all items from the menu.
|
int |
getItemCount()
Returns the items count in a menu.
|
protected List<MenuItem> |
getItems()
Getter for the items list.
|
String |
getItemText(int index)
return the text of the item located at the position provided as input.
|
String |
getValue(int index)
return the value of the item located at the position provided as input.
|
boolean |
isEnabled(int index)
Modify the enabled state of an item.
|
void |
onLoad()
Apply magic to bring the menu to life.
|
void |
setActionId(String forId)
|
void |
setAnchor(MenuAnchor inputAnchor)
Sets the position of the
Menu on the screen related to its
associated action button using one of the available anchoring options
provided by MenuAnchor. |
boolean |
setEnabled(int index,
boolean enabled)
Modify the enabled state of an item.
|
protected void |
setItems(List<MenuItem> itemList)
Setter for the items list.
|
add, add, add, addAndReplaceElement, addAndReplaceElement, addAndReplaceElement, addAndReplaceElement, addAndReplaceElement, addAndReplaceElement, createUniqueId, getElementById, wrapadd, adjustIndex, checkIndexBoundsForAccess, checkIndexBoundsForInsertion, getChildren, getWidget, getWidgetCount, getWidgetIndex, getWidgetIndex, insert, insert, iterator, remove, removeadd, adopt, clear, doAttachChildren, doDetachChildren, orphan, removeaddAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, onUnload, removeFromParent, setLayoutData, sinkEvents, unsinkEventsaddStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toStringpublic static final String CSS_MDL_MENU
Menu material style.public static final String CSS_JS_MENU
public Menu()
Menu and the action button is established by the
id of the button and must be provided using
setActionId(String). Buttonpublic final void setActionId(String forId) throws IllegalStateException
Button enabling mdl to bind the
Menu to it. This method can only be invoked when the menu is not
already attached to the DOM. If the menu is attached and therefore
upgraded, the action button cannot be changed.forId - The id of the action Button.IllegalStateException - mdl does not allow re binding the menu when the menu is not yet
upgraded. If the menu is already upgraded an exception is raised.public final void setAnchor(MenuAnchor inputAnchor)
IMenuMenu on the screen related to its
associated action button using one of the available anchoring options
provided by MenuAnchor.public final void onLoad()
Menu is upgraded using
ComponentHandler.upgradeElement(com.google.gwt.dom.client.Element)
which in turn uses MaterialMenu
to change the DOM tree of the component and add the required event
handlers.Menu to
be already attached to the DOM. This is due to the fact that MaterialMenu
references the Menu's parent element during the upgrade.Menu is.onLoad in class com.google.gwt.user.client.ui.Widgetpublic final void clearMenu()
IMenupublic final void addItem(String text, String value, boolean enabled)
IMenupublic final void addItem(String item, boolean enabled)
item - The value and the text of the item to be addedenabled - Defines whether the option can be chosen or not.public final void addItem(String item)
item - The value and the text of the item to be addedpublic final void addItem(String value, String text)
addItem(String, boolean) that adds an enabled
item to the menu.value - the value of the item to be added.text - the text of the item to be added.public final void addItemClickListener(Menu.ItemClickListener listener)
IMenuMenuItem click, it must
be be registered to the Menu as an Menu.ItemClickListener .Menu.ItemClickListener interfaceMenuItem is
clicked inside Menu.ItemClickListener.onItemClicked(ItemClickEvent)addItemClickListener(ItemClickListener) to register
itself to the menu and receive click notificationsaddItemClickListener in interface IMenulistener - The object to be notified when a MenuItem is clicked.Menu.ItemClickListenerpublic final int getItemCount()
IMenugetItemCount in interface IMenupublic final String getItemText(int index)
IMenugetItemText in interface IMenuindex - the position of the itempublic final String getValue(int index)
IMenupublic final boolean setEnabled(int index,
boolean enabled)
IMenusetEnabled in interface IMenuindex - the position of the item in the item list of the menuenabled - the state to be set for the itemtrue if the state was modified, false
otherwise.public final boolean isEnabled(int index)
IMenuprotected void afterItemClicked(com.google.gwt.event.dom.client.ClickEvent event)
event - The browser click event.protected final void setItems(List<MenuItem> itemList)
itemList - the menu item list.Copyright © 2016 com.github.ilyes4j. All rights reserved.