Class WMenuItem
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.AbstractContainer
-
- com.github.bordertech.wcomponents.WMenuItem
-
- All Implemented Interfaces:
AccessKeyable
,AjaxTrigger
,Container
,DialogOpenTrigger
,Disableable
,MenuItem
,MenuItemSelectable
,WComponent
,WebComponent
,Serializable
public class WMenuItem extends AbstractContainer implements Disableable, AjaxTrigger, MenuItemSelectable, DialogOpenTrigger, AccessKeyable
This component provides a menu item for use either directly in the top level of aWMenu
or as an item within aWSubMenu
orWMenuItemGroup
.- 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
WMenuItem.MenuItemModel
Holds the extrinsic state information of a WMenuItem.-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractWComponent
AbstractWComponent.WComponentRef
-
-
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 WMenuItem(WDecoratedLabel label)
Creates a WMenuItem with the given label.WMenuItem(WDecoratedLabel label, Action action)
Creates a WMenuItem with the given label and action.WMenuItem(WDecoratedLabel label, String url)
Creates a WMenuItem with the given label and url.WMenuItem(String text)
Creates a new WMenuItem with the specified text.WMenuItem(String text, char accessKey)
Creates a new WMenuItem with the specified text and accessKey.WMenuItem(String text, char accessKey, Action action)
Creates a new WMenuItem with the specified text, accessKey and action.WMenuItem(String text, Action action)
Creates a WMenuItem with the given label and action.WMenuItem(String text, String url)
Creates a WMenuItem with the given text and url.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description char
getAccessKey()
Action
getAction()
String
getActionCommand()
Retrieves this menu item's action command.Serializable
getActionObject()
Retrieves this menu item's action object.protected WMenuItem.MenuItemModel
getComponentModel()
Returns the effective component model for this component.WDecoratedLabel
getDecoratedLabel()
String
getMessage()
protected WMenuItem.MenuItemModel
getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified.Boolean
getSelectability()
Symmetric accessor which should not generally be used.String
getTargetWindow()
Retrieves the target window name.String
getText()
Retrieves the menu item text.String
getUrl()
Retrieves the menu item's URL.void
handleRequest(Request request)
Override handleRequest in order to perform processing for this component.boolean
isCancel()
boolean
isDisabled()
Indicates whether this menu item is disabled in the given context.protected boolean
isMenuPresent(Request request)
Determine if this WMenuItem's parent WMenu is on the Request.Boolean
isSelectable()
Deprecated.UsegetSelectability()
instead.boolean
isSelectAllowed()
boolean
isSelected()
boolean
isSubmit()
Indicates whether the form should be submitted when the menu item is selected.boolean
isTopLevelItem()
protected WMenuItem.MenuItemModel
newComponentModel()
Creates a new component model.void
setAccessKey(char accessKey)
Set the access key on the component.void
setAction(Action action)
Sets the action to execute when the menu item is invoked.void
setActionCommand(String actionCommand)
Sets this menu item's action command.void
setActionObject(Serializable actionObject)
Sets this menu item's action object.void
setCancel(boolean cancel)
void
setDisabled(boolean disabled)
Sets whether this menu item is disabled.void
setMessage(String message, Serializable... args)
Sets the confirmation message that is to be displayed to the user for this menu item.void
setSelectability(Boolean selectability)
void
setSelectable(Boolean selectable)
Deprecated.UsesetSelectability(java.lang.Boolean)
instead.void
setTargetWindow(String targetWindow)
Sets this menu item's target window name.void
setText(String text)
Sets the text of the menu item.void
setUrl(String url)
Sets the URL to navigate to when the menu item is invoked.String
toString()
Creates a String representation of this component; usually for debugging purposes.-
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, 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, 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.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
-
WMenuItem
public WMenuItem(WDecoratedLabel label)
Creates a WMenuItem with the given label.- Parameters:
label
- the menu item label.
-
WMenuItem
public WMenuItem(WDecoratedLabel label, String url)
Creates a WMenuItem with the given label and url.- Parameters:
label
- the menu item label.url
- the URL to navigate to when the menu item is invoked.
-
WMenuItem
public WMenuItem(WDecoratedLabel label, Action action)
Creates a WMenuItem with the given label and action.- Parameters:
label
- the menu item label.action
- the action to execute when the menu item is invoked.
-
WMenuItem
public WMenuItem(String text, String url)
Creates a WMenuItem with the given text and url.- Parameters:
text
- the menu item text.url
- the URL to navigate to when the menu item is invoked.
-
WMenuItem
public WMenuItem(String text, Action action)
Creates a WMenuItem with the given label and action.- Parameters:
text
- the menu item text.action
- the action to execute when the menu item is invoked.
-
WMenuItem
public WMenuItem(String text)
Creates a new WMenuItem with the specified text.- Parameters:
text
- the menu item's text.
-
WMenuItem
public WMenuItem(String text, char accessKey)
Creates a new WMenuItem with the specified text and accessKey.- Parameters:
text
- the menu item's text.accessKey
- the menu item's access key.
-
-
Method Detail
-
getDecoratedLabel
public WDecoratedLabel getDecoratedLabel()
- Returns:
- the decorated label which displays the menu item's text/icon etc.
-
getAction
public Action getAction()
- Returns:
- the menu item's action, or null if there is no action specified.
-
setAction
public void setAction(Action action)
Sets the action to execute when the menu item is invoked.- Parameters:
action
- the menu item's action.
-
getUrl
public String getUrl()
Retrieves the menu item's URL.- Returns:
- the menu item's url, or null if there is no url specified.
-
setUrl
public void setUrl(String url)
Sets the URL to navigate to when the menu item is invoked.- Parameters:
url
- the url to set.
-
isSubmit
public boolean isSubmit()
Indicates whether the form should be submitted when the menu item is selected. By default, the form will only be submitted if an action has been set on this item.
Examples of where the form might should not be submitted include if the menu item is within a sub-menu which supports multiple selection, or if the menu item points at an external URL.
- Returns:
- true if the form should be submitted when the menu item is selected.
-
getText
public String getText()
Retrieves the menu item text.- Returns:
- the menu item text
-
setText
public void setText(String text)
Sets the text of the menu item.- Parameters:
text
- the text to set.
-
getTargetWindow
public String getTargetWindow()
Retrieves the target window name.- Returns:
- the target window name.
-
setTargetWindow
public void setTargetWindow(String targetWindow)
Sets this menu item's target window name.- Parameters:
targetWindow
- the target window name.
-
isSelectable
@Deprecated public Boolean isSelectable()
Deprecated.UsegetSelectability()
instead.- 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.UsesetSelectability(java.lang.Boolean)
instead.- Parameters:
selectable
- true if this item is selectable, false if not, or null to default to the container.
-
isSelected
public boolean isSelected()
- Specified by:
isSelected
in interfaceMenuItemSelectable
- Returns:
- true if selected, otherwise false
-
getSelectability
public Boolean getSelectability()
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
public void setSelectability(Boolean selectability)
- Specified by:
setSelectability
in interfaceMenuItemSelectable
- Parameters:
selectability
- true if this item is selectable, false if not, or null to default to the container.
-
isDisabled
public boolean isDisabled()
Indicates whether this menu item is disabled in the given context.- Specified by:
isDisabled
in interfaceDisableable
- Returns:
- true if this menu item is disabled, false if it is enabled.
-
isSelectAllowed
public boolean isSelectAllowed()
- Specified by:
isSelectAllowed
in interfaceMenuItemSelectable
- Returns:
true
if a WMenuItem is allowed to have a selection state. This is determined by its nearest ancestorMenuSelectContainer
's selectionMode.
-
setDisabled
public void setDisabled(boolean disabled)
Sets whether this menu item is disabled.- Specified by:
setDisabled
in interfaceDisableable
- Parameters:
disabled
- true to set the item disabled, false for enabled.
-
isTopLevelItem
public final boolean isTopLevelItem()
- Returns:
true
if the WMenuItem is either an immediate child of a WMenu or an immediate child of a WMenuItemGroup which is itself an immediate child of a WMenu.
-
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.
-
getActionCommand
public String getActionCommand()
Retrieves this menu item's action command.- Returns:
- the actionCommand.
-
setActionCommand
public void setActionCommand(String actionCommand)
Sets this menu item's action command.- Parameters:
actionCommand
- The actionCommand to set.
-
getActionObject
public Serializable getActionObject()
Retrieves this menu item's action object.- Returns:
- the actionObject.
-
setActionObject
public void setActionObject(Serializable actionObject)
Sets this menu item's action object.- Parameters:
actionObject
- The actionObject to set.
-
getMessage
public String getMessage()
- Returns:
- the confirmation message for the menu item.
-
setMessage
public void setMessage(String message, Serializable... args)
Sets the confirmation message that is to be displayed to the user for this menu item.- Parameters:
message
- the confirmation message to display, usingMessageFormat
syntax.args
- optional arguments for the message format string.
-
isCancel
public boolean isCancel()
- Returns:
- true if menu item is a cancel control and will warn the user of unsaved changes, otherwise false
-
setCancel
public void setCancel(boolean cancel)
- Parameters:
cancel
- true if menu item is a cancel control and will warn the user of unsaved changes, otherwise false
-
handleRequest
public void handleRequest(Request request)
Override handleRequest in order to perform processing for this component. This implementation checks for selection of the menu item, 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.
-
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 WMenuItem.MenuItemModel newComponentModel()
Creates a new component model.- Overrides:
newComponentModel
in classAbstractWComponent
- Returns:
- a new MenuItemModel.
-
getComponentModel
protected WMenuItem.MenuItemModel 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 WMenuItem.MenuItemModel 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
-
-