public class Menu extends com.google.gwt.user.client.ui.HTMLPanel implements IMenu, IHasEventSource
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
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)
Syntactic sugar for
IMenu.addItem(String, String, boolean) where
the text and value are the same. |
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 |
addItem(String text,
String value,
int position,
boolean enabled)
Adds a an option into the set of options of the menu at a specified
position.
|
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 .In order to receive item click notifications, the object should : Implement the Menu.ItemClickListener interface
Define the actions that should be performed when a MenuItem is
clicked inside Menu.ItemClickListener.onItemClicked(ItemClickEvent)
Call addItemClickListener(ItemClickListener) to register
itself to the menu and receive click notifications
|
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.
|
boolean |
isUpgraded() |
void |
onLoad()
Apply magic to bring the menu to life.
After being attached to the DOM, the 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.The upgrade process performed by MaterialMenu requires the Menu to
be already attached to the DOM. |
void |
removeItem(int index)
Removes an item from the menu.
|
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 .An extra care should be taken when anchoring the menu. |
boolean |
setEnabled(int index,
boolean enabled)
Modify the enabled state of an item.
|
void |
setEventSource(Object inputSource) |
protected void |
setItems(List<MenuItem> itemList)
Setter for the items list.
|
void |
upgrade()
Causes the component to be upgraded.
|
add, add, add, addAndReplaceElement, addAndReplaceElement, addAndReplaceElement, addAndReplaceElement, addAndReplaceElement, addAndReplaceElement, createUniqueId, getElementById, wrap
add, adjustIndex, checkIndexBoundsForAccess, checkIndexBoundsForInsertion, getChildren, getWidget, getWidgetCount, getWidgetIndex, getWidgetIndex, insert, insert, iterator, remove, remove
add, adopt, clear, doAttachChildren, doDetachChildren, orphan, remove
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, onUnload, removeFromParent, setLayoutData, sinkEvents, unsinkEvents
addStyleDependentName, 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, toString
public Menu()
Menu
and the action button is established by the
id of the button and must be provided using
setActionId(String)
. Button
public void setEventSource(Object inputSource)
setEventSource
in interface IHasEventSource
inputSource
- the object designated as the source of events published by the
menupublic 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)
IMenu
Menu
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.Widget
public final void clearMenu()
IMenu
public final void addItem(String text, String value, boolean enabled)
IMenu
public void addItem(String text, String value, int position, boolean enabled)
IMenu
public final void addItem(String item, boolean enabled)
IMenu
IMenu.addItem(String, String, boolean)
where
the text and value are the same.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)
IMenu
MenuItem
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 IMenu
listener
- The object to be notified when a MenuItem
is clicked.Menu.ItemClickListener
public final int getItemCount()
IMenu
getItemCount
in interface IMenu
public final String getItemText(int index)
IMenu
getItemText
in interface IMenu
index
- the position of the itempublic final String getValue(int index)
IMenu
public final boolean setEnabled(int index, boolean enabled)
IMenu
setEnabled
in interface IMenu
index
- 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)
IMenu
public void removeItem(int index)
IMenu
removeItem
in interface IMenu
index
- the position of the item to be removedpublic void upgrade()
IUpgrade
public boolean isUpgraded()
isUpgraded
in interface IUpgrade
protected 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.