GWT中TabLayoutPanel内的Celltable

时间:2014-06-02 05:26:07

标签: gwt gxt tabpanel gwt-celltable gwt-tablayoutpanel

我是GWT的新手。我一直在搜索样本,使用UIBinder在TabLayoutPanel选项卡中嵌入celltable。任何人都可以向我提供代码示例吗?谢谢。

1 个答案:

答案 0 :(得分:1)

我认为理解TabLayoutPanel和CellTable如何工作的最佳方式是阅读官方文档并查看官方示例。链接:

  • CellTable

http://www.gwtproject.org/doc/latest/DevGuideUiCellWidgets.html#celltable http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCellTable

  • TabLayoutPanel

http://www.gwtproject.org/doc/latest/DevGuideUiPanels.html http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwTabLayoutPanel

如果您想查看一个非常简单的示例,以了解将数据模型转换为UI元素的速度有多快,请参阅:

使用UiBinder示例更新了答案:

public class ExampleGWT implements EntryPoint {

  public void onModuleLoad() {
    MyTabPanel tab = new MyTabPanel();
    RootLayoutPanel.get().add(tab);
  }

}

-

public class MyTabPanel extends Composite {

    private static MyTabPanelUiBinder uiBinder = GWT.create(MyTabPanelUiBinder.class);
    interface MyTabPanelUiBinder extends UiBinder<Widget, MyTabPanel> {}

    @UiField
    TabLayoutPanel tabPanel;

    @UiField (provided=true)
    CellTable<Person> cellTable;

    public MyTabPanel() {

      cellTable = getCellTableWithData();

      initWidget(uiBinder.createAndBindUi(this));
      tabPanel.selectTab(0);
    }

    private CellTable<Person> getCellTableWithData() {

      CellTable<Person> cellTable = new CellTable<Person>();

      cellTable.setAutoHeaderRefreshDisabled(true);

      //You can set many params here  like:
      //   - auto refresh headers and footers
      //   - a List Data provider
      //   - page control
      //   - selection model for selecting cells
      //   
      //   An example in: 
      //       Click on "Source Code" in http://gwt.googleusercontent.com/samples/Showcase/Showcase.html#!CwCellTable

      // Name column.
      Column<Person, String> firstNameColumn = new Column<Person, String>(
          new EditTextCell()) {
        @Override
        public String getValue(Person object) {
          return object.getName();
        }
      };
      cellTable.addColumn(firstNameColumn, "Name");


      //age column
      Column<Person, String> age = new Column<Person, String>(
          new TextCell()) {

        @Override
        public String getValue(Person object) {
          return String.valueOf(object.getAge());
        }
      };
      cellTable.addColumn(age, "Age");


      //Adding data
      Person personOne = new Person("Foo", 26);
      Person personTwo = new Person("Name Foo", 31);
      List<Person> people = new ArrayList<Person>();
      people.add(personOne);
      people.add(personTwo);

      ListDataProvider<Person> dataProvider = new ListDataProvider<Person>();
      dataProvider.setList(people);
      dataProvider.addDataDisplay(cellTable);

      return cellTable;
    }
}

-

<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder 
    xmlns:ui="urn:ui:com.google.gwt.uibinder"
    xmlns:g="urn:import:com.google.gwt.user.client.ui"
    xmlns:c="urn:import:com.google.gwt.user.cellview.client">

  <ui:style>
    .tabPanelCss {
      margin: 10px;
    }

    .cellTableCss {
      background-color: yellow ;
    }
  </ui:style>

  <g:TabLayoutPanel ui:field="tabPanel" barHeight="2" barUnit="EM" addStyleNames='{style.tabPanelCss}'>
    <g:tab>
      <g:header>CellTable</g:header>
      <g:FlowPanel>
        <c:CellTable ui:field="cellTable" addStyleNames='{style.cellTableCss}'/>    
      </g:FlowPanel> 
    </g:tab>
  </g:TabLayoutPanel>   

</ui:UiBinder>

-

    public class Person {
        String name;
        int age;

        public Person(String name, int age) {
          super();
          this.name = name;
          this.age = age;
        }

        public String getName() {
          return name;
        }
        public void setName(String name) {
          this.name = name;
        }
        public int getAge() {
          return age;
        }
        public void setAge(int age) {
          this.age = age;
        }


    }