Class WMenu
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.AbstractContainer
-
- com.github.bordertech.wcomponents.AbstractNamingContextContainer
-
- com.github.bordertech.wcomponents.WMenu
-
- All Implemented Interfaces:
AjaxTarget
,Container
,Disableable
,Marginable
,MenuContainer
,MenuSelectContainer
,NamingContextable
,WComponent
,WebComponent
,Serializable
public class WMenu extends AbstractNamingContextContainer implements Disableable, AjaxTarget, Marginable, MenuSelectContainer
This component enables rendering of a menuing system for an application. A menu bar consists of a collection of either "Menu Items" (see
WMenuItem
or "Sub Menus" (seeWSubMenu
).- Since:
- 1.0.0
- Author:
- Adam Millard, Yiannis Paschalidis, Jonathan Austin
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WMenu.MenuModel
Holds the state information for a WMenu.static class
WMenu.MenuType
The available types of client-side menus.static class
WMenu.SelectMode
Deprecated.UseMenuSelectContainer.getSelectionMode()
instead.-
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
-
-
Constructor Summary
Constructors Constructor Description WMenu()
Creates a WMenu which is displayed as a menu bar.WMenu(WMenu.MenuType type)
Creates a WMenu of the given type.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
add(WMenuItem item)
void
add(WMenuItemGroup item)
Deprecated.menu groups are not compatible with WCAG 2.0.void
add(WSeparator item)
void
add(WSubMenu item)
void
addMenuItem(MenuItem item)
void
addSeparator()
Adds a separator to the end of the menu.protected void
afterPaint(RenderContext renderContext)
Subclasses may override this method to output content after the component has been painted.void
clearSelectedItems()
Deprecated.UseclearSelectedMenuItems()
instead.void
clearSelectedMenuItems()
Clears an existing list of selected items.protected WMenu.MenuModel
getComponentModel()
Returns the effective component model for this component.Margin
getMargin()
Get the margin for the component, or null if not set.List<MenuItem>
getMenuItems()
List<MenuItem>
getMenuItems(boolean recurse)
protected WMenu.MenuModel
getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified.int
getRows()
Deprecated.No longer supported, no Java alternative.WComponent
getSelectedItem()
Deprecated.UsegetSelectedMenuItem()
instead.List<WComponent>
getSelectedItems()
Deprecated.UsegetSelectedMenuItems()
instead.MenuItemSelectable
getSelectedMenuItem()
Returns the selected item (WMenUItem/WSubMenu, depending on the menu type) in the given context.List<MenuItemSelectable>
getSelectedMenuItems()
Returns the selected items (WMenUItems/WSubMenus, depending on the menu type) in the given context.MenuSelectContainer.SelectionMode
getSelectionMode()
WMenu.SelectMode
getSelectMode()
Deprecated.UsegetSelectionMode()
instead.WMenu.MenuType
getType()
void
handleRequest(Request request)
Override handleRequest in order to perform processing specific to WMenu.boolean
isDisabled()
Indicates whether this menu is disabled.protected boolean
isPresent(Request request)
Determine if this WMenu is on the Request.protected WMenu.MenuModel
newComponentModel()
Creates a new component model.void
remove(WComponent item)
Deprecated.void
removeAllMenuItems()
Remove all menu items.void
removeMenuItem(MenuItem item)
void
setDisabled(boolean disabled)
Sets whether this menu is disabled.void
setMargin(Margin margin)
Set the margin for the component, or null for no margin.void
setRows(int rows)
Deprecated.No longer supported, no Java alternative.void
setSelectedItem(WComponent selectedItem)
Deprecated.void
setSelectedItems(List<WComponent> selectedItems)
Deprecated.UsesetSelectedMenuItems(java.util.List)
instead.void
setSelectedMenuItem(MenuItemSelectable selectedItem)
Sets the selected item (WMenuItem and/or WSubMenu, depending on the menu type).void
setSelectedMenuItems(List<? extends MenuItemSelectable> selectedItems)
Sets the selected items (WMenuItems or WSubMenus, depending on the menu type).void
setSelectionMode(MenuSelectContainer.SelectionMode selectionMode)
void
setSelectMode(WMenu.SelectMode selectMode)
Deprecated.-
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, 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, preparePaintComponent, 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, toString, 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.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
-
WMenu
public WMenu()
Creates a WMenu which is displayed as a menu bar.
-
WMenu
public WMenu(WMenu.MenuType type)
Creates a WMenu of the given type.- Parameters:
type
- the type of WMenu to create.
-
-
Method Detail
-
getType
public WMenu.MenuType getType()
- Returns:
- the menu type.
-
getRows
public int getRows()
Deprecated.No longer supported, no Java alternative. If this is required use application level CSS.- Returns:
- the number of rows to display for a column menu.
-
setRows
public void setRows(int rows)
Deprecated.No longer supported, no Java alternative. If this is required use application level CSS.Sets the number of rows to display for a column menu.- Parameters:
rows
- The rows to set.
-
getMargin
public Margin getMargin()
Get the margin for the component, or null if not set.- Specified by:
getMargin
in interfaceMarginable
- Returns:
- the margin for the component, or null if not set
-
setMargin
public void setMargin(Margin margin)
Set the margin for the component, or null for no margin.- Specified by:
setMargin
in interfaceMarginable
- Parameters:
margin
- the margin for the component
-
getSelectMode
@Deprecated public WMenu.SelectMode getSelectMode()
Deprecated.UsegetSelectionMode()
instead.- Returns:
- the selection mode of the container
-
setSelectMode
@Deprecated public void setSelectMode(WMenu.SelectMode selectMode)
Deprecated.- 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.
-
isDisabled
public boolean isDisabled()
Indicates whether this menu is disabled.- Specified by:
isDisabled
in interfaceDisableable
- Returns:
- true if this menu is disabled.
-
setDisabled
public void setDisabled(boolean disabled)
Sets whether this menu is disabled.- Specified by:
setDisabled
in interfaceDisableable
- Parameters:
disabled
- if true, the menu will be disabled.
-
addSeparator
public void addSeparator()
Adds a separator to the end of the menu.
-
add
public void add(WSeparator item)
- Parameters:
item
- add aWSeparator
-
add
@Deprecated public void add(WMenuItemGroup item)
Deprecated.menu groups are not compatible with WCAG 2.0.- 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
-
getMenuItems
public List<MenuItem> getMenuItems(boolean recurse)
- Parameters:
recurse
- true if recurse into child items that are menu containers (ie group items and submenus).- Returns:
- the list of menu items
-
getSelectedItem
@Deprecated public WComponent getSelectedItem()
Deprecated.UsegetSelectedMenuItem()
instead.Returns the selected item (WMenUItem/WSubMenu, depending on the menu type) in the given context.- Returns:
- the selected item, or null if no item has been selected.
-
setSelectedItem
@Deprecated public void setSelectedItem(WComponent selectedItem)
Deprecated.Sets the selected item (WMenuItem and/or WSubMenu, depending on the menu type).- Parameters:
selectedItem
- the selected item.
-
getSelectedItems
@Deprecated public List<WComponent> getSelectedItems()
Deprecated.UsegetSelectedMenuItems()
instead.Returns the selected items (WMenUItems/WSubMenus, depending on the menu type) in the given context.- Returns:
- the selected items, or an empty list if nothing is selected.
-
setSelectedItems
@Deprecated public void setSelectedItems(List<WComponent> selectedItems)
Deprecated.UsesetSelectedMenuItems(java.util.List)
instead.Sets the selected items (WMenuItems or WSubMenus, depending on the menu type).- Parameters:
selectedItems
- the selected items.
-
clearSelectedItems
@Deprecated public void clearSelectedItems()
Deprecated.UseclearSelectedMenuItems()
instead.Clears an existing list of selected items.
-
getSelectedMenuItem
public MenuItemSelectable getSelectedMenuItem()
Returns the selected item (WMenUItem/WSubMenu, depending on the menu type) in the given context.- Returns:
- the selected item, or null if no item has been selected.
-
setSelectedMenuItem
public void setSelectedMenuItem(MenuItemSelectable selectedItem)
Sets the selected item (WMenuItem and/or WSubMenu, depending on the menu type).- Parameters:
selectedItem
- the selected item.
-
getSelectedMenuItems
public List<MenuItemSelectable> getSelectedMenuItems()
Returns the selected items (WMenUItems/WSubMenus, depending on the menu type) in the given context.- Returns:
- the selected items, or an empty list if nothing is selected.
-
setSelectedMenuItems
public void setSelectedMenuItems(List<? extends MenuItemSelectable> selectedItems)
Sets the selected items (WMenuItems or WSubMenus, depending on the menu type).- Parameters:
selectedItems
- the selected items.
-
clearSelectedMenuItems
public void clearSelectedMenuItems()
Clears an existing list of selected items.
-
handleRequest
public void handleRequest(Request request)
Override handleRequest in order to perform processing specific to WMenu.- Specified by:
handleRequest
in interfaceWComponent
- Overrides:
handleRequest
in classAbstractWComponent
- Parameters:
request
- the request being handled.
-
afterPaint
protected void afterPaint(RenderContext renderContext)
Subclasses may override this method to output content after the component has been painted. When overriding this method, it is good practice to call the superclass implementation before emitting any additional content.- Overrides:
afterPaint
in classAbstractWComponent
- Parameters:
renderContext
- the context to render to.
-
isPresent
protected boolean isPresent(Request request)
Determine if this WMenu is on the Request.- Parameters:
request
- the request being responded to.- Returns:
- true if this WMenu is on the Request, otherwise return false.
-
newComponentModel
protected WMenu.MenuModel newComponentModel()
Creates a new component model.- Overrides:
newComponentModel
in classAbstractWComponent
- Returns:
- a new MenuModel.
-
getComponentModel
protected WMenu.MenuModel 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 WMenu.MenuModel 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
-
-