Class AbstractComponent

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.featurepack.server.AbstractClientConnector
com.vaadin.featurepack.ui.AbstractComponent
All Implemented Interfaces:
ClientConnector, FAbstractClientConnector, FSizeable, Sizeable, FAbstractComponent, com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.HasLabel, com.vaadin.flow.component.HasStyle, com.vaadin.flow.component.shared.HasTooltip, Serializable
Direct Known Subclasses:
AbstractComponentContainer, AbstractSingleComponentContainer, Label

public abstract class AbstractComponent extends AbstractClientConnector implements Sizeable, com.vaadin.flow.component.HasEnabled, com.vaadin.flow.component.shared.HasTooltip, com.vaadin.flow.component.HasLabel, FAbstractComponent
An abstract base class for most legacy components. In addition to its own legacy API, introduces the API from the legacy Component interface in framework 8.
See Also:
  • Constructor Details

    • AbstractComponent

      public AbstractComponent()
  • Method Details

    • beforeClientResponse

      public void beforeClientResponse(boolean initial)
      Description copied from interface: ClientConnector
      Called 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 initial is false when the component is attached again to a new UI when PreserveOnRefresh is used.

      Specified by:
      beforeClientResponse in interface ClientConnector
      Specified by:
      beforeClientResponse in interface FAbstractClientConnector
      Specified by:
      beforeClientResponse in interface FAbstractComponent
      Parameters:
      initial - true if the client-side connector will be created and initialized after this method has been invoked. false if there is already an initialized client-side connector.
    • setParent

      public void setParent(HasComponents parent)
      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 is Focusable. NOTE: the focus is not set until the component is attached.
    • isOrHasAncestor

      protected boolean isOrHasAncestor(com.vaadin.flow.component.Component content)
      Determine whether a content component is equal to, or the ancestor of this component.
      Parameters:
      content - the potential ancestor element
      Returns:
      true if the relationship holds
    • setWidth

      public void setWidth(float width, com.vaadin.flow.component.Unit unit)
      Description copied from interface: Sizeable
      Sets the width of the object. Negative number implies unspecified size (terminal is free to set the size).
      Specified by:
      setWidth in interface FSizeable
      Specified by:
      setWidth in interface Sizeable
      Parameters:
      width - the width of the object.
      unit - the unit used for the width.
    • setHeight

      public void setHeight(float height, com.vaadin.flow.component.Unit unit)
      Description copied from interface: Sizeable
      Sets the height of the object. Negative number implies unspecified size (terminal is free to set the size).
      Specified by:
      setHeight in interface FSizeable
      Specified by:
      setHeight in interface Sizeable
      Parameters:
      height - the height of the object.
      unit - the unit used for the width.
    • setWidth

      public void setWidth(String width)
      Description copied from interface: Sizeable
      Sets 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.

      Specified by:
      setWidth in interface FSizeable
      Specified by:
      setWidth in interface Sizeable
      Parameters:
      width - in CSS style string representation, null or empty string to reset
    • setSizeFull

      public void setSizeFull()
      Description copied from interface: Sizeable
      Sets the size to 100% x 100%.
      Specified by:
      setSizeFull in interface FSizeable
      Specified by:
      setSizeFull in interface Sizeable
    • setWidthFull

      public void setWidthFull()
      Description copied from interface: Sizeable
      Sets the width to 100%.
      Specified by:
      setWidthFull in interface FSizeable
      Specified by:
      setWidthFull in interface Sizeable
    • setHeightFull

      public void setHeightFull()
      Description copied from interface: Sizeable
      Sets the height to 100%.
      Specified by:
      setHeightFull in interface FSizeable
      Specified by:
      setHeightFull in interface Sizeable
    • setSizeUndefined

      public void setSizeUndefined()
      Description copied from interface: Sizeable
      Clears any size settings.
      Specified by:
      setSizeUndefined in interface FSizeable
      Specified by:
      setSizeUndefined in interface Sizeable
    • setWidthUndefined

      public void setWidthUndefined()
      Description copied from interface: Sizeable
      Clears any defined width.
      Specified by:
      setWidthUndefined in interface FSizeable
      Specified by:
      setWidthUndefined in interface Sizeable
    • setHeightUndefined

      public void setHeightUndefined()
      Description copied from interface: Sizeable
      Clears any defined height.
      Specified by:
      setHeightUndefined in interface FSizeable
      Specified by:
      setHeightUndefined in interface Sizeable
    • getWidth

      public float getWidth()
      Description copied from interface: Sizeable
      Gets the width of the object. Negative number implies unspecified size (terminal is free to set the size).
      Specified by:
      getWidth in interface Sizeable
      Returns:
      width of the object in units specified by widthUnits property.
    • getHeight

      public float getHeight()
      Description copied from interface: Sizeable
      Gets the height of the object. Negative number implies unspecified size (terminal is free to set the size).
      Specified by:
      getHeight in interface Sizeable
      Returns:
      height of the object in units specified by heightUnits property.
    • getWidthUnits

      public com.vaadin.flow.component.Unit getWidthUnits()
      Description copied from interface: Sizeable
      Gets the width property units.
      Specified by:
      getWidthUnits in interface FSizeable
      Specified by:
      getWidthUnits in interface Sizeable
      Returns:
      units used in width property.
    • getHeightUnits

      public com.vaadin.flow.component.Unit getHeightUnits()
      Description copied from interface: Sizeable
      Gets the height property units.
      Specified by:
      getHeightUnits in interface FSizeable
      Specified by:
      getHeightUnits in interface Sizeable
      Returns:
      units used in height property.
    • setHeight

      public void setHeight(String height)
      Description copied from interface: Sizeable
      Sets 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.

      Specified by:
      setHeight in interface FSizeable
      Specified by:
      setHeight in interface Sizeable
      Parameters:
      height - in CSS style string representation
    • doSetWidth

      protected void doSetWidth(SizeWithUnit width)
      Internal method for reacting to width changes.
      Parameters:
      width - the changed width to set
    • doSetHeight

      protected void doSetHeight(SizeWithUnit height)
      Internal method for reacting to height changes.
      Parameters:
      height - the changed height to set
    • addInternalStyles

      protected void addInternalStyles(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. In legacy framework these were handled by the client side connectors/widgets.
      Parameters:
      internalStyles - internal styles to add, not null
    • removeInternalStyles

      protected void removeInternalStyles(String... internalStyles)
      Removes the given internal styles.
      Parameters:
      internalStyles - the internal styles to remove
    • getInternalStyles

      protected Collection<String> getInternalStyles()
      Returns the internal styles in an unmodifiable collection.
      Returns:
      the internal styles of the component
      See Also:
    • getCustomStyles

      protected Collection<String> getCustomStyles()
      Returns the user added custom style names in an unmodifiable collection.
      Returns:
      the user added custom style names
    • onEnabledStateChanged

      public void onEnabledStateChanged(boolean enabled)
      Overrides:
      onEnabledStateChanged in class com.vaadin.flow.component.Component
    • getLocale

      public Locale getLocale()
      Get the locale from the current component or UI or from the given I18NProvider. -> If UI is not null, then it is used to get the locale, -> if UI is null, then the I18NProvider providedLocales first match will be returned, -> if I18NProvider is null, then default locale is returned.
      Overrides:
      getLocale in class com.vaadin.flow.component.Component
      Returns:
      Locale of this component or null if 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:
      isVisible in class com.vaadin.flow.component.Component
      Returns:
      true if the component is visible, false otherwise
      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:
      setVisible in class com.vaadin.flow.component.Component
      Parameters:
      visible - the component visibility value
      See Also:
    • setTooltipText

      public com.vaadin.flow.component.shared.Tooltip setTooltipText(String text)
      Specified by:
      setTooltipText in interface com.vaadin.flow.component.shared.HasTooltip
    • getTooltip

      public com.vaadin.flow.component.shared.Tooltip getTooltip()
      Specified by:
      getTooltip in interface com.vaadin.flow.component.shared.HasTooltip
    • addClassName

      public void addClassName(String className)
      Specified by:
      addClassName in interface com.vaadin.flow.component.HasStyle
    • removeClassName

      public boolean removeClassName(String className)
      Specified by:
      removeClassName in interface com.vaadin.flow.component.HasStyle
    • setClassName

      public void setClassName(String className)
      Specified by:
      setClassName in interface com.vaadin.flow.component.HasStyle
    • getClassName

      public String getClassName()
      Specified by:
      getClassName in interface com.vaadin.flow.component.HasStyle
    • getClassNames

      public com.vaadin.flow.dom.ClassList getClassNames()
      Specified by:
      getClassNames in interface com.vaadin.flow.component.HasStyle
    • setClassName

      public void setClassName(String className, boolean set)
      Specified by:
      setClassName in interface com.vaadin.flow.component.HasStyle
    • hasClassName

      public boolean hasClassName(String className)
      Specified by:
      hasClassName in interface com.vaadin.flow.component.HasStyle
    • getStyle

      public com.vaadin.flow.dom.Style getStyle()
      Specified by:
      getStyle in interface com.vaadin.flow.component.HasStyle
    • addClassNames

      public void addClassNames(String... classNames)
      Specified by:
      addClassNames in interface com.vaadin.flow.component.HasStyle
    • removeClassNames

      public void removeClassNames(String... classNames)
      Specified by:
      removeClassNames in interface com.vaadin.flow.component.HasStyle
    • fireEvent

      protected void fireEvent(com.vaadin.flow.component.ComponentEvent<?> componentEvent)
      Overrides:
      fireEvent in class com.vaadin.flow.component.Component