com.vaadin.ui.
Class CheckBox
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.ui.AbstractComponent
-
- com.vaadin.ui.AbstractField<Boolean>
-
- com.vaadin.ui.CheckBox
-
All Implemented Interfaces:
HasValue<Boolean>
,ContextClickEvent.ContextClickNotifier
,FieldEvents.BlurNotifier
,FieldEvents.FocusNotifier
,MethodEventSource
,ClientConnector
,Sizeable
,Connector
,Component
,Component.Focusable
,Serializable
public class CheckBox extends AbstractField<Boolean> implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier
See Also:
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CheckBox.CheckBoxInputElement
The inner input element of the CheckBox.
static class
CheckBox.CheckBoxLabelElement
The inner label element of the CheckBox.
-
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.data.HasValue
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<V>
-
Nested classes/interfaces inherited from interface com.vaadin.server.Sizeable
Sizeable.Unit
-
-
Field Summary
-
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
-
-
Method Summary
All Methods Modifier and Type Method Description Registration
addBlurListener(FieldEvents.BlurListener listener)
Adds a
BlurListener
to the Component which gets fired when aField
loses keyboard focus.Registration
addFocusListener(FieldEvents.FocusListener listener)
Adds a
FocusListener
to the Component which gets fired when aField
receives keyboard focus.protected void
doSetValue(Boolean value)
Sets the value of this field.
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.Boolean
getEmptyValue()
Returns the value that represents an empty value.
CheckBox.CheckBoxInputElement
getInputElement()
Returns the
CheckBox.CheckBoxInputElement
element to manipulate the style name of theinput
element of theCheckBox
.CheckBox.CheckBoxLabelElement
getLabelElement()
Returns the
CheckBox.CheckBoxLabelElement
element to manipulate the style name of thelabel
element of theCheckBox
.protected CheckBoxState
getState()
Returns the shared state bean with information to be sent from the server to the client.
protected CheckBoxState
getState(boolean markAsDirty)
Returns the shared state for this connector.
Boolean
getValue()
Returns the current value of this object.
void
readDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Reads the component state from the given design.
void
setValue(Boolean value)
Sets the value of this CheckBox.
protected boolean
setValue(Boolean value, boolean userOriginated)
Sets the value of this CheckBox.
void
writeDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Writes the component state to the given design.
-
Methods inherited from class com.vaadin.ui.AbstractField
addValueChangeListener, createValueChange, focus, getTabIndex, isDifferentValue, isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible, 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, isResponsive, isVisible, removeContextClickListener, removeListener, removeShortcutListener, removeStyleName, setCaption, setCaptionAsHtml, setComponentError, setData, setDebugId, setDescription, setDescription, setEnabled, setHeight, setHeight, setHeightFull, setHeightUndefined, setIcon, setId, setLocale, setParent, setPrimaryStyleName, 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.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.data.HasValue
clear, getDefaultValidator, getOptionalValue, isEmpty
-
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightFull, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthFull, setWidthUndefined
-
-
-
-
Constructor Detail
-
CheckBox
public CheckBox()
Creates a new checkbox.
-
CheckBox
public CheckBox(String caption)
Creates a new checkbox with a set caption.
Parameters:
caption
- the Checkbox caption.
-
CheckBox
public CheckBox(String caption, boolean initialState)
Creates a new checkbox with a caption and a set initial state.
Parameters:
caption
- the caption of the checkboxinitialState
- the initial state of the checkbox
-
-
Method Detail
-
getValue
public Boolean getValue()
Description copied from interface:
HasValue
Returns the current value of this object.
Implementation note: the implementing class should document whether null values may be returned or not.
-
setValue
public void setValue(Boolean value)
Sets the value of this CheckBox. If the new value is not equal to
getValue()
, fires aHasValue.ValueChangeEvent
. ThrowsNullPointerException
if the value is null.Specified by:
setValue
in interfaceHasValue<Boolean>
Overrides:
setValue
in classAbstractField<Boolean>
Parameters:
value
- the new value, notnull
Throws:
NullPointerException
- ifvalue
isnull
-
setValue
protected boolean setValue(Boolean value, boolean userOriginated)
Sets the value of this CheckBox. If the new value is not equal to
getValue()
, fires aHasValue.ValueChangeEvent
. ThrowsNullPointerException
if the value is null.Overrides:
setValue
in classAbstractField<Boolean>
Parameters:
value
- the new value, notnull
userOriginated
-true
if this event originates from the client,false
otherwise.Returns:
true
if the value was updated,false
otherwiseThrows:
NullPointerException
- ifvalue
isnull
-
getEmptyValue
public Boolean getEmptyValue()
Description copied from interface:
HasValue
Returns the value that represents an empty value.
By default
HasValue
is expected to supportnull
as empty values. Specific implementations might not support this.Specified by:
getEmptyValue
in interfaceHasValue<Boolean>
Returns:
empty value
See Also:
-
getState
protected CheckBoxState 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 classAbstractField<Boolean>
Returns:
updated component shared state
-
getState
protected CheckBoxState getState(boolean markAsDirty)
Description copied from class:
AbstractClientConnector
Returns the shared state for this connector.
Overrides:
getState
in classAbstractField<Boolean>
Parameters:
markAsDirty
- true if the connector should automatically be marked dirty, false otherwiseReturns:
The shared state for this connector. Never null.
See Also:
-
doSetValue
protected void doSetValue(Boolean value)
Description copied from class:
AbstractField
Sets the value of this field. May do sanitization or throw
IllegalArgumentException
if the value is invalid. Typically saves the value to shared state.Specified by:
doSetValue
in classAbstractField<Boolean>
Parameters:
value
- the new value of the field
-
addBlurListener
public Registration addBlurListener(FieldEvents.BlurListener listener)
Description copied from interface:
FieldEvents.BlurNotifier
Adds a
BlurListener
to the Component which gets fired when aField
loses keyboard focus.Specified by:
addBlurListener
in interfaceFieldEvents.BlurNotifier
Parameters:
listener
- the blur listener to add, not nullReturns:
a registration object for removing the listener
See Also:
-
addFocusListener
public Registration addFocusListener(FieldEvents.FocusListener listener)
Description copied from interface:
FieldEvents.FocusNotifier
Adds a
FocusListener
to the Component which gets fired when aField
receives keyboard focus.Specified by:
addFocusListener
in interfaceFieldEvents.FocusNotifier
Parameters:
listener
- the focus listener to add, not nullReturns:
a registration object for removing the listener
See Also:
-
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 classAbstractField<Boolean>
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 classAbstractField<Boolean>
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 classAbstractField<Boolean>
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
-
getInputElement
public CheckBox.CheckBoxInputElement getInputElement()
Returns the
CheckBox.CheckBoxInputElement
element to manipulate the style name of theinput
element of theCheckBox
.Returns:
the current
CheckBox.CheckBoxInputElement
, notnull
.Since:
8.7
-
getLabelElement
public CheckBox.CheckBoxLabelElement getLabelElement()
Returns the
CheckBox.CheckBoxLabelElement
element to manipulate the style name of thelabel
element of theCheckBox
.Returns:
the current
CheckBox.CheckBoxLabelElement
, notnull
.Since:
8.7
-
-