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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classLazyLoad.LazyLoadElementThis class exists so thatLazyLoadcan have a custom tag name.
-
Field Summary
Fields Modifier and Type Field Description static StringEMPTY_CLASS_NAMEStyle name when this component is empty (not showing anything).static StringLOADED_CLASS_NAMEStyle 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Optional<C>getLoadedContent()Gets the content if it was already loaded (isOnlyLoadedOnce()()} istrue) or if it is currently showing.booleanisLoaded()Checks if the content has been already loaded (isOnlyLoadedOnce()()} istrue) or is currently loaded.booleanisOnlyLoadedOnce()Returns if the lazy loading happens only on the first showing.protected voidonNowHidden()protected voidonNowVisible()-
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, 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.HasStyle
addClassName, addClassNames, getClassName, getClassNames, getStyle, hasClassName, removeClassName, removeClassNames, setClassName, setClassName
-
Methods inherited from interface org.vaadin.miki.markers.WithIdMixin
withId
-
-
-
-
Field Detail
-
EMPTY_CLASS_NAME
public static final String EMPTY_CLASS_NAME
Style name when this component is empty (not showing anything).- See Also:
- Constant Field Values
-
LOADED_CLASS_NAME
public static final String LOADED_CLASS_NAME
Style name when this component has content.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
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-Supplierthat 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-Supplierthat will be called when the component gets into view.removeOnHide- Whether to remove the component when this object gets hidden.
-
-
Method Detail
-
onNowHidden
protected void onNowHidden()
-
onNowVisible
protected void onNowVisible()
-
isOnlyLoadedOnce
public boolean isOnlyLoadedOnce()
Returns if the lazy loading happens only on the first showing.- Returns:
truewhen the target component will be loaded only once, the first time this component is shown; otherwisefalse.
-
getLoadedContent
public Optional<C> getLoadedContent()
Gets the content if it was already loaded (isOnlyLoadedOnce()()} istrue) 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(),isOnlyLoadedOnce()
-
isLoaded
public boolean isLoaded()
Checks if the content has been already loaded (isOnlyLoadedOnce()()} istrue) or is currently loaded.- Returns:
- Whether or not the content has been loaded.
- See Also:
getLoadedContent(),isOnlyLoadedOnce()
-
-