Class LazyPanel

All Implemented Interfaces:
HasAttachHandlers, HasHandlers, EventListener, AcceptsOneWidget, HasOneWidget, HasVisibility, HasWidgets, HasWidgets.ForIsWidget, IsWidget, Iterable<Widget>

public abstract class LazyPanel extends SimplePanel
Convenience class to help lazy loading. The bulk of a LazyPanel is not instantiated until setVisible(boolean)(true) or ensureWidget() is called.

Example

public class LazyPanelExample implements EntryPoint {

  private static class HelloLazyPanel extends LazyPanel {
    @Override
    protected Widget createWidget() {
      return new Label("Well hello there!");
    }
  }

  public void onModuleLoad() {
    final Widget lazy = new HelloLazyPanel();
    
    // Not strictly necessary, but keeps the empty outer div
    // from effecting layout before it is of any use
    lazy.setVisible(false);

    PushButton b = new PushButton("Click me");    
    b.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        lazy.setVisible(true);
      }
    });
    
    RootPanel root = RootPanel.get();
    root.add(b);
    root.add(lazy);
  }
}
  • Constructor Details

    • LazyPanel

      public LazyPanel()
  • Method Details

    • createWidget

      protected abstract Widget createWidget()
      Create the widget contained within the LazyPanel.
      Returns:
      the lazy widget
    • ensureWidget

      public void ensureWidget()
      Ensures that the widget has been created by calling createWidget() if SimplePanel.getWidget() returns null. Typically it is not necessary to call this directly, as it is called as a side effect of a setVisible(true) call.
    • setVisible

      public void setVisible(boolean visible)
      Description copied from interface: HasVisibility
      Sets whether this object is visible.
      Specified by:
      setVisible in interface HasVisibility
      Overrides:
      setVisible in class UIObject
      Parameters:
      visible - true to show the object, false to hide it