Class WMenuItem
public class WMenuItem extends WContainerWidget
Since JWt 3.3.0, this item is now a proper widget, which renders a single item in a menu.
An optional contents item can be associated with a menu item, which is inserted and shown in the widget stack of the menu to which this menu item belongs.
CSS
A menu item renders as a >li&;lt with additional markup/style classes provided by the theme. Unless you use the bootstrap theme, you will need to provide appropriate CSS.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WMenuItem.LoadPolicy
Enumeration that determines when contents should be loaded.Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WContainerWidget
WContainerWidget.Overflow
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Field Summary
Fields inherited from class eu.webtoolkit.jwt.WInteractWidget
dragTouchEndSlot_, dragTouchSlot_
-
Constructor Summary
Constructors Constructor Description WMenuItem(java.lang.CharSequence text)
Creates a new item with given label.WMenuItem(java.lang.CharSequence text, WWidget contents)
Creates a new item with given label.WMenuItem(java.lang.CharSequence text, WWidget contents, WMenuItem.LoadPolicy policy)
Creates a new item with given label.WMenuItem(java.lang.String iconPath, java.lang.CharSequence text)
WMenuItem(java.lang.String iconPath, java.lang.CharSequence text, WWidget contents)
WMenuItem(java.lang.String iconPath, java.lang.CharSequence text, WWidget contents, WMenuItem.LoadPolicy policy)
-
Method Summary
Modifier and Type Method Description void
close()
Closes this item.void
enableAjax()
Progresses to an Ajax-enabled widget.WAnchor
getAnchor()
Returns the anchor of this menu item.WCheckBox
getCheckBox()
Returns the checkbox for a checkable item.WWidget
getContents()
Returns the contents widget for this item.java.lang.Object
getData()
Returns additional data of the item.java.lang.String
getIcon()
Returns the item icon path.WWidget
getItemWidget()
Deprecated.WLink
getLink()
Returns the associated link.AnchorTarget
getLinkTarget()
Returns the link target.WMenu
getMenu()
Returns the submenu.WMenu
getParentMenu()
Returns the menu that contains this item.java.lang.String
getPathComponent()
Returns the path component for this item.WString
getText()
Returns the text for this item.boolean
isCheckable()
Returns whether the item is checkable.boolean
isChecked()
Returns the checked state.boolean
isCloseable()
Returns whether the item is closeable.boolean
isInternalPathEnabled()
Returns whether an item participates in internal paths.boolean
isSectionHeader()
Returns whether this item is a section header.boolean
isSelectable()
Returns whether the menu item can be selected.boolean
isSeparator()
Returns whether this item is a separator.void
remove()
Destructor.protected void
render(java.util.EnumSet<RenderFlag> flags)
Renders the widget.void
renderSelected(boolean selected)
Renders the item as selected or unselected.void
select()
Selects this item.void
setCheckable(boolean checkable)
Sets if the item is checkable.void
setChecked(boolean checked)
Sets the checked state.void
setCloseable(boolean closeable)
Make it possible to close this item interactively or byclose()
.void
setContents(WWidget contents)
Sets the contents widget for this item.void
setContents(WWidget contents, WMenuItem.LoadPolicy policy)
Sets the contents widget for this item.void
setData(java.lang.Object data)
Sets associated additional data with the item.void
setDisabled(boolean disabled)
Sets whether the widget is disabled.void
setHidden(boolean hidden, WAnimation animation)
Hides or shows the widget.void
setIcon(java.lang.String path)
Sets the item icon path.void
setInternalPathEnabled(boolean enabled)
Configures internal path support for the item.void
setLink(WLink link)
Sets the associated link.void
setLinkTarget(AnchorTarget target)
Sets the link target.void
setMenu(WMenu menu)
Sets a sub menu.void
setPathComponent(java.lang.String path)
Sets the path component for this item.void
setSelectable(boolean selectable)
Sets whether the menu item can be selected.void
setSubMenu(WMenu menu)
Deprecated.usesetMenu()
insteadvoid
setText(java.lang.CharSequence text)
Sets the text for this item.Signal1<WMenuItem>
triggered()
Signal emitted when an item is activated.Methods inherited from class eu.webtoolkit.jwt.WContainerWidget
addWidget, clear, createDomElement, getContentAlignment, getCount, getDomChanges, getIndexOf, getLayout, getPadding, getScrollLeft, getScrollTop, getWidget, insertBefore, insertWidget, isGlobalUnfocussed, isList, isOrderedList, isUnorderedList, parentResized, removeWidget, scrolled, setContentAlignment, setContentAlignment, setFormData, setGlobalUnfocused, setLayout, setLayout, setLayout, setList, setList, setOverflow, setOverflow, setOverflow, setPadding, setPadding, setPadding
Methods inherited from class eu.webtoolkit.jwt.WInteractWidget
clicked, doubleClicked, enterPressed, escapePressed, gestureChanged, gestureEnded, gestureStarted, getMouseOverDelay, isEnabled, keyPressed, keyWentDown, keyWentUp, load, mouseDragged, mouseMoved, mouseWentDown, mouseWentOut, mouseWentOver, mouseWentUp, mouseWheel, propagateSetEnabled, setDraggable, setDraggable, setDraggable, setDraggable, setMouseOverDelay, setPopup, touchEnded, touchMoved, touchStarted, unsetDraggable
Methods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, blurred, callJavaScriptMember, childrenChanged, doJavaScript, escapeText, escapeText, escapeText, escapeText, find, findById, focussed, getAttributeValue, getBaseZIndex, getChildren, getClearSides, getDecorationStyle, getFloatSide, getHeight, getHtmlTagName, getId, getJavaScriptMember, getLineHeight, getMargin, getMaximumHeight, getMaximumWidth, getMinimumHeight, getMinimumWidth, getOffset, getPositionScheme, getScrollVisibilityMargin, getStyleClass, getTabIndex, getToolTip, getVerticalAlignment, getVerticalAlignmentLength, getWidth, hasFocus, hasStyleClass, isCanReceiveFocus, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, jsStringLiteral, jsStringLiteral, parentResized, propagateSetVisible, refresh, removeScript, removeStyleClass, resize, scrollVisibilityChanged, setAttributeValue, setBaseZIndex, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setFloatSide, setFocus, setHiddenKeepsGeometry, setHtmlTagName, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setOffsets, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment, updateSignalConnection, voidEventSignal
Methods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isLayoutSizeAware, layoutSizeChanged, needsRerender, positionAt, positionAt, removeChild, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setObjectName, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, tr
Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getObjectName
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
WMenuItem
Creates a new item with given label.The optional contents is a widget that will be shown in the
WMenu
contents stack when the item is selected. For this widget, a loadpolicy
specifies whether the contents widgets is transmitted only when it the item is activated for the first time (LazyLoading) or transmitted prior to first rendering.If the menu supports internal path navigation, then a default
getPathComponent()
will be derived from thelabel
, and can be customized usingsetPathComponent()
. -
WMenuItem
public WMenuItem(java.lang.CharSequence text)Creates a new item with given label.Calls
this(text, (WWidget)null, WMenuItem.LoadPolicy.LazyLoading)
-
WMenuItem
Creates a new item with given label.Calls
this(text, contents, WMenuItem.LoadPolicy.LazyLoading)
-
WMenuItem
public WMenuItem(java.lang.String iconPath, java.lang.CharSequence text, WWidget contents, WMenuItem.LoadPolicy policy) -
WMenuItem
public WMenuItem(java.lang.String iconPath, java.lang.CharSequence text) -
WMenuItem
-
-
Method Details
-
remove
public void remove()Description copied from class:WContainerWidget
Destructor.- Overrides:
remove
in classWContainerWidget
- See Also:
WContainerWidget.removeWidget(WWidget widget)
-
setText
public void setText(java.lang.CharSequence text)Sets the text for this item.Unless a custom path component was defined, the
getPathComponent()
is also updated based on the new text.The item widget is updated using updateItemWidget().
- See Also:
setPathComponent(String path)
-
getText
Returns the text for this item.- See Also:
setText(CharSequence text)
-
setIcon
public void setIcon(java.lang.String path)Sets the item icon path.The icon should have a width of 16 pixels.
- See Also:
setText(CharSequence text)
-
getIcon
public java.lang.String getIcon()Returns the item icon path.- See Also:
setIcon(String path)
-
setCheckable
public void setCheckable(boolean checkable)Sets if the item is checkable.When an item is checkable, a checkbox is displayed to the left of the item text (instead of an icon).
- See Also:
setChecked(boolean checked)
,isChecked()
-
isCheckable
public boolean isCheckable()Returns whether the item is checkable.- See Also:
setCheckable(boolean checkable)
-
setPathComponent
public void setPathComponent(java.lang.String path)Sets the path component for this item.The path component is used by the menu item in the application internal path (see
WApplication#setInternalPath()
), when internal paths are enabled (seeWMenu#setInternalPathEnabled()
) for the menu.You may specify an empty
path
to let a menu item be the "default" menu option.For example, if
WMenu.getInternalBasePath()
is"/examples/"
andgetPathComponent()
for is"charts/"
, then the internal path for the item will be"/examples/charts/"
.By default, the path is automatically derived from
getText()
. If aWString.isLiteral()
is used, the path is based on the text itself, otherwise on theWString.getKey()
. It is converted to lower case, and replacing white space and special characters with '_'. -
getPathComponent
public java.lang.String getPathComponent()Returns the path component for this item.You may want to reimplement this to customize the path component set by the item in the application internal path.
- See Also:
setPathComponent(String path)
-
setInternalPathEnabled
public void setInternalPathEnabled(boolean enabled)Configures internal path support for the item.This configures whether the item supports internal paths (in a menu which supports internal paths).
The default value is
true
for all items but section headers and separators. -
isInternalPathEnabled
public boolean isInternalPathEnabled()Returns whether an item participates in internal paths.- See Also:
setInternalPathEnabled(boolean enabled)
-
setLink
Sets the associated link. -
getLink
Returns the associated link.- See Also:
setLink(WLink link)
-
setLinkTarget
Sets the link target.- See Also:
setLink(WLink link)
-
getLinkTarget
Returns the link target.- See Also:
setLinkTarget(AnchorTarget target)
-
setMenu
Sets a sub menu.Ownership of the
subMenu
is transferred to the item. In most cases, the sub menu would use the same contents stack as the parent menu.Note that adding a submenu makes this item not
selectable
by default.Note: If the
parent menu
is aWPopupMenu
, the submenu should also be aWPopupMenu
.- See Also:
setSelectable(boolean selectable)
-
setSubMenu
Deprecated.usesetMenu()
insteadSets a sub menu (deprecated) -
getMenu
Returns the submenu.- See Also:
setMenu(WMenu menu)
-
setChecked
public void setChecked(boolean checked)Sets the checked state.This is only used when
isCheckable()
==true
.- See Also:
setCheckable(boolean checkable)
,isCheckable()
-
isChecked
public boolean isChecked()Returns the checked state.This is only used when
isCheckable()
==true
.- See Also:
setChecked(boolean checked)
,isCheckable()
-
setSelectable
public void setSelectable(boolean selectable)Sets whether the menu item can be selected.Only a menu item that can be selected can be the result of a popup menu selection.
The default value is
true
for a normal menu item, andfalse
for a menu item that has a submenu.An item that is selectable but is disabled can still not be selected.
- Overrides:
setSelectable
in classWWebWidget
-
isSelectable
public boolean isSelectable()Returns whether the menu item can be selected.- See Also:
setSelectable(boolean selectable)
-
setData
public void setData(java.lang.Object data)Sets associated additional data with the item.You can use this to associate model information with a menu item.
-
getData
public java.lang.Object getData()Returns additional data of the item.- See Also:
setData(Object data)
-
getCheckBox
Returns the checkbox for a checkable item.- See Also:
setCheckable(boolean checkable)
-
setCloseable
public void setCloseable(boolean closeable)Make it possible to close this item interactively or byclose()
.- See Also:
close()
,isCloseable()
-
isCloseable
public boolean isCloseable()Returns whether the item is closeable.- See Also:
setCloseable(boolean closeable)
-
close
public void close()Closes this item.Hides the item widget and emits
WMenu.itemClosed()
signal. Only closeable items can be closed.- See Also:
setCloseable(boolean closeable)
,WWidget.hide()
-
getParentMenu
Returns the menu that contains this item. -
setContents
Sets the contents widget for this item.The contents is a widget that will be shown in the
WMenu
contents stack when the item is selected. For this widget, the loadpolicy
specifies whether the contents widgets is transmitted only when it the item is activated for the first time (LazyLoading) or transmitted prior to first rendering. -
setContents
Sets the contents widget for this item.Calls
setContents(contents, WMenuItem.LoadPolicy.LazyLoading)
-
getContents
Returns the contents widget for this item. -
getItemWidget
Deprecated.This is a pre-Wt 3.3.0 artifact which has lost its value sinceWMenuItem
is now a widget.Returns the widget that represents the item (deprecated).This returns this.
-
select
public void select()Selects this item.If the item was previously closed it will be shown.
- See Also:
close()
-
triggered
Signal emitted when an item is activated.Returns this item as argument.
-
isSeparator
public boolean isSeparator()Returns whether this item is a separator.- See Also:
WMenu.addSeparator()
-
isSectionHeader
public boolean isSectionHeader()Returns whether this item is a section header. -
getAnchor
Returns the anchor of this menu item.Can be used to add widgets to the menu.
-
renderSelected
public void renderSelected(boolean selected)Renders the item as selected or unselected.The default implementation sets the styleclass for
getItemWidget()
to 'item' for an unselected not closeable, 'itemselected' for selected not closeable, 'citem' for an unselected closeable and 'citemselected' for selected closeable item.Note that this method is called from within a stateless slot implementation, and thus should be stateless as well.
-
enableAjax
public void enableAjax()Description copied from class:WWidget
Progresses to an Ajax-enabled widget.This method is called when the progressive bootstrap method is used, and support for AJAX has been detected. The default behavior will upgrade the widget's event handling to use AJAX instead of full page reloads, and propagate the call to its children.
You may want to reimplement this method if you want to make changes to widget when AJAX is enabled. You should always call the base implementation.
- Overrides:
enableAjax
in classWWebWidget
- See Also:
WApplication.enableAjax()
-
setHidden
Description copied from class:WWidget
Hides or shows the widget.Hides or show the widget (including all its descendant widgets). When setting
hidden
=false
, this widget and all descendant widgets that are not hidden will be shown. A widget is only visible if it and all its ancestors in the widget tree are visible, which may be checked usingisVisible()
.- Overrides:
setHidden
in classWWebWidget
-
setDisabled
public void setDisabled(boolean disabled)Description copied from class:WWidget
Sets whether the widget is disabled.Enables or disables the widget (including all its descendant widgets). setDisabled(false) will enable this widget and all descendant widgets that are not disabled. A widget is only enabled if it and all its ancestors in the widget tree are disabled.
Typically, a disabled form widget will not allow changing the value, and disabled widgets will not react to mouse click events.
- Overrides:
setDisabled
in classWWebWidget
- See Also:
WWidget.disable()
,WWidget.enable()
-
render
Description copied from class:WWidget
Renders the widget.This function renders the widget (or an update for the widget), after this has been scheduled using
scheduleRender()
.The default implementation will render the widget by serializing changes to JavaScript and HTML. You may want to reimplement this widget if you have been postponing some of the layout / rendering implementation until the latest moment possible. In that case you should make sure you call the base implementation however.
- Overrides:
render
in classWWebWidget
-
WMenuItem
is now a widget.