Class AbstractOrderedLayout

All Implemented Interfaces:
LayoutEvents.LayoutClickNotifier, ClientConnector, Sizeable, ComponentContainer, HasComponents, HasComponents.ComponentAttachDetachNotifier, Layout.AlignmentHandler, Layout.MarginHandler, com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasComponents, 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:
FormLayout, HorizontalLayout, VerticalLayout

public abstract class AbstractOrderedLayout extends AbstractLayout implements Layout.AlignmentHandler, Layout.MarginHandler, LayoutEvents.LayoutClickNotifier
Legacy version of AbstractOrderedLayout that resembles Vaadin 7/8's AbstractOrderedLayout API as closely as possible in order to facilitate migration to newer versions of Vaadin.

Base class for ordered layouts.

Author:
Vaadin Ltd
See Also:
  • Constructor Details

    • AbstractOrderedLayout

      public AbstractOrderedLayout(boolean isVertical)
      Constructs an ordered layout with the indicated orientation.
      Parameters:
      isVertical - true if it should be vertically oriented, false for horizontally oriented
    • AbstractOrderedLayout

      public AbstractOrderedLayout()
      Constructs an ordered layout with the horizontal orientation.
  • 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 AbstractComponent
      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.
    • addComponent

      public void addComponent(com.vaadin.flow.component.Component component)
      Description copied from interface: ComponentContainer
      Adds the component into this container.
      Specified by:
      addComponent in interface ComponentContainer
      Overrides:
      addComponent in class AbstractComponentContainer
      Parameters:
      component - the component to be added.
    • add

      public void add(com.vaadin.flow.component.Component... components)
      Specified by:
      add in interface com.vaadin.flow.component.HasComponents
      Overrides:
      add in class AbstractComponentContainer
    • addComponentsAndExpand

      public void addComponentsAndExpand(com.vaadin.flow.component.Component... components)
      Adds the given components to this layout and sets them as expanded. The main layout dimension is set to 100% if it is currently undefined.

      The components are added in the provided order to the end of this layout. Any components that are already children of this layout will be moved to new positions.

      Parameters:
      components - the components to set, not null
    • doSetHeight

      protected void doSetHeight(SizeWithUnit height)
      Description copied from class: AbstractComponent
      Internal method for reacting to height changes.
      Overrides:
      doSetHeight in class AbstractComponent
      Parameters:
      height - the changed height to set
    • doSetWidth

      protected void doSetWidth(SizeWithUnit width)
      Description copied from class: AbstractComponent
      Internal method for reacting to width changes.
      Overrides:
      doSetWidth in class AbstractComponent
      Parameters:
      width - the changed width to set
    • setSpacing

      public void setSpacing(boolean spacing)
      Enable spacing between child components within this layout.
      Parameters:
      spacing - true if spacing should be turned on, false if it should be turned off
    • isSpacing

      public boolean isSpacing()
      get the state of spacing in this layout
      Returns:
      true if spacing between child components within this layout is enabled, false otherwise
    • setMargin

      public void setMargin(boolean enabled)
      (non-Javadoc)
      Specified by:
      setMargin in interface Layout.MarginHandler
      Parameters:
      enabled - true if margins should be enabled on all sides, false to disable all margins
      See Also:
    • setMargin

      public void setMargin(MarginInfo marginInfo)
      (non-Javadoc)
      Specified by:
      setMargin in interface Layout.MarginHandler
      Parameters:
      marginInfo - MarginInfo object containing the new margins.
      See Also:
    • getMargin

      public MarginInfo getMargin()
      (non-Javadoc)
      Specified by:
      getMargin in interface Layout.MarginHandler
      Returns:
      MarginInfo containing the currently enabled margins.
      See Also:
    • remove

      public void remove(com.vaadin.flow.component.Component... components)
      Specified by:
      remove in interface com.vaadin.flow.component.HasComponents
      Overrides:
      remove in class AbstractComponentContainer
    • removeComponent

      public void removeComponent(com.vaadin.flow.component.Component component)
      Description copied from interface: ComponentContainer
      Removes the component from this container.
      Specified by:
      removeComponent in interface ComponentContainer
      Overrides:
      removeComponent in class AbstractComponentContainer
      Parameters:
      component - the component to be removed.
    • setExpandRatio

      public void setExpandRatio(com.vaadin.flow.component.Component component, float ratio)

      This method is used to control how excess space in layout is distributed among components. Excess space may exist if layout is sized and contained non relatively sized components don't consume all available space.

      Example how to distribute 1:3 (33%) for component1 and 2:3 (67%) for component2 : layout.setExpandRatio(component1, 1);
      layout.setExpandRatio(component2, 2);

      If no ratios have been set, the excess space is distributed evenly among all components.

      Note, that width or height (depending on orientation) needs to be defined for this method to have any effect.

      Parameters:
      component - the component in this layout which expand ratio is to be set
      ratio - new expand ratio (greater or equal to 0)
      Throws:
      IllegalArgumentException - if the expand ratio is negative or the component is not a direct child of the layout
    • getExpandRatio

      public float getExpandRatio(com.vaadin.flow.component.Component component)
      Returns the expand ratio of given component.
      Parameters:
      component - which expand ratios is requested
      Returns:
      expand ratio of given component, 0.0f by default.
    • getChildren

      public Stream<com.vaadin.flow.component.Component> getChildren()
      Overrides:
      getChildren in class com.vaadin.flow.component.Component
    • addComponentAtIndex

      public void addComponentAtIndex(int index, com.vaadin.flow.component.Component component)
      Specified by:
      addComponentAtIndex in interface com.vaadin.flow.component.HasComponents
    • addComponent

      public void addComponent(com.vaadin.flow.component.Component component, int index) throws IndexOutOfBoundsException
      Adds a component into indexed position in this container.
      Parameters:
      component - the component to be added.
      index - the index of the component position. The components currently in and after the position are shifted forwards.
      Throws:
      IndexOutOfBoundsException
    • addComponentAsFirst

      public void addComponentAsFirst(com.vaadin.flow.component.Component component)
      Adds a component into this container. The component is added to the left or on top of the other components.
      Specified by:
      addComponentAsFirst in interface com.vaadin.flow.component.HasComponents
      Parameters:
      component - the component to be added.
    • replaceComponent

      public void replaceComponent(com.vaadin.flow.component.Component oldComponent, com.vaadin.flow.component.Component newComponent)
      Description copied from interface: ComponentContainer
      Replaces the component in the container with another one without changing position.

      This method replaces component with another one is such way that the new component overtakes the position of the old component. If the old component is not in the container, the new component is added to the container. If the both component are already in the container, their positions are swapped. Component attach and detach events should be taken care as with add and remove.

      Specified by:
      replaceComponent in interface ComponentContainer
      Parameters:
      oldComponent - the old component that will be replaced.
      newComponent - the new component to be replaced.
    • getComponentCount

      public int getComponentCount()
      Gets the number of contained components.
      Specified by:
      getComponentCount in interface ComponentContainer
      Returns:
      the number of contained components
    • getComponent

      public com.vaadin.flow.component.Component getComponent(int index) throws IndexOutOfBoundsException
      Returns the component at the given position.
      Parameters:
      index - The position of the component.
      Returns:
      The component at the given index.
      Throws:
      IndexOutOfBoundsException - If the index is out of range.
    • getComponentIndex

      public int getComponentIndex(com.vaadin.flow.component.Component component)
      Returns the index of the given component.
      Parameters:
      component - The component to look up.
      Returns:
      The index of the component or -1 if the component is not a child.
    • setSlotClasses

      protected void setSlotClasses()
    • setComponentAlignment

      public void setComponentAlignment(com.vaadin.flow.component.Component childComponent, Alignment alignment)
      Description copied from interface: Layout.AlignmentHandler
      Set alignment for one contained component in this layout. Use predefined alignments from Alignment class.

      Example: layout.setComponentAlignment(myComponent, Alignment.TOP_RIGHT);

      Specified by:
      setComponentAlignment in interface Layout.AlignmentHandler
      Parameters:
      childComponent - the component to align within it's layout cell.
      alignment - the Alignment value to be set
    • getComponentAlignment

      public Alignment getComponentAlignment(com.vaadin.flow.component.Component childComponent)
      Description copied from interface: Layout.AlignmentHandler
      Returns the current Alignment of given component.
      Specified by:
      getComponentAlignment in interface Layout.AlignmentHandler
      Returns:
      the Alignment
    • setDefaultComponentAlignment

      public void setDefaultComponentAlignment(Alignment defaultComponentAlignment)
      Description copied from interface: Layout.AlignmentHandler
      Sets the alignment used for new components added to this layout. The default is Alignment.TOP_LEFT.
      Specified by:
      setDefaultComponentAlignment in interface Layout.AlignmentHandler
      Parameters:
      defaultComponentAlignment - The new default alignment
    • getDefaultComponentAlignment

      public Alignment getDefaultComponentAlignment()
      Description copied from interface: Layout.AlignmentHandler
      Returns the alignment used for new components added to this layout.
      Specified by:
      getDefaultComponentAlignment in interface Layout.AlignmentHandler
      Returns:
      The default alignment
    • addLayoutClickListener

      public com.vaadin.flow.shared.Registration addLayoutClickListener(LayoutEvents.LayoutClickListener listener)
      Description copied from interface: LayoutEvents.LayoutClickNotifier
      Add a click listener to the layout. The listener is called whenever the user clicks inside the layout. An event is also triggered when the click targets a component inside a nested layout or Panel, provided the targeted component does not prevent the click event from propagating. A caption is not considered part of a component.

      The child component that was clicked is included in the LayoutEvents.LayoutClickEvent.

      Specified by:
      addLayoutClickListener in interface LayoutEvents.LayoutClickNotifier
      Parameters:
      listener - The listener to add
      Returns:
      a registration object for removing the listener
      See Also:
      • Registration