Class CustomField<T>
- java.lang.Object
-
- com.vaadin.server.AbstractClientConnector
-
- com.vaadin.ui.AbstractComponent
-
- com.vaadin.ui.AbstractField<T>
-
- com.vaadin.ui.CustomField<T>
-
- Type Parameters:
T- field value type
- All Implemented Interfaces:
Buffered,BufferedValidatable,Property<T>,Property.Editor,Property.ReadOnlyStatusChangeListener,Property.ReadOnlyStatusChangeNotifier,Property.ValueChangeListener,Property.ValueChangeNotifier,Property.Viewer,Validatable,Action.ShortcutNotifier,ContextClickEvent.ContextClickNotifier,MethodEventSource,ClientConnector,Sizeable,Connector,Component,Component.Focusable,Field<T>,HasComponents,Serializable,Iterable<Component>
public abstract class CustomField<T> extends AbstractField<T> implements HasComponents
AFieldwhose UI content can be constructed by the user, enabling the creation of e.g. form fields by composing Vaadin components. Customization of both the visual presentation and the logic of the field is possible. Subclasses must implementAbstractField.getType()andinitContent(). Most custom fields can simply compose a user interface that calls the methodsAbstractField.setInternalValue(Object)andAbstractField.getInternalValue()when necessary. It is also possible to overrideAbstractField.validate(),AbstractField.setInternalValue(Object),AbstractField.commit(),AbstractField.setPropertyDataSource(Property),AbstractField.isEmpty()and other logic of the field. Methods overridingAbstractField.setInternalValue(Object)should also call the corresponding superclass method.- Since:
- 7.0
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractField
AbstractField.FocusShortcut, AbstractField.ReadOnlyStatusChangeEvent
-
Nested classes/interfaces inherited from interface com.vaadin.data.Buffered
Buffered.SourceException
-
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.ui.Field
Field.ValueChangeEvent
-
Nested classes/interfaces inherited from interface com.vaadin.ui.HasComponents
HasComponents.ComponentAttachDetachNotifier, HasComponents.ComponentAttachEvent, HasComponents.ComponentAttachListener, HasComponents.ComponentDetachEvent, HasComponents.ComponentDetachListener
-
Nested classes/interfaces inherited from interface com.vaadin.data.Property
Property.Editor, Property.ReadOnlyException, Property.ReadOnlyStatusChangeListener, Property.ReadOnlyStatusChangeNotifier, Property.Transactional<T>, Property.ValueChangeListener, Property.ValueChangeNotifier, Property.Viewer
-
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
-
-
Constructor Summary
Constructors Constructor Description CustomField()Constructs a new custom field.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidattach()Constructs the content and notifies it that theCustomFieldis attached to a window.voidfocus()Sets the focus for this component if the component isComponent.Focusable.protected ComponentgetContent()Returns the content (UI) of the custom component.intgetTabIndex()Gets the tabulator index of theFocusablecomponent.protected abstract ComponentinitContent()Create the content component or layout for the field.Iterator<Component>iterator()Gets an iterator to the collection of contained components.voidsetFocusDelegate(Component.Focusable focusDelegate)Sets the component to which all methods from theComponent.Focusableinterface should be delegated.voidsetHeight(float height, Sizeable.Unit unit)Sets the height of the object.voidsetTabIndex(int tabIndex)Sets the tabulator index of theFocusablecomponent.voidsetWidth(float width, Sizeable.Unit unit)Sets the width of the object.-
Methods inherited from class com.vaadin.ui.AbstractField
addListener, addListener, addReadOnlyStatusChangeListener, addValidator, addValueChangeListener, beforeClientResponse, clear, commit, detach, discard, fireReadOnlyStatusChange, fireValueChange, getConversionError, getConversionError, getConvertedValue, getConverter, getCurrentBufferedSourceException, getCustomAttributes, getErrorMessage, getInternalValue, getModelType, getPropertyDataSource, getRequiredError, getState, getState, getType, getValidators, getValue, isBuffered, isEmpty, isImmediate, isInvalidAllowed, isInvalidCommitted, isModified, isReadOnly, isRequired, isValid, isValidationVisible, readDesign, readOnlyStatusChange, removeAllValidators, removeListener, removeListener, removeReadOnlyStatusChangeListener, removeValidator, removeValueChangeListener, setBuffered, setConversionError, setConvertedValue, setConverter, setConverter, setCurrentBufferedSourceException, setInternalValue, setInvalidAllowed, setInvalidCommitted, setLocale, setPropertyDataSource, setReadOnly, setRequired, setRequiredError, setValidationVisible, setValue, setValue, setValue, shouldHideErrors, toString, validate, validate, valueChange, writeDesign
-
Methods inherited from class com.vaadin.ui.AbstractComponent
addContextClickListener, addListener, addShortcutListener, addStyleName, findAncestor, fireComponentErrorEvent, fireComponentEvent, getActionManager, getCaption, getComponentError, getData, getDebugId, getDescription, getExplicitImmediateValue, 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, setEnabled, setHeight, setHeightUndefined, setIcon, setId, setImmediate, setParent, setPrimaryStyleName, setResponsive, setSizeFull, setSizeUndefined, setStyleName, setStyleName, setVisible, setWidth, setWidthUndefined
-
Methods inherited from class com.vaadin.server.AbstractClientConnector
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
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, 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, getCaption, getDescription, getIcon, getId, getLocale, getParent, getPrimaryStyleName, getStyleName, getUI, isEnabled, isReadOnly, isVisible, readDesign, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setId, setParent, setPrimaryStyleName, setReadOnly, setStyleName, setVisible, writeDesign
-
Methods inherited from interface com.vaadin.shared.Connector
getConnectorId
-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Methods inherited from interface com.vaadin.server.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeightUndefined, setSizeFull, setSizeUndefined, setWidth, setWidthUndefined
-
-
-
-
Method Detail
-
attach
public void attach()
Constructs the content and notifies it that theCustomFieldis attached to a window.- Specified by:
attachin interfaceClientConnector- Specified by:
attachin interfaceComponent- Overrides:
attachin classAbstractField<T>- See Also:
Component.attach()
-
getContent
protected Component getContent()
Returns the content (UI) of the custom component.- Returns:
- Component
-
initContent
protected abstract Component initContent()
Create the content component or layout for the field. Subclasses ofCustomFieldshould implement this method. Note that this method is called when the CustomField is attached to a layout or whengetContent()is called explicitly for the first time. It is only called once for aCustomField.- Returns:
Componentrepresenting the UI of the CustomField
-
setHeight
public void setHeight(float height, Sizeable.Unit unit)Description copied from interface:SizeableSets the height of the object. Negative number implies unspecified size (terminal is free to set the size).- Specified by:
setHeightin interfaceSizeable- Overrides:
setHeightin classAbstractComponent- Parameters:
height- the height of the object.unit- the unit used for the width.
-
setWidth
public void setWidth(float width, Sizeable.Unit unit)Description copied from interface:SizeableSets the width of the object. Negative number implies unspecified size (terminal is free to set the size).- Specified by:
setWidthin interfaceSizeable- Overrides:
setWidthin classAbstractComponent- Parameters:
width- the width of the object.unit- the unit used for the width.
-
iterator
public Iterator<Component> iterator()
Description copied from interface:HasComponentsGets an iterator to the collection of contained components. Using this iterator it is possible to step through all components contained in this container.- Specified by:
iteratorin interfaceHasComponents- Specified by:
iteratorin interfaceIterable<T>- Returns:
- the component iterator.
-
setFocusDelegate
public void setFocusDelegate(Component.Focusable focusDelegate)
Sets the component to which all methods from theComponent.Focusableinterface should be delegated.Set this to a wrapped field to include that field in the tabbing order, to make it receive focus when
focus()is called and to make it be correctly focused when used as a Grid editor component.By default,
Component.Focusableevents are handled by the super class and ultimately ignored.- Parameters:
focusDelegate- the focusable component to which focus events are redirected
-
focus
public void focus()
Description copied from class:AbstractFieldSets the focus for this component if the component isComponent.Focusable.- Specified by:
focusin interfaceComponent.Focusable- Overrides:
focusin classAbstractField<T>- See Also:
FieldEvents,FieldEvents.FocusEvent,FieldEvents.FocusListener,FieldEvents.BlurEvent,FieldEvents.BlurListener
-
getTabIndex
public int getTabIndex()
Description copied from interface:Component.FocusableGets the tabulator index of theFocusablecomponent.- Specified by:
getTabIndexin interfaceComponent.Focusable- Overrides:
getTabIndexin classAbstractField<T>- Returns:
- tab index set for the
Focusablecomponent - See Also:
Component.Focusable.setTabIndex(int)
-
setTabIndex
public void setTabIndex(int tabIndex)
Description copied from interface:Component.FocusableSets the tabulator index of theFocusablecomponent. The tab index property is used to specify the order in which the fields are focused when the user presses the Tab key. Components with a defined tab index are focused sequentially first, and then the components with no tab index.Form loginBox = new Form(); loginBox.setCaption("Login"); layout.addComponent(loginBox); // Create the first field which will be focused TextField username = new TextField("User name"); loginBox.addField("username", username); // Set focus to the user name username.focus(); TextField password = new TextField("Password"); loginBox.addField("password", password); Button login = new Button("Login"); loginBox.getFooter().addComponent(login); // An additional component which natural focus order would // be after the button. CheckBox remember = new CheckBox("Remember me"); loginBox.getFooter().addComponent(remember); username.setTabIndex(1); password.setTabIndex(2); remember.setTabIndex(3); // Different than natural place login.setTabIndex(4);After all focusable user interface components are done, the browser can begin again from the component with the smallest tab index, or it can take the focus out of the page, for example, to the location bar.
If the tab index is not set (is set to zero), the default tab order is used. The order is somewhat browser-dependent, but generally follows the HTML structure of the page.
A negative value means that the component is completely removed from the tabulation order and can not be reached by pressing the Tab key at all.
- Specified by:
setTabIndexin interfaceComponent.Focusable- Overrides:
setTabIndexin classAbstractField<T>- Parameters:
tabIndex- the tab order of this component. Indexes usually start from 1. Zero means that default tab order should be used. A negative value means that the field should not be included in the tabbing sequence.- See Also:
Component.Focusable.getTabIndex()
-
-