com.vaadin.ui.
Class Button
-
All Implemented Interfaces:
Action.ShortcutNotifier
,ContextClickEvent.ContextClickNotifier
,FieldEvents.BlurNotifier
,FieldEvents.FocusNotifier
,MethodEventSource
,ClientConnector
,Sizeable
,Connector
,Component
,Component.Focusable
,Serializable
Direct Known Subclasses:
public class Button extends AbstractFocusable implements Action.ShortcutNotifier
A generic button component.
Since:
3.0
Author:
Vaadin Ltd.
See Also:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
Button.ClickEvent
Click event.
static interface
Button.ClickListener
Interface for listening for a
Button.ClickEvent
fired by aComponent
.static class
Button.ClickShortcut
A
ShortcutListener
specifically made to define a keyboard shortcut that invokes a click on the given button.-
Nested classes/interfaces inherited from interface com.vaadin.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
-
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
-
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
Sizeable.Unit
-
-
Field Summary
Fields Modifier and Type Field Description protected Button.ClickShortcut
clickShortcut
-
Fields inherited from class com.vaadin.ui.AbstractComponent
DESIGN_ATTR_PLAIN_TEXT
-
Fields inherited from interface com.vaadin.server.Sizeable
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
-
-
Constructor Summary
Constructors Constructor Description Button()
Creates a new push button.
Button(Resource icon)
Creates a new push button with the given icon.
Button(Resource icon, Button.ClickListener listener)
Creates a new push button with a click listener.
Button(String caption)
Creates a new push button with the given caption.
Button(String caption, Resource icon)
Creates a new push button with the given caption and icon.
Button(String caption, Button.ClickListener listener)
Creates a new push button with a click listener.
-
Method Summary
All Methods Modifier and Type Method Description Registration
addClickListener(Button.ClickListener listener)
Adds the button click listener.
void
click()
Simulates a button click, notifying all server-side listeners.
protected void
fireClick()
Fires a click event to all listeners without any event details.
protected void
fireClick(MouseEventDetails details)
Fires a click event to all listeners.
protected Collection<String>
getCustomAttributes()
Returns a collection of attributes that should not be handled by the basic implementation of the
AbstractComponent.readDesign(Element, DesignContext)
andAbstractComponent.writeDesign(Element, DesignContext)
methods.String
getIconAlternateText()
Returns the icon's alt text.
protected ButtonState
getState()
Returns the shared state bean with information to be sent from the server to the client.
protected ButtonState
getState(boolean markAsDirty)
Returns the shared state for this connector.
boolean
isDisableOnClick()
Determines if a button is automatically disabled when clicked.
boolean
isHtmlContentAllowed()
Deprecated.
as of 8.0.0, useAbstractComponent.isCaptionAsHtml()
instead.void
readDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Reads the component state from the given design.
void
removeClickListener(Button.ClickListener listener)
Deprecated.
As of 8.0, replaced byRegistration.remove()
in the registration object returned fromaddClickListener(ClickListener)
.void
removeClickShortcut()
Removes the keyboard shortcut previously set with
setClickShortcut(int, int...)
.void
setClickShortcut(int keyCode, int... modifiers)
Makes it possible to invoke a click on this button by pressing the given
ShortcutAction.KeyCode
and (optional)ShortcutAction.ModifierKey
s.
The shortcut is global (bound to the containing Window).void
setDisableOnClick(boolean disableOnClick)
Determines if a button is automatically disabled when clicked.
void
setHtmlContentAllowed(boolean htmlContentAllowed)
Deprecated.
as of 8.0.0, useAbstractComponent.setCaptionAsHtml(boolean)
instead.void
setIcon(Resource icon, String iconAltText)
Sets the component's icon and alt text.
void
setIconAlternateText(String iconAltText)
void
writeDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Writes the component state to the given design.
-
Methods inherited from class com.vaadin.ui.AbstractFocusable
addBlurListener, addFocusListener, focus, getTabIndex, setTabIndex
-
Methods inherited from class com.vaadin.ui.AbstractComponent
addContextClickListener, addListener, addShortcutListener, addStyleName, attach, beforeClientResponse, detach, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorMessage, getHeight, getHeightUnits, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getWidth, getWidthUnits, isCaptionAsHtml, isConnectorEnabled, isEnabled, isOrHasAncestor, isReadOnly, isRequiredIndicatorVisible, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setDescription, setEnabled, setHeight, setHeight, setHeightFull, setHeightUndefined, setIcon, setId, setLocale, setParent, setPrimaryStyleName, setReadOnly, setRequiredIndicatorVisible, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setVisible, setWidth, setWidth, setWidthFull, setWidthUndefined
-
Methods inherited from class com.vaadin.server.AbstractClientConnector
addAttachListener, addDetachListener, addExtension, addListener, addListener, addListener, addListener, addListener, addListener, addMethodInvocationToQueue, createState, encodeState, equals, fireEvent, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getListeners, getResource, getRpcManager, getRpcProxy, getSession, getStateType, getUI, handleConnectorRequest, hashCode, hasListeners, isAttached, isThis, markAsDirty, markAsDirtyRecursive, registerRpc, registerRpc, removeAttachListener, removeDetachListener, removeExtension, removeListener, removeListener, removeListener, removeListener, removeListener, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.vaadin.event.Action.ShortcutNotifier
addShortcutListener, removeShortcutListener
-
Methods inherited from interface com.vaadin.server.ClientConnector
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
-
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, addStyleNames, attach, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isVisible, removeListener, removeStyleName, removeStyleNames, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setStyleName, setStyleName, setVisible
-
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
-
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightFull, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull, setWidthUndefined
-
-
-
-
Field Detail
-
clickShortcut
protected Button.ClickShortcut clickShortcut
-
-
Constructor Detail
-
Button
public Button()
Creates a new push button.
-
Button
public Button(String caption)
Creates a new push button with the given caption.
Parameters:
caption
- the Button caption.
-
Button
public Button(Resource icon)
Creates a new push button with the given icon.
Parameters:
icon
- the icon
-
Button
public Button(String caption, Resource icon)
Creates a new push button with the given caption and icon.
Parameters:
caption
- the captionicon
- the icon
-
Button
public Button(String caption, Button.ClickListener listener)
Creates a new push button with a click listener.
Parameters:
caption
- the Button caption.listener
- the Button click listener.
-
Button
public Button(Resource icon, Button.ClickListener listener)
Creates a new push button with a click listener.
Parameters:
icon
- the Button icon.listener
- the Button click listener.Since:
8.2
-
-
Method Detail
-
addClickListener
public Registration addClickListener(Button.ClickListener listener)
Adds the button click listener.
Parameters:
listener
- the Listener to be added.Returns:
a registration object for removing the listener
Since:
8.0
See Also:
-
removeClickListener
@Deprecated public void removeClickListener(Button.ClickListener listener)
Deprecated.As of 8.0, replaced byRegistration.remove()
in the registration object returned fromaddClickListener(ClickListener)
.Removes the button click listener.
Parameters:
listener
- the Listener to be removed.
-
click
public void click()
Simulates a button click, notifying all server-side listeners.
No action is taken if the button is disabled.
-
fireClick
protected void fireClick()
Fires a click event to all listeners without any event details.
In subclasses, override
fireClick(MouseEventDetails)
instead of this method.
-
fireClick
protected void fireClick(MouseEventDetails details)
Fires a click event to all listeners.
Parameters:
details
- MouseEventDetails from which keyboard modifiers and other information about the mouse click can be obtained. If the button was clicked by a keyboard event, some of the fields may be empty/undefined.
-
setClickShortcut
public void setClickShortcut(int keyCode, int... modifiers)
Makes it possible to invoke a click on this button by pressing the given
ShortcutAction.KeyCode
and (optional)ShortcutAction.ModifierKey
s.
The shortcut is global (bound to the containing Window).Parameters:
keyCode
- the keycode for invoking the shortcutmodifiers
- the (optional) modifiers for invoking the shortcut, null for none
-
removeClickShortcut
public void removeClickShortcut()
Removes the keyboard shortcut previously set with
setClickShortcut(int, int...)
.
-
isDisableOnClick
public boolean isDisableOnClick()
Determines if a button is automatically disabled when clicked. See
setDisableOnClick(boolean)
for details.Returns:
true if the button is disabled when clicked, false otherwise
-
setDisableOnClick
public void setDisableOnClick(boolean disableOnClick)
Determines if a button is automatically disabled when clicked. If this is set to true the button will be automatically disabled when clicked, typically to prevent (accidental) extra clicks on a button.
Note that this is only used when the click comes from the user, not when calling
click()
method programmatically. Also, if developer wants to re-enable the button, it needs to be done programmatically.Parameters:
disableOnClick
- true to disable button when it is clicked, false otherwise
-
getState
protected ButtonState getState()
Description copied from class:
AbstractComponent
Returns the shared state bean with information to be sent from the server to the client. Subclasses should override this method and set any relevant fields of the state returned by super.getState().
Overrides:
getState
in classAbstractFocusable
Returns:
updated component shared state
-
getState
protected ButtonState getState(boolean markAsDirty)
Description copied from class:
AbstractClientConnector
Returns the shared state for this connector.
Overrides:
getState
in classAbstractFocusable
Parameters:
markAsDirty
- true if the connector should automatically be marked dirty, false otherwiseReturns:
The shared state for this connector. Never null.
See Also:
-
setIcon
public void setIcon(Resource icon, String iconAltText)
Sets the component's icon and alt text.
An alt text is shown when an image could not be loaded, and read by assistive devices.
Parameters:
icon
- the icon to be shown with the component's caption.iconAltText
- String to use as alt text
-
getIconAlternateText
public String getIconAlternateText()
Returns the icon's alt text.
Returns:
String with the alt text
-
setIconAlternateText
public void setIconAlternateText(String iconAltText)
-
setHtmlContentAllowed
@Deprecated public void setHtmlContentAllowed(boolean htmlContentAllowed)
Deprecated.as of 8.0.0, useAbstractComponent.setCaptionAsHtml(boolean)
instead.Set whether the caption text is rendered as HTML or not. You might need to re-theme button to allow higher content than the original text style. If set to true, the captions are passed to the browser as html and the developer is responsible for ensuring no harmful html is used. If set to false, the content is passed to the browser as plain text.
Parameters:
htmlContentAllowed
-true
if caption is rendered as HTML,false
otherwise
-
isHtmlContentAllowed
@Deprecated public boolean isHtmlContentAllowed()
Deprecated.as of 8.0.0, useAbstractComponent.isCaptionAsHtml()
instead.Return HTML rendering setting.
Returns:
true
if the caption text is to be rendered as HTML,false
otherwise
-
readDesign
public void readDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Description copied from interface:
Component
Reads the component state from the given design.
The component is responsible not only for updating its own state but also for ensuring that its children update their state based on the design.
It is assumed that the component is in its default state when this method is called. Reading should only take into consideration attributes specified in the design and not reset any unspecified attributes to their defaults.
This method must not modify the design.
Specified by:
readDesign
in interfaceComponent
Overrides:
readDesign
in classAbstractComponent
Parameters:
design
- The element to obtain the state fromdesignContext
- The DesignContext instance used for parsing the design
-
getCustomAttributes
protected Collection<String> getCustomAttributes()
Description copied from class:
AbstractComponent
Returns a collection of attributes that should not be handled by the basic implementation of the
AbstractComponent.readDesign(Element, DesignContext)
andAbstractComponent.writeDesign(Element, DesignContext)
methods. Typically these are handled in a custom way in the overridden versions of the above methodsOverrides:
getCustomAttributes
in classAbstractComponent
Returns:
the collection of attributes that are not handled by the basic implementation
-
writeDesign
public void writeDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Description copied from interface:
Component
Writes the component state to the given design.
The component is responsible not only for writing its own state but also for ensuring that its children write their state to the design.
This method must not modify the component state.
Specified by:
writeDesign
in interfaceComponent
Overrides:
writeDesign
in classAbstractComponent
Parameters:
design
- The element to write the component state to. Any previous attributes or child nodes are not cleared.designContext
- The DesignContext instance used for writing the design
-
-