GWT延迟加载

时间:2008-12-20 06:44:59

标签: gwt gwt-ext

GWT是否有LazyPanel。我看不到它。请让我知道。如果它有lazyPanel,请知道版本

2 个答案:

答案 0 :(得分:2)

我同意rustyshelf关于Google搜索的原则,但由于StackOverflow本身也是一个参考,这里有一个更详细的答案:

  

默认情况下,不显示LazyPanel。只有在LazyPanel上调用setVisible(true)时才会创建基础窗口小部件。

     

当子面板包含相对较重的内容时,此类主要应与StackPanel,DisclosurePanel和TabPanel一起使用。
  使用LazyPanel包装这些内容的创建可以显着改善用户体验。


  

Using the LazyPanel is simple。您需要做的就是在惰性面板中添加要延迟加载的窗口小部件,然后在惰性面板上调用setVisible(true)以实际按需加载窗口小部件。值得一提的是,LazyPanel主要用于TabPanel和StackPanel等小部件,在所有情况下并不理想。

答案 1 :(得分:0)

这是来自“候选版本”GWT 1.6.2的LazyPanel.java 所以是的,简单的,并确认上面的答案。

/*
 * Copyright 2008 Google Inc.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */

package com.google.gwt.user.client.ui;

/**
 * Convenience class to help lazy loading. The bulk of a LazyPanel is not
 * instantiated until {@link #setVisible}(true) or {@link #ensureWidget} is
 * called.
 * <p>
 * <h3>Example</h3> {@example com.google.gwt.examples.LazyPanelExample}
 */
public abstract class LazyPanel extends SimplePanel {

  public LazyPanel() {
  }

  /**
   * Create the widget contained within the {@link LazyPanel}.
   * 
   * @return the lazy widget
   */
  protected abstract Widget createWidget();

  /**
   * Ensures that the widget has been created by calling {@link #createWidget}
   * if {@link #getWidget} returns <code>null</code>. Typically it is not
   * necessary to call this directly, as it is called as a side effect of a
   * <code>setVisible(true)</code> call.
   */
  public void ensureWidget() {
    Widget widget = getWidget();
    if (widget == null) {
      widget = createWidget();
      setWidget(widget);
    }
  }

  @Override
  /*
   * Sets whether this object is visible. If <code>visible</code> is
   * <code>true</code>, creates the sole child widget if necessary by calling
   * {@link #ensureWidget}.
   * 
   * @param visible <code>true</code> to show the object, <code>false</code> to
   * hide it
   */
  public void setVisible(boolean visible) {
    if (visible) {
      ensureWidget();
    }
    super.setVisible(visible);
  }
}