Class WMenuItem
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/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData -
Field Summary
Fields inherited from class eu.webtoolkit.jwt.WInteractWidget
dragTouchEndSlot_, dragTouchSlot_, noDefaultFields inherited from class eu.webtoolkit.jwt.WWidget
WT_GETEXTRAMS_JS -
Constructor Summary
ConstructorsConstructorDescriptionWMenuItem(CharSequence text) Creates a new item with given label.WMenuItem(CharSequence text, WWidget contents) Creates a new item with given label.WMenuItem(CharSequence text, WWidget contents, ContentLoading policy) Creates a new item with given label.WMenuItem(String iconPath, CharSequence text) WMenuItem(String iconPath, CharSequence text, WWidget contents) WMenuItem(String iconPath, CharSequence text, WWidget contents, ContentLoading policy) -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes this item.voidProgresses to an Ajax-enabled widget.Returns the anchor of this menu item.getBadge()Returns the item's badge.Returns the checkbox for a checkable item.Returns the contents widget for this item.getData()Returns additional data of the item.getIcon()Returns the item icon path.getLink()Returns the associated link.getMenu()Returns the submenu.Returns the menu that contains this item.Returns the path component for this item.Removes the contents widget from this item.getText()Returns the text for this item.booleanReturns whether the item is checkable.booleanReturns the checked state.booleanReturns whether the item is closeable.booleanReturns whether an item participates in internal paths.booleanReturns whether this item is a section header.booleanReturns whether the menu item can be selected.booleanReturns whether this item is a separator.voidremove()Destructor.removeWidget(WWidget widget) Removes a child widget from this container.protected voidrender(EnumSet<RenderFlag> flags) Renders the widget.voidrenderSelected(boolean selected) Renders the item as selected or unselected.voidselect()Selects this item.voidSets the item's badge.voidsetCheckable(boolean checkable) Sets if the item is checkable.voidsetChecked(boolean checked) Sets the checked state.voidsetCloseable(boolean closeable) Make it possible to close this item interactively or byclose().final voidsetContents(WWidget contents) Sets the contents widget for this item.voidsetContents(WWidget contents, ContentLoading policy) Sets the contents widget for this item.voidSets associated additional data with the item.voidsetDisabled(boolean disabled) Sets whether the widget is disabled.voidsetHidden(boolean hidden, WAnimation animation) Hides or shows the widget.voidSets the item icon path.voidsetInternalPathEnabled(boolean enabled) Configures internal path support for the item.voidSets the associated link.voidSets a sub menu.voidsetPathComponent(String path) Sets the path component for this item.voidsetSelectable(boolean selectable) Sets whether the menu item can be selected.voidsetText(CharSequence text) Sets the text for this item.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, iterateChildren, parentResized, scrolled, setContentAlignment, setContentAlignment, setFormData, setGlobalUnfocused, setLayout, setList, setList, setOverflow, setOverflow, setOverflow, setPadding, setPadding, setPaddingMethods 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, unsetDraggableMethods inherited from class eu.webtoolkit.jwt.WWebWidget
addStyleClass, beingDeleted, blurred, callJavaScriptMember, childrenChanged, doJavaScript, escapeText, escapeText, escapeText, escapeText, find, findById, focussed, formDataChanged, 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, hideToolTip, isCanReceiveFocus, isDisabled, isHidden, isHiddenKeepsGeometry, isInline, isLoaded, isPopup, isRendered, isScrollVisibilityEnabled, isScrollVisible, isSetFirstFocus, isThemeStyleEnabled, isVisible, jsStringLiteral, jsStringLiteral, manageWidget, parentResized, propagateSetVisible, refresh, removeScript, removeStyleClass, resendFormData, resize, scrollVisibilityChanged, setAttributeValue, setBaseZIndex, setCanReceiveFocus, setClearSides, setDecorationStyle, setDeferredToolTip, setFlexBox, setFloatSide, setFocus, setHiddenKeepsGeometry, setHtmlTagName, setId, setInline, setJavaScriptMember, setLineHeight, setLoadLaterWhenInvisible, setMargin, setMaximumSize, setMinimumSize, setObjectName, setOffsets, setParentWidget, setPositionScheme, setScrollVisibilityEnabled, setScrollVisibilityMargin, setStyleClass, setTabIndex, setThemeStyleEnabled, setToolTip, setVerticalAlignment, showToolTip, showToolTipOnHover, unescapeText, updateSignalConnection, voidEventSignal, widgetAdded, widgetRemovedMethods inherited from class eu.webtoolkit.jwt.WWidget
acceptDrops, acceptDrops, addCssRule, addCssRule, addJSignal, addStyleClass, animateHide, animateShow, applyThemeStyles, boxBorder, boxPadding, createJavaScript, disable, dropEvent, enable, getDropTouch, getJsRef, getParent, hide, htmlText, isExposed, isGlobalWidget, isLayoutSizeAware, layoutSizeChanged, needsRerender, positionAt, positionAt, positionAt, positionAt, removeFromParent, removeStyleClass, render, resize, scheduleRender, scheduleRender, scheduleRender, scheduleThemeStyleApply, setClearSides, setDeferredToolTip, setFocus, setHeight, setHidden, setLayoutSizeAware, setMargin, setMargin, setMargin, setMargin, setMargin, setOffsets, setOffsets, setOffsets, setOffsets, setOffsets, setToolTip, setVerticalAlignment, setWidth, show, stopAcceptDrops, toggleStyleClass, toggleStyleClass, trMethods inherited from class eu.webtoolkit.jwt.WObject
getObjectName
-
Constructor Details
-
WMenuItem
Creates a new item with given label.The optional contents is a widget that will be shown in the
WMenucontents stack when the item is selected. For this widget, a loadpolicyspecifies 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
Creates a new item with given label. -
WMenuItem
Creates a new item with given label. -
WMenuItem
-
WMenuItem
-
WMenuItem
-
-
Method Details
-
remove
public void remove()Description copied from class:WContainerWidgetDestructor.- Overrides:
removein classWContainerWidget- See Also:
-
setText
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:
-
getText
Returns the text for this item.- See Also:
-
setIcon
Sets the item icon path.The icon should have a width of 16 pixels.
- See Also:
-
getIcon
Returns the item icon path.- See Also:
-
setBadge
Sets the item's badge.To remove the badge again, call this function with
null. -
getBadge
Returns the item's badge.- See Also:
-
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:
-
isCheckable
public boolean isCheckable()Returns whether the item is checkable.- See Also:
-
setPathComponent
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
pathto 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 whitespace and special characters with '_'.- See Also:
-
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:
-
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
truefor all items but section headers and separators.- See Also:
-
isInternalPathEnabled
public boolean isInternalPathEnabled()Returns whether an item participates in internal paths.- See Also:
-
setLink
Sets the associated link. -
getLink
Returns the associated link.- See Also:
-
setMenu
Sets a sub menu.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
selectableby default.Note: If the
parent menuis aWPopupMenu, the submenu should also be aWPopupMenu.- See Also:
-
getMenu
Returns the submenu.- See Also:
-
setChecked
public void setChecked(boolean checked) Sets the checked state.This is only used when
isCheckable()==true.- See Also:
-
isChecked
public boolean isChecked()Returns the checked state.This is only used when
isCheckable()==true.- See Also:
-
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
truefor a normal menu item, andfalsefor a menu item that has a popup submenu.An item that is selectable but is disabled can still not be selected.
- Overrides:
setSelectablein classWWebWidget
-
isSelectable
public boolean isSelectable()Returns whether the menu item can be selected.- See Also:
-
setData
Sets associated additional data with the item.You can use this to associate model information with a menu item.
-
getData
Returns additional data of the item.- See Also:
-
getCheckBox
Returns the checkbox for a checkable item.- See Also:
-
setCloseable
public void setCloseable(boolean closeable) Make it possible to close this item interactively or byclose().- See Also:
-
isCloseable
public boolean isCloseable()Returns whether the item is closeable.- See Also:
-
close
public void close()Closes this item.Hides the item widget and emits
WMenu.itemClosed()signal. Only closeable items can be closed.- See Also:
-
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
WMenucontents stack when the item is selected. For this widget, the loadpolicyspecifies 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. -
getContents
Returns the contents widget for this item.- See Also:
-
getRemoveContents
Removes the contents widget from this item. -
select
public void select()Selects this item.If the item was previously closed it will be shown.
- See Also:
-
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:
-
isSectionHeader
public boolean isSectionHeader()Returns whether this item is a section header.- See Also:
-
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 itemWidget() 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:WWidgetProgresses 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:
enableAjaxin classWWebWidget- See Also:
-
setHidden
Description copied from class:WWidgetHides 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:
setHiddenin classWWebWidget
-
setDisabled
public void setDisabled(boolean disabled) Description copied from class:WWidgetSets whether the widget is disabled.The widget can be set to being disabled, or enabled. This state will also be propagated to all its descendants. Those descendants will only be "visually" made disabled, their actual
isDisabled()state will remain unaltered. All descendants will be assigned the disabled styleclass, which is dependent on the used Theme.The
isDisabled()check will thus only returntruein case setDisabled(true) has been called on the widget before. If the anscestor of a widget has been marked setDisabled(true), the widget'sisDisabled()state will remainfalse.To check if a widget has been passively disabled, by one of its anscestors, use
isEnabled().Typically, a disabled form widget will not allow changing the value, and disabled widgets will not react to mouse click events.
- Overrides:
setDisabledin classWWebWidget- See Also:
-
removeWidget
Description copied from class:WContainerWidgetRemoves a child widget from this container.If the
WContainerWidgetowns the given widget (i.e. if it was added withaddWidget()orinsertWidget()and not removed with WObject::removeChild()), a unique_ptr to this widget is returned. Otherwise, this returns nullptr.- Overrides:
removeWidgetin classWContainerWidget
-
render
Description copied from class:WWidgetRenders 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:
renderin classWInteractWidget
-