Class WSubMenu
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.AbstractContainer
-
- com.github.bordertech.wcomponents.AbstractNamingContextContainer
-
- com.github.bordertech.wcomponents.WSubMenu
-
- All Implemented Interfaces:
AccessKeyable
,Container
,Disableable
,MenuContainer
,MenuItem
,MenuItemSelectable
,MenuSelectContainer
,NamingContextable
,WComponent
,WebComponent
,Serializable
public class WSubMenu extends AbstractNamingContextContainer implements Disableable, MenuSelectContainer, MenuItemSelectable, AccessKeyable
This component is used to provide either a dropmenu (when added directly to a
WMenu
or nestable sub menus (when added to anotherWSubMenu
instance).Sub Menus may contain the following components:
- Other sub menus.
- Menu items (
WMenuItem
) - Menu separators (see
addSeparator()
)
- Author:
- Adam Millard, Yiannis Paschalidis, Mark Reeves
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WSubMenu.MenuMode
The available types of operation.static class
WSubMenu.SubMenuModel
Holds the extrinsic state information of a WSubMenu.-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractWComponent
AbstractWComponent.WComponentRef
-
Nested classes/interfaces inherited from interface com.github.bordertech.wcomponents.MenuSelectContainer
MenuSelectContainer.SelectionMode
-
-
Field Summary
-
Fields inherited from interface com.github.bordertech.wcomponents.WComponent
DEFAULT_APPLICATION_ID, DEFAULT_INTERNAL_ID, DEFAULT_NO_ID, ID_CONTEXT_SEPERATOR, ID_FRAMEWORK_ASSIGNED_SEPERATOR, ID_VALIDATION_PATTERN
-
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(WMenuItem item)
void
add(WMenuItemGroup item)
void
add(WSeparator item)
void
add(WSubMenu item)
void
addMenuItem(MenuItem item)
void
addMenuItemGroup(WMenuItemGroup menuItemGroup)
Deprecated.menu groups are not compatible with WCAG 2.0.void
addSeparator()
Adds a separator to the sub-menu.char
getAccessKey()
Action
getAction()
String
getActionCommand()
Retrieves this sub-menu's "default" action command.Serializable
getActionObject()
Retrieves this sub-menu's "default" action object.protected WSubMenu.SubMenuModel
getComponentModel()
Returns the effective component model for this component.WDecoratedLabel
getDecoratedLabel()
List<MenuItem>
getMenuItems()
WSubMenu.MenuMode
getMode()
protected WSubMenu.SubMenuModel
getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified.Boolean
getSelectability()
Deprecated.WSubMenu is never selectable for a11y reasons.MenuSelectContainer.SelectionMode
getSelectionMode()
WMenu.SelectMode
getSelectMode()
Deprecated.UseMenuSelectContainer.getSelectionMode()
instead.String
getText()
void
handleRequest(Request request)
Override handleRequest in order to perform processing for this component.boolean
isDisabled()
Indicates whether this sub menu is disabled in the given context.protected boolean
isMenuPresent(Request request)
Determine if this WMenuItem's parent WMenu is on the Request.boolean
isMultipleSelection()
Deprecated.boolean
isOpen()
Indicates whether this sub-menu is open in the given context.Boolean
isSelectable()
Deprecated.WSubMenu is never selectable for a11y reasons.boolean
isSelectAllowed()
boolean
isSelected()
Deprecated.WSubMenu is never selectable for a11y reasons.boolean
isTopLevelMenu()
Indicates whether this is a top-level menu (ie. attached to a menu bar).protected WSubMenu.SubMenuModel
newComponentModel()
Creates a new component model.void
paintMenuItems(RenderContext renderContext)
Paint the menu items.protected void
preparePaintComponent(Request request)
Override preparePaintComponent in order to correct the visibility of the sub-menu's children before they are rendered.void
remove(WComponent item)
Deprecated.void
removeAllMenuItems()
Remove all menu items.void
removeMenuItem(MenuItem item)
void
setAccessKey(char accessKey)
Set the access key on the component.void
setAction(Action action)
Sets the action to execute when the sub-menu is selected.void
setActionCommand(String actionCommand)
Sets this sub-menu's action command.void
setActionObject(Serializable actionObject)
Sets this sub-menu's "default" action object.void
setDisabled(boolean disabled)
Sets whether this sub menu is disabled.void
setMode(WSubMenu.MenuMode mode)
Sets the menu mode.void
setMultipleSelection(boolean multipleSelection)
Deprecated.void
setOpen(boolean open)
Sets whether this menu is open.void
setSelectability(Boolean selectability)
Deprecated.WSubMenu is never selectable for a11y reasons.void
setSelectable(Boolean selectable)
Deprecated.WSubMenu is never selectable for a11y reasons.void
setSelectionMode(MenuSelectContainer.SelectionMode selectionMode)
void
setSelectMode(WMenu.SelectMode selectMode)
Deprecated.UseMenuSelectContainer.setSelectionMode(SelectionMode)
instead.void
setText(String text)
Sets the sub-menu text.String
toString()
Creates a String representation of this component; usually for debugging purposes.-
Methods inherited from class com.github.bordertech.wcomponents.AbstractNamingContextContainer
getNamingContextId, isNamingContext, setNamingContext
-
Methods inherited from class com.github.bordertech.wcomponents.AbstractContainer
getChildAt, getChildCount, getChildren, getIndexOfChild
-
Methods inherited from class com.github.bordertech.wcomponents.AbstractWComponent
addHtmlClass, addHtmlClass, addNotify, afterPaint, assertAddSupported, beforePaint, createErrorDiagnostic, createErrorDiagnostic, forward, getAccessibleText, getAttribute, getBaseUrl, getDefaultModel, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getScratchMap, getTabIndex, getTag, getTemplate, getTemplateMarkUp, getToolTip, hasNoComponentModel, hasTabIndex, initialiseComponentModel, invokeLater, invokeLaters, isDebugStructure, isDefaultState, isFlagSet, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, paintComponent, preparePaint, removeAttribute, removeComponentModel, removeHtmlClass, removeHtmlClass, removeNotify, replaceWComponent, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFlag, setFocussed, setHidden, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showErrorIndicatorsForComponent, showWarningIndicators, showWarningIndicatorsForComponent, tidyUpUIContext, tidyUpUIContextForTree, validate, validateComponent, writeReplace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.bordertech.wcomponents.AccessKeyable
getAccessKeyAsString
-
Methods inherited from interface com.github.bordertech.wcomponents.Container
getChildAt, getChildCount, getChildren, getIndexOfChild
-
Methods inherited from interface com.github.bordertech.wcomponents.WComponent
addHtmlClass, addHtmlClass, forward, getAccessibleText, getAttribute, getBaseUrl, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getTabIndex, getTag, getToolTip, hasTabIndex, invokeLater, isDefaultState, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, preparePaint, removeAttribute, removeHtmlClass, removeHtmlClass, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFocussed, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showWarningIndicators, tidyUpUIContextForTree, validate
-
-
-
-
Constructor Detail
-
WSubMenu
public WSubMenu(String text)
Creates a WSubMenu with the given text.- Parameters:
text
- the sub menu text.
-
WSubMenu
public WSubMenu(WDecoratedLabel label)
Creates a WSubMenu with the given text.- Parameters:
label
- the sub menu label.
-
WSubMenu
@Deprecated public WSubMenu(String text, char accessKey)
Deprecated.access keys are not implemented in menus. See https://www.w3.org/TR/wai-aria-practices/#keyboard-interaction-9 for information regarding key access to menus.Creates a WSubMenu with the given text. The accessKey arg is now ignored for a11y reasons.- Parameters:
text
- the sub menu textaccessKey
- the access key - not used
-
-
Method Detail
-
setMode
public void setMode(WSubMenu.MenuMode mode)
Sets the menu mode. See #687.- Parameters:
mode
- the menu mode.
-
getMode
public WSubMenu.MenuMode getMode()
- Returns:
- the menu mode.
-
isTopLevelMenu
public boolean isTopLevelMenu()
Indicates whether this is a top-level menu (ie. attached to a menu bar).- Returns:
true
if this is a top-level menu.
-
addSeparator
public void addSeparator()
Adds a separator to the sub-menu.
-
add
public void add(WSeparator item)
- Parameters:
item
- add aWSeparator
-
addMenuItemGroup
public void addMenuItemGroup(WMenuItemGroup menuItemGroup)
Deprecated.menu groups are not compatible with WCAG 2.0.Adds a menu item group to this sub menu.- Parameters:
menuItemGroup
- the menu item group to add.
-
add
public void add(WMenuItemGroup item)
- Parameters:
item
- add aWMenuItemGroup
-
addMenuItem
public void addMenuItem(MenuItem item)
- Specified by:
addMenuItem
in interfaceMenuContainer
- Parameters:
item
- the menu item to add
-
remove
@Deprecated public void remove(WComponent item)
Deprecated.
-
removeMenuItem
public void removeMenuItem(MenuItem item)
- Specified by:
removeMenuItem
in interfaceMenuContainer
- Parameters:
item
- the menu item to remove
-
removeAllMenuItems
public void removeAllMenuItems()
Remove all menu items.- Specified by:
removeAllMenuItems
in interfaceMenuContainer
-
getMenuItems
public List<MenuItem> getMenuItems()
- Specified by:
getMenuItems
in interfaceMenuContainer
- Returns:
- the items of this menu container
-
isDisabled
public boolean isDisabled()
Indicates whether this sub menu is disabled in the given context.- Specified by:
isDisabled
in interfaceDisableable
- Returns:
- true if this sub menu is disabled.
-
setDisabled
public void setDisabled(boolean disabled)
Sets whether this sub menu is disabled.- Specified by:
setDisabled
in interfaceDisableable
- Parameters:
disabled
- true to disable this sub menu, false to enable.
-
getAccessKey
public char getAccessKey()
- Specified by:
getAccessKey
in interfaceAccessKeyable
- Returns:
- the component's access key.
-
setAccessKey
public void setAccessKey(char accessKey)
Description copied from interface:AccessKeyable
Set the access key on the component.- Specified by:
setAccessKey
in interfaceAccessKeyable
- Parameters:
accessKey
- the key that will form a keyboard shortcut to the component.
-
getText
public String getText()
- Returns:
- the sub-menu text.
-
setText
public void setText(String text)
Sets the sub-menu text.- Parameters:
text
- the sub-menu text.
-
isSelectable
@Deprecated public Boolean isSelectable()
Deprecated.WSubMenu is never selectable for a11y reasons. If you need a selectable useWTree
.- Returns:
- true if this item is selectable, false if not, or null to default to the container.
-
setSelectable
@Deprecated public void setSelectable(Boolean selectable)
Deprecated.WSubMenu is never selectable for a11y reasons. If you need a selectable useWTree
.- Parameters:
selectable
- true if this item is selectable, false if not, or null to default to the container.
-
getSelectability
@Deprecated public final Boolean getSelectability()
Deprecated.WSubMenu is never selectable for a11y reasons. If you need a selectable useWTree
.Symmetric accessor which should not generally be used. If you need to know if an instance of MenuItemSelectable is selectable then it is better to useMenuItemSelectable.isSelectAllowed()
.- Specified by:
getSelectability
in interfaceMenuItemSelectable
- Returns:
- true if this item is selectable, false if not, or null if default to its container.
-
setSelectability
@Deprecated public final void setSelectability(Boolean selectability)
Deprecated.WSubMenu is never selectable for a11y reasons. If you need a selectable useWTree
.- Specified by:
setSelectability
in interfaceMenuItemSelectable
- Parameters:
selectability
- true if this item is selectable, false if not, or null to default to the container.
-
isSelectAllowed
public boolean isSelectAllowed()
- Specified by:
isSelectAllowed
in interfaceMenuItemSelectable
- Returns:
- always
false
for WSubMenu.
-
isMultipleSelection
@Deprecated public boolean isMultipleSelection()
Deprecated.- Returns:
- Returns the multipleSelection.
-
setMultipleSelection
@Deprecated public void setMultipleSelection(boolean multipleSelection)
Deprecated.- Parameters:
multipleSelection
- The multipleSelection to set.
-
getSelectMode
public WMenu.SelectMode getSelectMode()
Deprecated.UseMenuSelectContainer.getSelectionMode()
instead.- Returns:
- the selection mode of the container
-
setSelectMode
public void setSelectMode(WMenu.SelectMode selectMode)
Deprecated.UseMenuSelectContainer.setSelectionMode(SelectionMode)
instead.- Parameters:
selectMode
- the selection mode for the items in this menu container.
-
getSelectionMode
public MenuSelectContainer.SelectionMode getSelectionMode()
- Specified by:
getSelectionMode
in interfaceMenuSelectContainer
- Returns:
- the selection mode of the container
-
setSelectionMode
public void setSelectionMode(MenuSelectContainer.SelectionMode selectionMode)
- Specified by:
setSelectionMode
in interfaceMenuSelectContainer
- Parameters:
selectionMode
- the selection mode for the items in this menu container.
-
getAction
public Action getAction()
- Returns:
- the sub-menu's action, or null if there is no action specified.
-
setAction
public void setAction(Action action)
Sets the action to execute when the sub-menu is selected.- Parameters:
action
- the menu item's action.
-
getActionCommand
public String getActionCommand()
Retrieves this sub-menu's "default" action command.- Returns:
- the actionCommand.
-
setActionCommand
public void setActionCommand(String actionCommand)
Sets this sub-menu's action command.- Parameters:
actionCommand
- The actionCommand to set.
-
getActionObject
public Serializable getActionObject()
Retrieves this sub-menu's "default" action object.- Returns:
- the actionObject.
-
setActionObject
public void setActionObject(Serializable actionObject)
Sets this sub-menu's "default" action object.- Parameters:
actionObject
- The actionObject to set.
-
setOpen
public void setOpen(boolean open)
Sets whether this menu is open. Only has an effect for some menu types.- Parameters:
open
- true if the menu should be open, false for closed.
-
isOpen
public boolean isOpen()
Indicates whether this sub-menu is open in the given context.- Returns:
- true if this menu is open in the given context, false otherwise.
-
getDecoratedLabel
public WDecoratedLabel getDecoratedLabel()
- Returns:
- the sub menu's decorated label.
-
isSelected
@Deprecated public boolean isSelected()
Deprecated.WSubMenu is never selectable for a11y reasons. If you need a selectable see WTree.Indicates whether this sub-menu is selected (for menu types which support sub-menu selection).- Specified by:
isSelected
in interfaceMenuItemSelectable
- Returns:
- true if this sub-menu is selected, false otherwise.
-
handleRequest
public void handleRequest(Request request)
Override handleRequest in order to perform processing for this component. This implementation checks for submenu selection and executes the associated action if it has been set.- Specified by:
handleRequest
in interfaceWComponent
- Overrides:
handleRequest
in classAbstractWComponent
- Parameters:
request
- the request being responded to.
-
isMenuPresent
protected boolean isMenuPresent(Request request)
Determine if this WMenuItem's parent WMenu is on the Request.- Parameters:
request
- the request being responded to.- Returns:
- true if this WMenuItem's WMenu is on the Request, otherwise return false.
-
preparePaintComponent
protected void preparePaintComponent(Request request)
Override preparePaintComponent in order to correct the visibility of the sub-menu's children before they are rendered.- Overrides:
preparePaintComponent
in classAbstractWComponent
- Parameters:
request
- the request being responded to.
-
paintMenuItems
public void paintMenuItems(RenderContext renderContext)
Paint the menu items.- Parameters:
renderContext
- the render context
-
toString
public String toString()
Description copied from class:AbstractWComponent
Creates a String representation of this component; usually for debugging purposes.- Overrides:
toString
in classAbstractWComponent
- Returns:
- a String representation of this component, for debugging purposes.
-
newComponentModel
protected WSubMenu.SubMenuModel newComponentModel()
Creates a new component model.- Overrides:
newComponentModel
in classAbstractWComponent
- Returns:
- a new SubMenuModel.
-
getComponentModel
protected WSubMenu.SubMenuModel getComponentModel()
Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.- Overrides:
getComponentModel
in classAbstractWComponent
- Returns:
- the effective component model
-
getOrCreateComponentModel
protected WSubMenu.SubMenuModel getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.- Overrides:
getOrCreateComponentModel
in classAbstractWComponent
- Returns:
- the model for this component
-
-