GWT ленивая загрузка - PullRequest
       8

GWT ленивая загрузка

1 голос
/ 20 декабря 2008

Имеет ли GWT LazyPanel. Я не вижу его. Пожалуйста, дайте мне знать. Если он получил LazyPanel, пожалуйста, дайте мне знать версию

Ответы [ 2 ]

2 голосов
/ 20 декабря 2008

Я согласен с rustyshelf по принципу поиска в Google, но, поскольку StackOverflow также является ссылкой сам по себе, вот более подробный ответ:

По умолчанию LazyPanel не отображается. Только когда вызывается setVisible (true) на LazyPanel, создается базовый виджет.

Этот класс в первую очередь следует использовать вместе со StackPanel, DisclosurePanel и TabPanel, когда дочерние панели содержат относительно тяжелое содержимое.
Использование LazyPanel для создания этого содержимого может значительно улучшить пользовательский опыт.


Использовать LazyPanel просто . Все, что вам нужно сделать, это добавить виджет, который вы хотите лениво загрузить на ленивую панель, а затем вызвать setVisible (true) на ленивой панели, чтобы фактически загрузить виджет по требованию. Стоит отметить, что LazyPanel в основном предназначен для использования с виджетами, такими как TabPanel и StackPanel, и не идеален во всех случаях.

0 голосов
/ 26 марта 2009

Вот LazyPanel.java из "релиз-кандидата" GWT 1.6.2 Так что да, просто, и подтверждение ответа выше.

/*
 * 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);
  }
}
...