文档帮助

术语、图标和标签

许多类在使用配置对象创建(实例化)类时都有快捷名称。快捷名称称为 alias(如果类扩展了 Ext.Component,则称为 xtype)。别名/xtype 列在适用类的类名旁边,以供快速参考。

访问级别

框架类或其成员可以指定为 privateprotected。否则,类/成员为 publicPublicprotectedprivate 是访问描述符,用于传达应如何以及何时使用类或类成员。

成员类型

成员语法

下面是一个示例类成员,我们可以对其进行剖析,以显示类成员的语法(在本例中,从 Ext.button.Button 类查看的 lookupComponent 方法)。

lookupComponent ( item ) : Ext.Component
protected

当原始配置对象添加到此容器时调用,无论是在初始化 items 配置期间,还是在 添加新项目或 {@link #insert 插入} 时调用。

此方法将传递的对象转换为实例化的子组件。

当需要对子创建应用特殊处理时,可以在子类中重写此方法。

参数

item :  Object

正在添加的配置对象。

返回值
Ext.Component

要添加的组件。

让我们看一下成员行的每个部分

成员标志

API 文档使用许多标志来进一步传达类成员的功能和意图。标签可以用文本标签、缩写或图标表示。

类图标

- 表示框架类

- Singleton 框架类。*有关更多信息,请参阅 singleton 标志

- 组件类型框架类(Ext JS 框架中扩展 Ext.Component 的任何类)

- 表示类、成员或指南在当前查看的版本中是新的

成员图标

- 表示 config 类型的类成员

- 表示 property 类型的类成员

- 表示 method 类型的类成员

- 表示 event 类型的类成员

- 表示 theme variable 类型的类成员

- 表示 theme mixin 类型的类成员

- 表示类、成员或指南在当前查看的版本中是新的

类成员快速导航菜单

在 API 文档页面上的类名下方,有一行按钮,对应于当前类拥有的成员类型。每个按钮都显示按类型划分的成员计数(此计数会随着应用过滤器而更新)。单击按钮将导航到该成员部分。将鼠标悬停在成员类型按钮上将显示该类型的所有成员的弹出菜单,以便快速导航。

Getter 和 Setter 方法

与类配置选项相关的 Getter 和 Setter 方法将显示在方法部分以及 API 文档和成员类型菜单的配置部分中,就在它们所作用的配置下方。Getter 和 Setter 方法文档将在配置行中找到,以便于参考。

历史记录栏

您的页面历史记录保存在本地存储中,并显示在顶部标题栏下方(使用可用空间)。默认情况下,显示的唯一搜索结果是与您当前查看的产品/版本匹配的页面。您可以通过单击历史记录栏右侧的 按钮并选择“全部”单选选项来扩展显示的内容。这将显示所有产品/版本的所有最近页面。

在历史记录配置菜单中,您还将看到最近页面访问的列表。结果按“当前产品/版本”和“全部”单选选项过滤。单击 按钮将清除历史记录栏以及本地存储中保存的历史记录。

如果在历史记录配置菜单中选择了“全部”,则将启用“在历史记录栏中显示产品详细信息”复选框选项。选中后,每个历史页面的产品/版本将与历史记录栏中的页面名称一起显示。将光标悬停在历史记录栏中的页面名称上也会将产品/版本显示为工具提示。

搜索和过滤器

可以使用页面顶部的搜索字段搜索 API 文档和指南。

在 API 文档页面上,还有一个过滤器输入字段,该字段使用过滤器字符串过滤成员行。除了按字符串过滤外,您还可以按访问级别、继承和只读过滤类成员。这可以使用页面顶部的复选框完成。

API 类导航树底部的复选框过滤类列表以包含或排除私有类。

单击空的搜索字段将显示您最近的 10 次搜索,以便快速导航。

API 文档类元数据

每个 API 文档页面(Javascript 原始类型页面除外)都有一个与该类相关的元数据菜单视图。此元数据视图将具有以下一项或多项

展开和折叠示例和类成员

可运行示例 (Fiddle) 默认在页面上展开。您可以使用代码块左上角的箭头单独折叠和展开示例代码块。您还可以使用页面右上角的切换按钮切换所有示例的折叠状态。切换所有状态将在页面加载之间记住。

类成员默认在页面上折叠。您可以使用成员行左侧的箭头图标或全局使用右上角的展开/折叠所有切换按钮来展开和折叠成员。

桌面视图 -vs- 移动视图

在较窄的屏幕或浏览器上查看文档将导致针对较小外形尺寸优化的视图。桌面视图和“移动”视图之间的主要区别在于

查看类源代码

可以通过单击 API 文档页面顶部的类名来查看类源代码。可以通过单击成员行右侧的“查看源代码”链接来查看类成员的源代码。

GXT 4.x


顶部

GXT Driver 模型

本指南介绍构建 GWT WebDriver widget 绑定模型。

参考

模型部分

ForWidget

GWT Driver 模型类注释 @ForWidget(Label.class)@ForWidget(com.google.gwt.user.client.ui.Label.class) 不是必需的,但对于使用 .is.as 强制转换引用非常方便。

@ForWidget(Label.class)
public class GwtLabel extends GwtWidget<GwtLabelFinder> {
  //...
}

GwtWidgetFinder

GwtWidgetFinder<Model> 使用构建器模式来实例化模型,其目标是为查找器提供 DOM 中 widget 的方向。

@ForWidget(Label.class)
public class GwtLabel extends GwtWidget<GwtLabelFinder> {
  public GwtLabel(WebDriver driver, WebElement element) {
    super(driver, element);
  }

  // This is the definition to how the widget is found, each super model will have this. 
  public static class GwtLabelFinder extends GwtWidgetFinder<GwtLabel> {
    @Override
    public GwtLabel done() {
      //...
      return new GwtLabel(driver, webElement);
    }
  }
}

Widget 方法访问器

访问翻译后的 javascript 函数可以通过使用 ClientMethodsFactory 完成。ClientMethodsFactory 接口创建一个代理来与应用程序中翻译后的 javascript 交互。

@ForWidget(com.sencha.gxt.widget.core.client.tree.Tree.class)
public class Tree extends GwtWidget<GwtWidgetFinder<Tree>> {
  public interface TreeMethods extends ClientMethods {

    // this will tap the Tree.class isExpand method using reflection
    boolean isExpanded(WebElement widget, WebElement item);

    //...
  }

  private final TreeMethods methods;

  public Tree(WebDriver driver, WebElement element) {
    super(driver, element);
    methods = ClientMethodsFactory.create(TreeMethods.class, driver);
  }

  public class Item {
    public boolean isExpanded() {
      // this accesses the reflected method
      return methods.isExpanded(getWidgetElement(), getElement());
    }

    //...
  }

  //...
}

扩展

扩展 GWT Driver 模型。重要的是要注意,当使用此方法时,GwtWidget.find 使用超类名称,然后强制转换为子类名称。

  • 扩展示例。

    @ForWidget(com.sencha.gxt.widget.core.client.form.ComboBox.class)
    public class ComboBox extends Field {
    //...
    }
    
  • 实例化其用法的示例。请注意,find(Field.class,...) 使用模型的超类名称,.as(ComboBox.class) 将其强制转换为模型子类名称。

    ComboBox combo = GwtWidget.find(Field.class, driver).withText("Pick").done().as(ComboBox.class);
    

示例

基本示例

此示例适用于 GWT Label widget。 源代码

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.senchalabs.gwt.gwtdriver.by.ByNearestWidget;
import org.senchalabs.gwt.gwtdriver.by.FasterByChained;
import org.senchalabs.gwt.gwtdriver.models.GwtLabel.GwtLabelFinder;
import org.senchalabs.gwt.gwtdriver.models.GwtWidget.ForWidget;

import com.google.gwt.user.client.ui.Label;

@ForWidget(Label.class)
public class GwtLabel extends GwtWidget<GwtLabelFinder> {
  public GwtLabel(WebDriver driver, WebElement element) {
    super(driver, element);
  }

  public String getText() {
    return getElement().getText();
  }

  public static class GwtLabelFinder extends GwtWidgetFinder<GwtLabel> {
    String text;

    public GwtLabelFinder withText(String text) {
      this.text = text;
      return this;
    }

    @Override
    public GwtLabel done() {
      WebElement elt = this.elt;
      if (text != null) {
        elt = elt.findElement(
          new FasterByChained(
            By.xpath(".//*[contains(text(), " + escapeToString(text) + ")]"),
              new ByNearestWidget(driver, Label.class)));
      }
      return new GwtLabel(driver, elt);
    }
  }
}

Widget 方法访问器示例

这是一个使用 widget 函数访问器插件到翻译后的 javascript 的示例。 模型源代码

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.TimeUnit;

import com.google.common.base.Predicate;
import org.openqa.selenium.By;
import org.openqa.selenium.NotFoundException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.FluentWait;
import org.senchalabs.gwt.gwtdriver.invoke.ClientMethods;
import org.senchalabs.gwt.gwtdriver.invoke.ClientMethodsFactory;
import org.senchalabs.gwt.gwtdriver.models.GwtWidget;
import org.senchalabs.gwt.gwtdriver.models.GwtWidget.ForWidget;
import org.senchalabs.gwt.gwtdriver.models.GwtWidgetFinder;

@ForWidget(com.sencha.gxt.widget.core.client.tree.Tree.class)
public class Tree extends GwtWidget<GwtWidgetFinder<Tree>> {
  public interface TreeMethods extends ClientMethods {
    /** From any element within the widget, finds the nearest complete node. */
    WebElement getNodeElement(WebElement widget, WebElement elt);

    /** Find the root children */
    List<WebElement> getRootChildren(WebElement widget);

    /** Find the children of the given item */
    List<WebElement> getChildren(WebElement widget, WebElement item);

    /** Gets the element of the parent node of the given item */
    WebElement getParent(WebElement widget, WebElement item);

    boolean isExpanded(WebElement widget, WebElement item);

    WebElement getExpandElement(WebElement widget, WebElement item);

    WebElement getCheckElement(WebElement widget, WebElement item);

    boolean isLoading(WebElement widget, WebElement item);
  }

  private final TreeMethods methods;

  public Tree(WebDriver driver, WebElement element) {
    super(driver, element);
    methods = ClientMethodsFactory.create(TreeMethods.class, driver);
  }

  public class Item {
    private final WebElement elt;

    private Item(WebElement element) {
      this.elt = element;
    }

    public String getText() {
      return elt.getText();
    }

    public WebElement getElement() {
      return elt;
    }

    public void toggleExpand() {
      methods.getExpandElement(getWidgetElement(), getElement()).click();
    }

    public boolean isExpanded() {
      return methods.isExpanded(getWidgetElement(), getElement());
    }

    public void toggleCheck() {
      methods.getCheckElement(getWidgetElement(), getElement()).click();
    }

    public void waitForLoaded() {
      waitForLoaded(10, TimeUnit.SECONDS);
    }

    public void waitForLoaded(long duration, TimeUnit unit) {
      new FluentWait<WebDriver>(getDriver()).withTimeout(duration, unit).ignoring(NotFoundException.class).until(
          new Predicate<WebDriver>() {
            @Override
            public boolean apply(WebDriver input) {
              return !methods.isLoading(getWidgetElement(), getElement());
            }
          });
    }

    public List<Item> getChildren() {
      List<WebElement> childNodes = methods.getChildren(getWidgetElement(), getElement());
      List<Item> items = new ArrayList<Item>();
      for (WebElement childNode : childNodes) {
        items.add(new Item(childNode));
      }
      return items;
    }

    public boolean isLeaf() {
      return getChildren().isEmpty();
    }

    public Item getParent() {
      return new Item(methods.getParent(getWidgetElement(), getElement()));
    }
  }

  public Item findItemWithText(String text) {
    String escaped = escapeToString(text);
    return new Item(methods.getNodeElement(getElement(),
        getElement().findElement(By.xpath(".//*[contains(text()," + escaped + ")]"))));
  }

  public List<Item> getRootChildren() {
    List<WebElement> childNodes = methods.getRootChildren(getWidgetElement());
    List<Item> items = new ArrayList<Item>();
    for (WebElement child : childNodes) {
      items.add(new Item(child));
    }
    return items;
  }

  protected WebElement getWidgetElement() {
    return getElement();
  }
}

GXT 4.x