public class CheckBox extends AbstractField<Boolean> implements FieldEvents.BlurNotifier, FieldEvents.FocusNotifier
HasValue.ValueChangeEvent<V>, HasValue.ValueChangeListener<V>
Component.ErrorEvent, Component.Event, Component.Focusable, Component.Listener
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.ConnectorErrorEvent, ClientConnector.DetachEvent, ClientConnector.DetachListener
Sizeable.Unit
DESIGN_ATTR_PLAIN_TEXT
SIZE_UNDEFINED, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
Constructor and Description |
---|
CheckBox()
Creates a new checkbox.
|
CheckBox(String caption)
Creates a new checkbox with a set caption.
|
CheckBox(String caption,
boolean initialState)
Creates a new checkbox with a caption and a set initial state.
|
Modifier and Type | Method and Description |
---|---|
Registration |
addBlurListener(FieldEvents.BlurListener listener)
Adds a
BlurListener to the Component which gets fired
when a Field loses keyboard focus. |
Registration |
addFocusListener(FieldEvents.FocusListener listener)
Adds a
FocusListener to the Component which gets fired
when a Field 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)
and AbstractComponent.writeDesign(Element, DesignContext) methods. |
Boolean |
getEmptyValue()
Returns the value that represents an empty value.
|
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.
|
addValueChangeListener, createValueChange, focus, getTabIndex, isDifferentValue, isReadOnly, isRequiredIndicatorVisible, setReadOnly, setRequiredIndicatorVisible, setTabIndex
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, setHeightUndefined, setIcon, setId, setLocale, setParent, setPrimaryStyleName, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setStyleName, setVisible, setWidth, setWidth, setWidthUndefined
addAttachListener, addDetachListener, addExtension, 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, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler, setResource, updateDiffstate
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
clear, getDefaultValidator, getOptionalValue, isEmpty
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, setVisible
addAttachListener, addDetachListener, beforeClientResponse, detach, encodeState, getErrorHandler, getExtensions, getRpcManager, getStateType, handleConnectorRequest, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, removeAttachListener, removeDetachListener, removeExtension, requestRepaint, requestRepaintAll, retrievePendingRpcCalls, setErrorHandler
getConnectorId
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidthUndefined
public CheckBox()
public CheckBox(String caption)
caption
- the Checkbox caption.public CheckBox(String caption, boolean initialState)
caption
- the caption of the checkboxinitialState
- the initial state of the checkboxpublic Boolean getValue()
HasValue
Implementation note: the implementing class should document whether null values may be returned or not.
public void setValue(Boolean value)
getValue()
, fires a ValueChangeEvent
. Throws
NullPointerException
if the value is null.setValue
in interface HasValue<Boolean>
setValue
in class AbstractField<Boolean>
value
- the new value, not null
NullPointerException
- if value
is null
protected boolean setValue(Boolean value, boolean userOriginated)
getValue()
, fires a ValueChangeEvent
. Throws
NullPointerException
if the value is null.setValue
in class AbstractField<Boolean>
value
- the new value, not null
userOriginated
- true
if this event originates from the client,
false
otherwise.true
if the value was updated, false
otherwiseNullPointerException
- if value
is null
public Boolean getEmptyValue()
HasValue
By default HasValue
is expected to support null
as empty
values. Specific implementations might not support this.
getEmptyValue
in interface HasValue<Boolean>
Binder#bind(HasValue, ValueProvider, Setter)
protected CheckBoxState getState()
AbstractComponent
getState
in class AbstractField<Boolean>
protected CheckBoxState getState(boolean markAsDirty)
AbstractClientConnector
getState
in class AbstractField<Boolean>
markAsDirty
- true if the connector should automatically be marked dirty,
false otherwiseAbstractClientConnector.getState()
protected void doSetValue(Boolean value)
AbstractField
IllegalArgumentException
if the value is invalid. Typically saves
the value to shared state.doSetValue
in class AbstractField<Boolean>
value
- the new value of the fieldpublic Registration addBlurListener(FieldEvents.BlurListener listener)
FieldEvents.BlurNotifier
BlurListener
to the Component which gets fired
when a Field
loses keyboard focus.addBlurListener
in interface FieldEvents.BlurNotifier
listener
- the blur listener to add, not nullFieldEvents.BlurListener
,
Registration
public Registration addFocusListener(FieldEvents.FocusListener listener)
FieldEvents.FocusNotifier
FocusListener
to the Component which gets fired
when a Field
receives keyboard focus.addFocusListener
in interface FieldEvents.FocusNotifier
listener
- the focus listener to add, not nullFieldEvents.FocusListener
,
Registration
public void readDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Component
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.
readDesign
in interface Component
readDesign
in class AbstractField<Boolean>
design
- The element to obtain the state fromdesignContext
- The DesignContext instance used for parsing the designprotected Collection<String> getCustomAttributes()
AbstractComponent
AbstractComponent.readDesign(Element, DesignContext)
and AbstractComponent.writeDesign(Element, DesignContext)
methods. Typically these
are handled in a custom way in the overridden versions of the above
methodsgetCustomAttributes
in class AbstractField<Boolean>
public void writeDesign(org.jsoup.nodes.Element design, DesignContext designContext)
Component
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.
writeDesign
in interface Component
writeDesign
in class AbstractField<Boolean>
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 designCopyright © 2018 Vaadin Ltd. All rights reserved.