Class AbstractComponent

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.classic.v8.server.AbstractClientConnector
com.vaadin.classic.v8.ui.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.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
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
      Overrides:
      beforeClientResponse in class AbstractClientConnector
      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(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 Sizeable
      Parameters:
      width - in CSS style string representation, null or empty string to reset
    • 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 Sizeable
      Parameters:
      width - the width of the object.
      unit - the unit used for the width.
    • 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.
    • getWidthUnits

      public com.vaadin.flow.component.Unit getWidthUnits()
      Description copied from interface: Sizeable
      Gets the width property units.
      Specified by:
      getWidthUnits in interface Sizeable
      Returns:
      units used in width 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 Sizeable
      Parameters:
      height - in CSS style string representation
    • 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 Sizeable
      Parameters:
      height - the height of the object.
      unit - the unit used for the width.
    • 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.
    • getHeightUnits

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

      public void setSizeFull()
      Description copied from interface: Sizeable
      Sets the size to 100% x 100%.
      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 Sizeable
    • setHeightFull

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

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

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

      public void setHeightUndefined()
      Description copied from interface: Sizeable
      Clears any defined height.
      Specified by:
      setHeightUndefined in interface Sizeable
    • 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
    • getStyleName

      public String 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

      public void setStyleName(String style)
      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 Label component 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

      public void setStyleName(String style, boolean add)
      Adds or removes a style name. Multiple styles can be specified as a space-separated list of style names.

      If the add parameter is true, the style name is added to the component. If the add parameter is false, the style name is removed from the component.

      Functionally this is equivalent to using addStyleName(String) or removeStyleName(String)

      Parameters:
      style - the style name to be added or removed
      add - true to add the given style, false to remove it
      See Also:
    • addStyleName

      public void addStyleName(String style)
      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 Label component 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

      public void addStyleNames(String... styles)
      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

      public void removeStyleName(String style)
      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() or setStyleName() 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

      public void removeStyleNames(String... styles)
      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

      public String getPrimaryStyleName()
      Gets the primary style name of the classic component. See setPrimaryStyleName(String) for a better description of the primary stylename.
    • setPrimaryStyleName

      public void setPrimaryStyleName(String style)
      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

      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
    • addListener

      public com.vaadin.flow.shared.Registration addListener(Listener listener)
      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:
    • onEnabledStateChanged

      public void onEnabledStateChanged(boolean enabled)
      Overrides:
      onEnabledStateChanged in class com.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:
      isEnabled in interface com.vaadin.flow.component.HasEnabled
      Returns:
      true if the component and its parent are enabled, false otherwise.
    • 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:
      setEnabled in interface com.vaadin.flow.component.HasEnabled
      Parameters:
      enabled - a boolean value specifying if the component should be enabled or not
    • setData

      public void setData(Object data)
      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

      public Object getData()
      Gets the application specific data. See setData(Object).
      Returns:
      the Application specific data set with setData function.
    • setLocale

      public void setLocale(Locale locale)
      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

      public 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:
      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:
    • 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 public Resource 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 protected void 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 protected ActionManager 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 public String 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 public ErrorMessage 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 protected Collection<String> 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 public String 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 public ErrorMessage 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 protected AbstractComponentState getState()
      Deprecated.
      Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.
      Overrides:
      getState in class AbstractClientConnector
      Returns:
      fake shared state
    • getState

      @Deprecated protected AbstractComponentState getState(boolean markAsDirty)
      Deprecated.
      Not supported. See Classic Component Pack documentation in https://vaadin.com/docs/latest/flow/upgrading/legacy-component-pack for mitigation options.
      Overrides:
      getState in class AbstractClientConnector
      Parameters:
      markAsDirty - mark as dirty
      Returns:
      fake shared state
    • isCaptionAsHtml

      @Deprecated public boolean 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 protected boolean 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 protected boolean 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 public boolean 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 public void setCaption(String caption)
      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 public void setCaptionAsHtml(boolean captionAsHtml)
      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 public void setComponentError(ErrorMessage componentError)
      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 public void setDescription(String description)
      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
    • setDescription

      @Deprecated public void setDescription(String description, ContentMode mode)
      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
      mode - mode
    • setIcon

      @Deprecated public void setIcon(Resource icon)
      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 protected void setReadOnly(boolean readOnly)
      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 protected void setRequiredIndicatorVisible(boolean visible)
      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 public void setResponsive(boolean responsive)
      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
    • setLabel

      public void setLabel(String label)
      Specified by:
      setLabel in interface com.vaadin.flow.component.HasLabel
    • getLabel

      public String getLabel()
      Specified by:
      getLabel in interface com.vaadin.flow.component.HasLabel
    • 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