Class LazyLoad<C extends com.vaadin.flow.component.Component>

java.lang.Object
com.vaadin.flow.component.Component
com.vaadin.flow.component.Composite<LazyLoad.LazyLoadElement>
org.vaadin.miki.superfields.lazyload.LazyLoad<C>
Type Parameters:
C - Type of component that is lazy-loaded.
All Implemented Interfaces:
com.vaadin.flow.component.AttachNotifier, com.vaadin.flow.component.DetachNotifier, com.vaadin.flow.component.HasElement, com.vaadin.flow.component.HasStyle, Serializable, HasId, WithIdMixin<LazyLoad<C>>

public class LazyLoad<C extends com.vaadin.flow.component.Component> extends com.vaadin.flow.component.Composite<LazyLoad.LazyLoadElement> implements WithIdMixin<LazyLoad<C>>, com.vaadin.flow.component.HasStyle
A component that remains empty until it gets into view. After that it displays the lazy-loaded content. Note that by default the size of this component is 0px, as there is no styling to it. Be sure to apply styling. As a result and by default, if there are many of lazy load components one next to another, all of them will trigger.
Since:
2020-04-22
Author:
miki
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    This class exists so that LazyLoad can have a custom tag name.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Style name when this component is empty (not showing anything).
    static final String
    Style name when this component has content.
  • Constructor Summary

    Constructors
    Constructor
    Description
    LazyLoad(C contents)
    Creates lazy load wrapper for given contents.
    LazyLoad(com.vaadin.flow.function.SerializableSupplier<C> supplier)
    Creates lazy load wrapper for given component supplier.
    LazyLoad(com.vaadin.flow.function.SerializableSupplier<C> supplier, boolean removeOnHide)
    Creates lazy load wrapper for given component supplier.
    LazyLoad(C contents, boolean removeOnHide)
    Creates lazy load wrapper for given contents.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets the content if it was already loaded (isOnlyLoadedOnce() ()} is true) or if it is currently showing.
    boolean
    Checks if the content has been already loaded (isOnlyLoadedOnce() ()} is true) or is currently loaded.
    boolean
    Returns if the lazy loading happens only on the first showing.
    protected void
     
    protected void
     

    Methods inherited from class com.vaadin.flow.component.Composite

    getChildren, getContent, getElement, initContent

    Methods inherited from class com.vaadin.flow.component.Component

    addListener, findAncestor, fireEvent, from, get, getEventBus, getId, getListeners, getLocale, getParent, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getTranslation, getUI, hasListener, isAttached, isTemplateMapped, isVisible, onAttach, onDetach, onEnabledStateChanged, removeFromParent, scrollIntoView, scrollIntoView, set, setElement, setId, setVisible

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface com.vaadin.flow.component.AttachNotifier

    addAttachListener

    Methods inherited from interface com.vaadin.flow.component.DetachNotifier

    addDetachListener

    Methods inherited from interface com.vaadin.flow.component.HasElement

    getElement

    Methods inherited from interface org.vaadin.miki.markers.HasId

    getId, setId

    Methods inherited from interface com.vaadin.flow.component.HasStyle

    addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName

    Methods inherited from interface org.vaadin.miki.markers.WithIdMixin

    withId
  • Field Details

    • EMPTY_CLASS_NAME

      public static final String EMPTY_CLASS_NAME
      Style name when this component is empty (not showing anything).
      See Also:
    • LOADED_CLASS_NAME

      public static final String LOADED_CLASS_NAME
      Style name when this component has content.
      See Also:
  • Constructor Details

    • LazyLoad

      public LazyLoad(C contents)
      Creates lazy load wrapper for given contents. It will be displayed the first time this component becomes shown on screen.
      Parameters:
      contents - Contents to wrap for lazy loading.
    • LazyLoad

      public LazyLoad(com.vaadin.flow.function.SerializableSupplier<C> supplier)
      Creates lazy load wrapper for given component supplier. It will be called exactly once, the first time this component becomes shown on screen.
      Parameters:
      supplier - Supplier that will be called when the component gets into view.
    • LazyLoad

      public LazyLoad(C contents, boolean removeOnHide)
      Creates lazy load wrapper for given contents.
      Parameters:
      contents - Contents to wrap for lazy loading.
      removeOnHide - Whether to remove the component when this object gets hidden.
    • LazyLoad

      public LazyLoad(com.vaadin.flow.function.SerializableSupplier<C> supplier, boolean removeOnHide)
      Creates lazy load wrapper for given component supplier.
      Parameters:
      supplier - Supplier that will be called when the component gets into view.
      removeOnHide - Whether to remove the component when this object gets hidden.
  • Method Details

    • onNowHidden

      protected void onNowHidden()
    • onNowVisible

      protected void onNowVisible()
    • isOnlyLoadedOnce

      public boolean isOnlyLoadedOnce()
      Returns if the lazy loading happens only on the first showing.
      Returns:
      true when the target component will be loaded only once, the first time this component is shown; otherwise false.
    • getLoadedContent

      public Optional<C> getLoadedContent()
      Gets the content if it was already loaded (isOnlyLoadedOnce() ()} is true) or if it is currently showing.
      Returns:
      A component that was lazy-loaded. If the component was not yet shown on-screen, returns Optional.empty().
      See Also:
    • isLoaded

      public boolean isLoaded()
      Checks if the content has been already loaded (isOnlyLoadedOnce() ()} is true) or is currently loaded.
      Returns:
      Whether or not the content has been loaded.
      See Also: