Class AbstractSingleComponentContainer

java.lang.Object
com.vaadin.flow.component.Component
All Implemented Interfaces:
ClientConnector, Sizeable, HasComponents, HasComponents.ComponentAttachDetachNotifier, SingleComponentContainer, 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, Iterable<com.vaadin.flow.component.Component>
Direct Known Subclasses:
Panel

public abstract class AbstractSingleComponentContainer extends AbstractComponent implements SingleComponentContainer
Abstract base class for legacy Vaadin framework version 7/8 component containers that have only one child component.

For component containers that support multiple children, inherit AbstractComponentContainer instead of this class.

See Also:
  • Constructor Details

    • AbstractSingleComponentContainer

      public AbstractSingleComponentContainer()
  • Method Details

    • getComponentCount

      public int getComponentCount()
      Description copied from interface: SingleComponentContainer
      Gets the number of children this SingleComponentContainer has. This must be symmetric with what HasComponents.iterator() returns and thus typically return 1 if the content is set, 0 otherwise.
      Specified by:
      getComponentCount in interface SingleComponentContainer
      Returns:
      The number of child components this container has.
    • iterator

      public Iterator<com.vaadin.flow.component.Component> iterator()
      Description copied from interface: HasComponents
      Gets an iterator to the collection of contained components. Using this iterator it is possible to step through all components contained in this container.

      The iterator is typically unmodifiable, and calls to Iterator.remove() throw an exception.

      Specified by:
      iterator in interface HasComponents
      Specified by:
      iterator in interface Iterable<com.vaadin.flow.component.Component>
      Returns:
      the component iterator.
    • addComponentAttachListener

      public com.vaadin.flow.shared.Registration addComponentAttachListener(HasComponents.ComponentAttachListener listener)
      Description copied from interface: HasComponents.ComponentAttachDetachNotifier
      Listens the component attach events.
      Specified by:
      addComponentAttachListener in interface HasComponents.ComponentAttachDetachNotifier
      Parameters:
      listener - the listener to add, not null
      Returns:
      a registration object for removing the listener
      See Also:
      • Registration
    • addComponentDetachListener

      public com.vaadin.flow.shared.Registration addComponentDetachListener(HasComponents.ComponentDetachListener listener)
      Description copied from interface: HasComponents.ComponentAttachDetachNotifier
      Listens the component detach events.
      Specified by:
      addComponentDetachListener in interface HasComponents.ComponentAttachDetachNotifier
    • fireComponentAttachEvent

      protected void fireComponentAttachEvent(com.vaadin.flow.component.Component component)
      Fires the component attached event. This is called by the setContent(Component) method after the component has been set as the content.
      Parameters:
      component - the component that has been added to this container.
    • fireComponentDetachEvent

      protected void fireComponentDetachEvent(com.vaadin.flow.component.Component component)
      Fires the component detached event. This is called by the setContent(Component) method after the content component has been replaced by other content.
      Parameters:
      component - the component that has been removed from this container.
    • getContent

      public com.vaadin.flow.component.Component getContent()
      Description copied from interface: SingleComponentContainer
      Gets the content of this container. The content is a component that serves as the outermost item of the visual contents.
      Specified by:
      getContent in interface SingleComponentContainer
      Returns:
      a component to use as content
      See Also:
    • setContent

      public void setContent(com.vaadin.flow.component.Component content)
      Sets the content of this container. The content is a component that serves as the outermost item of the visual contents.

      The content must always be set, either with a constructor parameter or by calling this method.

      Previous versions of Vaadin used a VerticalLayout with margins enabled as the default content but that is no longer the case.

      Specified by:
      setContent in interface SingleComponentContainer
      Parameters:
      content - a component (typically a layout) to use as content
    • setContentWrapper

      protected void setContentWrapper(com.vaadin.flow.dom.Element wrapper)
      Sets the element that will be used as the content wrapper.

      By default, the content component defined through setContent(Component) is attached as a direct child of AbstractSingleComponentContainer. That's sometimes not the desired behavior if, for instance, the container wants to define a different slot on which the content will be attached to.

      Note that it might have a side effect where Component.getParent() from the content component returns the wrapper instead of the AbstractSingleComponentContainer instance. To avoid this, the Element API can be used to create the element and ComponentUtil.componentFromElement(Element, Class, boolean) to get the component passing false to the mapComponent property, so it won't map the component to the element. Or use the ElementFactory methods.

      The wrapper can only be set once and if no content is already set to the container.

      Parameters:
      wrapper - the wrapper element to be used to attach the content to
    • getContentWrapper

      protected com.vaadin.flow.dom.Element getContentWrapper()
      Get the wrapper to be used as parent of the content element. If no wrapper is set, this.getElement() is returned.
      Returns:
      the wrapper or this.getElement() element.
    • onAttach

      protected void onAttach(com.vaadin.flow.component.AttachEvent attachEvent)
      Overrides:
      onAttach in class AbstractClientConnector
    • removeFromParent

      public static void removeFromParent(com.vaadin.flow.component.Component content) throws IllegalArgumentException
      Utility method for removing a component from its parent (if possible).
      Parameters:
      content - component to remove
      Throws:
      IllegalArgumentException
    • setHeight

      public void setHeight(float height, Sizeable.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
      Overrides:
      setHeight in class AbstractComponent
      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: 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
      Overrides:
      setWidth in class AbstractComponent
      Parameters:
      width - the width of the object.
      unit - the unit used for the width.