Class AbstractComponent
- All Implemented Interfaces:
ClientConnector,Sizeable,com.vaadin.flow.component.AttachNotifier,com.vaadin.flow.component.DetachNotifier,com.vaadin.flow.component.HasElement,com.vaadin.flow.component.HasEnabled,com.vaadin.flow.component.HasStyle,Serializable
- Direct Known Subclasses:
AbstractComponentContainer,AbstractSingleComponentContainer,Label
Component interface in
framework 8.- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.vaadin.classic.v8.server.ClientConnector
ClientConnector.AttachEvent, ClientConnector.AttachListener, ClientConnector.DetachEvent, ClientConnector.DetachListenerNested classes/interfaces inherited from interface com.vaadin.classic.v8.server.Sizeable
Sizeable.Unit -
Field Summary
Fields inherited from interface com.vaadin.classic.v8.server.Sizeable
SIZE_UNDEFINED -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddInternalStyles(String... internalStyles) Adds given style names as "internal" which means that those will not be prefixed with the primary style name like user added style names are.com.vaadin.flow.shared.RegistrationaddListener(Listener listener) Registers a new (generic) component event listener for the component.com.vaadin.flow.shared.RegistrationaddShortcutListener(ShortcutListener shortcut) Deprecated.voidaddStyleName(String style) Adds one or more style names to the classic component.voidaddStyleNames(String... styles) Adds one or more style names to this classic component by using one or multiple parameters.voidbeforeClientResponse(boolean initial) Called before the response is written to client side.protected voiddoSetHeight(SizeWithUnit height) Internal method for reacting to height changes.protected voiddoSetWidth(SizeWithUnit width) Internal method for reacting to width changes.protected voidDeprecated.protected voidEmits the component event.protected voidfocus()Sets the focus for this component if the component isFocusable.protected ActionManagerDeprecated.Deprecated.Deprecated.protected Collection<String>Deprecated.protected Collection<String>Returns the user added custom style names in an unmodifiable collection.getData()Gets the application specific data.Deprecated.Deprecated.floatGets the height of the object.Gets the height property units.getIcon()Deprecated.protected Collection<String>Returns the internal styles in an unmodifiable collection.Gets the locale of the component.Gets the primary style name of the classic component.protected AbstractComponentStategetState()Deprecated.protected AbstractComponentStategetState(boolean markAsDirty) Deprecated.Gets all user-defined CSS style names of a classic component.floatgetWidth()Gets the width of the object.Gets the width property units.booleanDeprecated.booleanTests whether the component is enabled or not.protected booleanisOrHasAncestor(com.vaadin.flow.component.Component content) Determine whether acontentcomponent is equal to, or the ancestor of this component.protected booleanDeprecated.protected booleanDeprecated.booleanDeprecated.booleanGets the component visibility value.protected voidThis method is executed when a style name is added or removed, mainly used to mark the parent as dirty.voidonEnabledStateChanged(boolean enabled) protected voidremoveInternalStyles(String... internalStyles) Removes the given internal styles.voidremoveStyleName(String style) Removes one or more style names from the classic component.voidremoveStyleNames(String... styles) Removes one or more style names from the classic component.voidsetCaption(String caption) Deprecated.voidsetCaptionAsHtml(boolean captionAsHtml) Deprecated.voidsetComponentError(ErrorMessage componentError) Deprecated.voidSets the data object, that can be used for any application specific data.voidsetDescription(String description) Deprecated.voidsetDescription(String description, ContentMode mode) Deprecated.voidsetEnabled(boolean enabled) Enables or disables the component.voidsetHeight(float height, Sizeable.Unit unit) Sets the height of the object.voidSets the height of the component using String presentation.voidSets the height to 100%.voidClears any defined height.voidDeprecated.voidSets the locale of this component.voidsetParent(HasComponents parent) Sets the parent classic component of the component.voidsetPrimaryStyleName(String style) Changes the primary style name of the classic component.protected voidsetReadOnly(boolean readOnly) Deprecated.protected voidsetRequiredIndicatorVisible(boolean visible) Deprecated.voidsetResponsive(boolean responsive) Deprecated.voidSets the size to 100% x 100%.voidClears any size settings.voidsetStyleName(String style) Sets one or more user-defined style names of the classic component, replacing any previous user-defined styles.voidsetStyleName(String style, boolean add) Adds or removes a style name.voidsetVisible(boolean visible) Sets the component visibility value.voidsetWidth(float width, Sizeable.Unit unit) Sets the width of the object.voidSets the width of the component using String presentation.voidSets the width to 100%.voidClears any defined width.Methods inherited from class com.vaadin.classic.v8.server.AbstractClientConnector
addExtension, addLegacyAttachListener, addLegacyDetachListener, addListener, addListener, addMethodInvocationToQueue, attach, createState, detach, getAllChildrenIterable, getConnectorId, getErrorHandler, getExtensions, getResource, getSession, handleConnectorRequest, hasListeners, isAttached, isConnectorEnabled, markAsDirty, markAsDirtyRecursive, onAttach, onDetach, registerRpc, registerRpc, removeExtension, setErrorHandler, setResource, updateDiffstateMethods inherited from class com.vaadin.flow.component.Component
addListener, findAncestor, fireEvent, from, get, getChildren, getElement, getEventBus, getId, getListeners, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isTemplateMapped, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setIdMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface com.vaadin.flow.component.AttachNotifier
addAttachListenerMethods inherited from interface com.vaadin.flow.component.DetachNotifier
addDetachListenerMethods inherited from interface com.vaadin.flow.component.HasElement
getElementMethods inherited from interface com.vaadin.flow.component.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Constructor Details
-
AbstractComponent
public AbstractComponent()
-
-
Method Details
-
beforeClientResponse
public void beforeClientResponse(boolean initial) Description copied from interface:ClientConnectorCalled before the response is written to client side. Gives the legacy connector an opportunity to set computed/dynamic state values.This is implemented for the legacy components to keep consistent behavior and e.g. legaze size calculations working.
NOTE: the parameter
initialisfalsewhen the component is attached again to a newUIwhenPreserveOnRefreshis used.- Specified by:
beforeClientResponsein interfaceClientConnector- Overrides:
beforeClientResponsein classAbstractClientConnector- Parameters:
initial-trueif the client-side connector will be created and initialized after this method has been invoked.falseif there is already an initialized client-side connector.
-
setParent
Sets the parent classic component of the component. The role of this method is to just make sure the old parent is flagged as dirty so that changes are applied (e.g. to sizing).- Parameters:
parent- the parent connector- Throws:
IllegalStateException- if a parent is given even though the connector already has a parent
-
fireComponentEvent
protected void fireComponentEvent()Emits the component event. It is transmitted to all registered listeners interested in such events. -
focus
protected void focus()Sets the focus for this component if the component isFocusable. NOTE: the focus is not set until the component is attached. -
isOrHasAncestor
protected boolean isOrHasAncestor(com.vaadin.flow.component.Component content) Determine whether acontentcomponent is equal to, or the ancestor of this component.- Parameters:
content- the potential ancestor element- Returns:
trueif the relationship holds
-
setWidth
Description copied from interface:SizeableSets the width of the component using String presentation.String presentation is similar to what is used in Cascading Style Sheets. Size can be length or percentage of available size.
The empty string ("") or null will unset the width and set the units to pixels.
See CSS specification for more details.
-
setWidth
Description copied from interface:SizeableSets the width of the object. Negative number implies unspecified size (terminal is free to set the size). -
getWidth
public float getWidth()Description copied from interface:SizeableGets the width of the object. Negative number implies unspecified size (terminal is free to set the size). -
getWidthUnits
Description copied from interface:SizeableGets the width property units.- Specified by:
getWidthUnitsin interfaceSizeable- Returns:
- units used in width property.
-
setHeight
Description copied from interface:SizeableSets the height of the component using String presentation.String presentation is similar to what is used in Cascading Style Sheets. Size can be length or percentage of available size.
The empty string ("") or null will unset the height and set the units to pixels.
See CSS specification for more details.
-
setHeight
Description copied from interface:SizeableSets the height of the object. Negative number implies unspecified size (terminal is free to set the size). -
getHeight
public float getHeight()Description copied from interface:SizeableGets the height of the object. Negative number implies unspecified size (terminal is free to set the size). -
getHeightUnits
Description copied from interface:SizeableGets the height property units.- Specified by:
getHeightUnitsin interfaceSizeable- Returns:
- units used in height property.
-
setSizeFull
public void setSizeFull()Description copied from interface:SizeableSets the size to 100% x 100%.- Specified by:
setSizeFullin interfaceSizeable
-
setWidthFull
public void setWidthFull()Description copied from interface:SizeableSets the width to 100%.- Specified by:
setWidthFullin interfaceSizeable
-
setHeightFull
public void setHeightFull()Description copied from interface:SizeableSets the height to 100%.- Specified by:
setHeightFullin interfaceSizeable
-
setSizeUndefined
public void setSizeUndefined()Description copied from interface:SizeableClears any size settings.- Specified by:
setSizeUndefinedin interfaceSizeable
-
setWidthUndefined
public void setWidthUndefined()Description copied from interface:SizeableClears any defined width.- Specified by:
setWidthUndefinedin interfaceSizeable
-
setHeightUndefined
public void setHeightUndefined()Description copied from interface:SizeableClears any defined height.- Specified by:
setHeightUndefinedin interfaceSizeable
-
doSetWidth
Internal method for reacting to width changes.- Parameters:
width- the changed width to set
-
doSetHeight
Internal method for reacting to height changes.- Parameters:
height- the changed height to set
-
getStyleName
Gets all user-defined CSS style names of a classic component. If the component has multiple style names defined, the return string is a space-separated list of style names. Built-in style names defined in Vaadin or GWT are not returned.The style names are returned only in the basic form in which they were added; each user-defined style name shows as two CSS style class names in the rendered HTML: one as it was given and one prefixed with the component-specific style name. Only the former is returned.
- Returns:
- the style name or a space-separated list of user-defined style names of the component
- See Also:
-
setStyleName
Sets one or more user-defined style names of the classic component, replacing any previous user-defined styles. Multiple styles can be specified as a space-separated list of style names. The style names must be valid CSS class names and should not conflict with any built-in style names in Vaadin or GWT.Label label = new Label("This text has a lot of style"); label.setStyleName("myonestyle myotherstyle");Each style name will occur in two versions: one as specified and one that is prefixed with the style name of the component. For example, if you have a
Labelcomponent and give it "mystyle" style, the component will have both "mystyle" and "v-label-mystyle" styles. You could then style the component either with:.mystyle {background: blue;}or
.v-label-mystyle {background: blue;}It is normally a good practice to use
addStyleName()rather than this setter, as different software abstraction layers can then add their own styles without accidentally removing those defined in other layers.- Parameters:
style- the new style or styles of the component as a space-separated list- See Also:
-
setStyleName
Adds or removes a style name. Multiple styles can be specified as a space-separated list of style names.If the
addparameter is true, the style name is added to the component. If theaddparameter is false, the style name is removed from the component.Functionally this is equivalent to using
addStyleName(String)orremoveStyleName(String)- Parameters:
style- the style name to be added or removedadd-trueto add the given style,falseto remove it- See Also:
-
addStyleName
Adds one or more style names to the classic component. Multiple styles can be specified as a space-separated list of style names. The style name will be rendered as a HTML class name, which can be used in a CSS definition.Label label = new Label("This text has style"); label.addStyleName("mystyle");Each style name will occur in two versions: one as specified and one that is prefixed with the style name of the component. For example, if you have a
Labelcomponent and give it "mystyle" style, the component will have both "mystyle" and "v-label-mystyle" styles. You could then style the component either with:.mystyle {font-style: italic;}or
.v-label-mystyle {font-style: italic;}- Parameters:
style- the new style to be added to the component- See Also:
-
addStyleNames
Adds one or more style names to this classic component by using one or multiple parameters.- Parameters:
styles- the style name or style names to be added to the component- See Also:
-
removeStyleName
Removes one or more style names from the classic component. Multiple styles can be specified as a space-separated list of style names.The parameter must be a valid CSS style name. Only user-defined style names added with
addStyleName()orsetStyleName()can be removed; built-in style names defined in Vaadin or GWT can not be removed.- Parameters:
style- the style name or style names to be removed- See Also:
-
removeStyleNames
Removes one or more style names from the classic component. Multiple styles can be specified by using multiple parameters.- Parameters:
styles- the style name or style names to be removed- See Also:
-
getPrimaryStyleName
Gets the primary style name of the classic component. SeesetPrimaryStyleName(String)for a better description of the primary stylename. -
setPrimaryStyleName
Changes the primary style name of the classic component.The primary style name identifies the component when applying the CSS theme to the Component. By changing the style name all CSS rules targeted for that style name will no longer apply, and might result in the component not working as intended.
- Parameters:
style- The new primary style name
-
notifyParentAboutStyleChanges
protected void notifyParentAboutStyleChanges()This method is executed when a style name is added or removed, mainly used to mark the parent as dirty. The default implementation marks the parent as dirty if it's an AbstractOrderedLayout. -
addInternalStyles
Adds given style names as "internal" which means that those will not be prefixed with the primary style name like user added style names are. In legacy framework these were handled by the client side connectors/widgets.- Parameters:
internalStyles- internal styles to add, notnull
-
removeInternalStyles
Removes the given internal styles.- Parameters:
internalStyles- the internal styles to remove
-
getInternalStyles
Returns the internal styles in an unmodifiable collection.- Returns:
- the internal styles of the component
- See Also:
-
getCustomStyles
Returns the user added custom style names in an unmodifiable collection.- Returns:
- the user added custom style names
-
addListener
Registers a new (generic) component event listener for the component.class Listening extends CustomComponent implements Listener { // Stored for determining the source of an event Button ok; Label status; // For displaying info about the event public Listening() { VerticalLayout layout = new VerticalLayout(); // Some miscellaneous component TextField name = new TextField("Say it all here"); name.addListener(this); layout.addComponent(name); // Handle button clicks as generic events instead // of Button.ClickEvent events ok = new Button("OK"); ok.addListener(this); layout.addComponent(ok); // For displaying information about an event status = new Label(""); layout.addComponent(status); setCompositionRoot(layout); } public void componentEvent(Event event) { // Act according to the source of the event if (event.getSource() == ok) getWindow().showNotification("Click!"); status.setValue( "Event from " + event.getSource().getClass().getName() + ": " + event.getClass().getName()); } } Listening listening = new Listening(); layout.addComponent(listening);- Parameters:
listener- the new Listener to be registered.- Returns:
- a registration object for removing this listener
- See Also:
-
EventRegistration
-
onEnabledStateChanged
public void onEnabledStateChanged(boolean enabled) - Overrides:
onEnabledStateChangedin classcom.vaadin.flow.component.Component
-
isEnabled
public boolean isEnabled()Tests whether the component is enabled or not. A user can not interact with disabled components. Disabled components are rendered in a style that indicates the status, usually in gray color. Children of a disabled component are also disabled. Components are enabled by default.As a security feature, all updates for disabled components are blocked on the server-side.
Note that this method only returns the status of the component and does not take parents into account. Even though this method returns true the component can be disabled to the user if a parent is disabled.
- Specified by:
isEnabledin interfacecom.vaadin.flow.component.HasEnabled- Returns:
trueif the component and its parent are enabled,falseotherwise.
-
setEnabled
public void setEnabled(boolean enabled) Enables or disables the component. The user can not interact with disabled components, which are shown with a style that indicates the status, usually shaded in light gray color. Components are enabled by default.Button enabled = new Button("Enabled"); enabled.setEnabled(true); // The default layout.addComponent(enabled); Button disabled = new Button("Disabled"); disabled.setEnabled(false); layout.addComponent(disabled);- Specified by:
setEnabledin interfacecom.vaadin.flow.component.HasEnabled- Parameters:
enabled- a boolean value specifying if the component should be enabled or not
-
setData
Sets the data object, that can be used for any application specific data. The component does not use or modify this data.- Parameters:
data- the Application specific data.
-
getData
Gets the application specific data. SeesetData(Object).- Returns:
- the Application specific data set with setData function.
-
setLocale
Sets the locale of this component.// Component for which the locale is meaningful InlineDateField date = new InlineDateField("Datum"); // German language specified with ISO 639-1 language // code and ISO 3166-1 alpha-2 country code. date.setLocale(new Locale("de", "DE")); date.setResolution(DateField.RESOLUTION_DAY); layout.addComponent(date);- Parameters:
locale- the locale to become this component's locale.
-
getLocale
Gets the locale of the component.If a component does not have a locale set, the locale of its parent is returned, and so on. Eventually, if no parent has locale set, the locale of the application is returned. If the application does not have a locale set, it is determined by
Locale.getDefault().As the component must be attached before its locale can be acquired, using this method in the internationalization of component captions, etc. is generally not feasible. For such use case, we recommend using an otherwise acquired reference to the application locale.
- Overrides:
getLocalein classcom.vaadin.flow.component.Component- Returns:
- Locale of this component or
nullif the component and none of its parents has a locale set and the component is not yet attached to an application.
-
isVisible
public boolean isVisible()Gets the component visibility value.Note: Although semantically the same, unlike Vaadin framework version 7/8 when a component is not visible, it is not removed from the DOM.
- Overrides:
isVisiblein classcom.vaadin.flow.component.Component- Returns:
trueif the component is visible,falseotherwise- See Also:
-
setVisible
public void setVisible(boolean visible) Sets the component visibility value.When a component is set as invisible, all the updates of the component from the server to the client are blocked until the component is set as visible again.
Invisible components don't receive any updates from the client-side. Unlike the server-side updates, client-side updates, if any, are discarded while the component is invisible, and are not transmitted to the server when the component is made visible.
Note: Although semantically the same, unlike Vaadin framework version 7/8 when a component is not visible, it is not removed from the DOM.
- Overrides:
setVisiblein classcom.vaadin.flow.component.Component- Parameters:
visible- the component visibility value- See Also:
-
addShortcutListener
@Deprecated public com.vaadin.flow.shared.Registration addShortcutListener(ShortcutListener shortcut) Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Returns:
- fake registration
-
getIcon
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Returns:
- fake resource
-
fireComponentErrorEvent
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options. -
getActionManager
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Returns:
- fake action manager
-
getCaption
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Returns:
- empty string
-
getComponentError
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Returns:
- fake error message
-
getCustomAttributes
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Returns:
- empty collection
-
getDescription
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Returns:
- empty string
-
getErrorMessage
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Returns:
- fake error message
-
getState
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Overrides:
getStatein classAbstractClientConnector- Returns:
- fake shared state
-
getState
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Overrides:
getStatein classAbstractClientConnector- Parameters:
markAsDirty- mark as dirty- Returns:
- fake shared state
-
isCaptionAsHtml
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Returns:
- false
-
isReadOnly
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Returns:
- false
-
isRequiredIndicatorVisible
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Returns:
- false
-
isResponsive
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Returns:
- false
-
setCaption
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Parameters:
caption- caption
-
setCaptionAsHtml
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Parameters:
captionAsHtml- caption as html
-
setComponentError
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Parameters:
componentError- component error
-
setDescription
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Parameters:
description- description
-
setIcon
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Parameters:
icon- icon
-
setReadOnly
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Parameters:
readOnly- read only
-
setRequiredIndicatorVisible
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Parameters:
visible- visible
-
setResponsive
Deprecated.Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.- Parameters:
responsive- responsive
-