eu.livotov.tpt.gui.widgets
Class TPTLazyLoadingLayout

java.lang.Object
  extended by com.vaadin.ui.AbstractComponent
      extended by com.vaadin.ui.AbstractComponentContainer
          extended by com.vaadin.ui.AbstractLayout
              extended by com.vaadin.ui.AbstractOrderedLayout
                  extended by com.vaadin.ui.VerticalLayout
                      extended by eu.livotov.tpt.gui.widgets.TPTLazyLoadingLayout
All Implemented Interfaces:
com.vaadin.event.MethodEventSource, com.vaadin.terminal.Paintable, com.vaadin.terminal.Sizeable, com.vaadin.terminal.VariableOwner, com.vaadin.ui.Component, com.vaadin.ui.ComponentContainer, com.vaadin.ui.Layout, com.vaadin.ui.Layout.AlignmentHandler, com.vaadin.ui.Layout.MarginHandler, com.vaadin.ui.Layout.SpacingHandler, java.io.Serializable, java.lang.Runnable, java.util.EventListener

public class TPTLazyLoadingLayout
extends com.vaadin.ui.VerticalLayout
implements java.lang.Runnable

This layout allows easy implementation of heavy components initialization or data loading. If your component initialization process takes significant time or you need to load some data from a database lenghty query, TPTLazyLoadingLayout can simplify your task. It runs your component initialization or data loading process in a separate thread on the server side and while the thread is running, it displays a progress indicator and optional message. When initialization of your component is finished, it appears in place of progress bar. This all happens without blocking the entire UI, so while your data is loading, application interface is alive and responsive.

Author:
dll
See Also:
Serialized Form

Nested Class Summary
static interface TPTLazyLoadingLayout.LazyLoader
          Implement this interface in your long initialing component and move all lenghty stuff into the lazyLoad method, returning the fully initializing component at the end
 
Nested classes/interfaces inherited from class com.vaadin.ui.AbstractComponent
com.vaadin.ui.AbstractComponent.ComponentErrorEvent, com.vaadin.ui.AbstractComponent.ComponentErrorHandler
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Layout
com.vaadin.ui.Layout.AlignmentHandler, com.vaadin.ui.Layout.MarginHandler, com.vaadin.ui.Layout.MarginInfo, com.vaadin.ui.Layout.SpacingHandler
 
Nested classes/interfaces inherited from interface com.vaadin.ui.ComponentContainer
com.vaadin.ui.ComponentContainer.ComponentAttachEvent, com.vaadin.ui.ComponentContainer.ComponentAttachListener, com.vaadin.ui.ComponentContainer.ComponentDetachEvent, com.vaadin.ui.ComponentContainer.ComponentDetachListener
 
Nested classes/interfaces inherited from interface com.vaadin.ui.Component
com.vaadin.ui.Component.ErrorEvent, com.vaadin.ui.Component.ErrorListener, com.vaadin.ui.Component.Event, com.vaadin.ui.Component.Focusable, com.vaadin.ui.Component.Listener
 
Nested classes/interfaces inherited from interface com.vaadin.terminal.Paintable
com.vaadin.terminal.Paintable.RepaintRequestEvent, com.vaadin.terminal.Paintable.RepaintRequestListener
 
Field Summary
private  com.vaadin.ui.Label errorLabel
           
private  TPTLazyLoadingLayout.LazyLoader loader
           
private  com.vaadin.ui.Label loadingLabel
           
private  com.vaadin.ui.ProgressIndicator progressBar
           
 
Fields inherited from class com.vaadin.ui.AbstractOrderedLayout
components
 
Fields inherited from class com.vaadin.ui.AbstractLayout
margins
 
Fields inherited from interface com.vaadin.ui.Layout.AlignmentHandler
ALIGNMENT_BOTTOM, ALIGNMENT_HORIZONTAL_CENTER, ALIGNMENT_LEFT, ALIGNMENT_RIGHT, ALIGNMENT_TOP, ALIGNMENT_VERTICAL_CENTER
 
Fields inherited from interface com.vaadin.terminal.Sizeable
SIZE_UNDEFINED, UNIT_SYMBOLS, UNITS_CM, UNITS_EM, UNITS_EX, UNITS_INCH, UNITS_MM, UNITS_PERCENTAGE, UNITS_PICAS, UNITS_PIXELS, UNITS_POINTS
 
Constructor Summary
TPTLazyLoadingLayout(TPTLazyLoadingLayout.LazyLoader loader, boolean loadImmideately)
          Constructs lazy loadig layout
 
Method Summary
private  void activateErrorView(java.lang.Throwable err)
           
private  void activateLoadedView(com.vaadin.ui.Component lazyLoad)
           
private  void activateLoadingView()
           
 com.vaadin.ui.Label getErrorLabel()
          Returns an instance of the label which is used to display an unexpected error message if the loading process throws an exception.
 com.vaadin.ui.Label getLoadingLabel()
          Returns an instance of loading label, which is shown together with a progress indicator during the loading process.
 com.vaadin.ui.ProgressIndicator getProgressIndicator()
          Returns an instance of progress indicator component for further customization
private  void initUI()
           
 void loadComponent()
          Initiates the process of loading an actual component via provided LazyLoader interface.
 void run()
          Do not call this method manually.
 void setLoadingProgress(float progress)
          Allow to update the progress status of the current component loading process.
 
Methods inherited from class com.vaadin.ui.AbstractOrderedLayout
addComponent, addComponent, addComponentAsFirst, addListener, changeVariables, getComponentAlignment, getComponentIterator, getExpandRatio, isSpacing, isSpacingEnabled, paintContent, removeComponent, removeListener, replaceComponent, setComponentAlignment, setComponentAlignment, setComponentAlignment, setExpandRatio, setSpacing
 
Methods inherited from class com.vaadin.ui.AbstractLayout
getMargin, setMargin, setMargin, setMargin
 
Methods inherited from class com.vaadin.ui.AbstractComponentContainer
addListener, addListener, attach, detach, fireComponentAttachEvent, fireComponentDetachEvent, moveComponentsFrom, removeAllComponents, removeListener, removeListener, requestRepaintAll, setEnabled, setHeight, setWidth
 
Methods inherited from class com.vaadin.ui.AbstractComponent
addListener, addListener, addListener, addListener, addListener, addStyleName, childRequestedRepaint, fireComponentErrorEvent, fireComponentEvent, fireEvent, focus, getApplication, getCaption, getComponentError, getData, getDebugId, getDescription, getErrorHandler, getErrorMessage, getHeight, getHeightUnits, getIcon, getLocale, getParent, getStyle, getStyleName, getTag, getWidth, getWidthUnits, getWindow, handleError, isEnabled, isImmediate, isReadOnly, isVisible, paint, removeListener, removeListener, removeListener, removeListener, removeListener, removeListener, removeStyleName, requestRepaint, requestRepaintRequests, setCaption, setComponentError, setData, setDebugId, setDescription, setErrorHandler, setHeight, setHeight, setHeightUnits, setIcon, setImmediate, setLocale, setParent, setReadOnly, setSizeFull, setSizeUndefined, setStyle, setStyleName, setVisible, setWidth, setWidth, setWidthUnits
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.vaadin.ui.ComponentContainer
addListener, addListener, moveComponentsFrom, removeAllComponents, removeListener, removeListener, requestRepaintAll
 
Methods inherited from interface com.vaadin.ui.Component
addListener, addStyleName, attach, childRequestedRepaint, detach, getApplication, getCaption, getIcon, getLocale, getParent, getStyleName, getWindow, isEnabled, isReadOnly, isVisible, removeListener, removeStyleName, setCaption, setEnabled, setIcon, setParent, setReadOnly, setStyleName, setVisible
 
Methods inherited from interface com.vaadin.terminal.Paintable
addListener, getDebugId, paint, removeListener, requestRepaint, requestRepaintRequests, setDebugId
 
Methods inherited from interface com.vaadin.terminal.VariableOwner
isImmediate
 
Methods inherited from interface com.vaadin.terminal.Sizeable
getHeight, getHeightUnits, getWidth, getWidthUnits, setHeight, setHeight, setHeight, setHeightUnits, setSizeFull, setSizeUndefined, setWidth, setWidth, setWidth, setWidthUnits
 

Field Detail

loader

private TPTLazyLoadingLayout.LazyLoader loader

progressBar

private com.vaadin.ui.ProgressIndicator progressBar

loadingLabel

private com.vaadin.ui.Label loadingLabel

errorLabel

private com.vaadin.ui.Label errorLabel
Constructor Detail

TPTLazyLoadingLayout

public TPTLazyLoadingLayout(TPTLazyLoadingLayout.LazyLoader loader,
                            boolean loadImmideately)
Constructs lazy loadig layout

Parameters:
loader - loader interface, which actually loads the data and constructs an actual component
loadImmideately - if set to true immideately starts a background thread to construct actual component. Otherwise you must explicitly call loadComponent() method to initiate this process. Until called, component displays empty panel.
Method Detail

loadComponent

public void loadComponent()
Initiates the process of loading an actual component via provided LazyLoader interface. Once this mehtod is called, UI start displaying a progress indicator and actual component loading process begins. Once process completed, a progress indicator will be automatically replaced by a constructed component. In case of any uncaught error, it will be also displayed instead of progress indicator.


run

public void run()
Do not call this method manually. It will be automatically called in a separate thread by a TPTApplication instance.

Specified by:
run in interface java.lang.Runnable

setLoadingProgress

public void setLoadingProgress(float progress)
Allow to update the progress status of the current component loading process. As the instance of TPTLazyLoader is passed to your LazyLoader implementation, you may update the progress from there.

Parameters:
progress - new progress. Must be specified from 0.0 to 1.0, which reflects 0% ... 100% interval. If set to 0.0, a progress indicator will be swithced to indeterminate mode, displaying an endless wheel.

getProgressIndicator

public com.vaadin.ui.ProgressIndicator getProgressIndicator()
Returns an instance of progress indicator component for further customization

Returns:
ProgressIndicator instance that is used to display a progress indicator during the loading process.

getLoadingLabel

public com.vaadin.ui.Label getLoadingLabel()
Returns an instance of loading label, which is shown together with a progress indicator during the loading process. Use this for further customization of the UI (set styles, sizes, etc...)

Returns:
Label instance

getErrorLabel

public com.vaadin.ui.Label getErrorLabel()
Returns an instance of the label which is used to display an unexpected error message if the loading process throws an exception. Use it for further customization of the UI (set styles, sizes, etc)

Returns:
Label instance

activateLoadedView

private void activateLoadedView(com.vaadin.ui.Component lazyLoad)

activateErrorView

private void activateErrorView(java.lang.Throwable err)

activateLoadingView

private void activateLoadingView()

initUI

private void initUI()