开发者

gwt celltable not working with uibinder

I got the following code from http://robin.mytechtip.com/2010/11/17/gwt-celltable-example-using-asyncdataprovider/#comment-920. I am trying to get it to work with uibinder. The result is that all data is shown in the celltable and therefore the simplePager navigation is disabled.

package com.example.random.client.view;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

import com.example.random.shared.Contact;
import com.google.gwt.cell.client.DateCell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.Column;
import com.google.gwt.user.cellview.client.SimplePager;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.AsyncDataProvider;
import com.google.gwt.view.client.HasData;

public class HtmlBinder extends Composite {

    private static HtmlBinderUiBinder uiBinder = GWT
            .create(HtmlBinderUiBinder.class);

    interface HtmlBinderUiBinder extends UiBinder<Widget, HtmlBinder> {
    }

    @SuppressWarnings("deprecation")
    private static final List<Contact> CONTACTS = Arrays.asList(new Contact(
            "John", new Date(80, 4, 12), "123 Abc Avenue"), new Contact("Joe",
            new Date(85, 2, 22), "22 Lance Ln"), new Contact("Tom", new Date(
            85, 3, 22), "33 Lance Ln"), new Contact("Jack",
            new Date(85, 4, 22), "44 Lance Ln"), new Contact("Tim", new Date(
            85, 5, 22), "55 Lance Ln"), new Contact("Mike",
            new Date(85, 6, 22), "66 Lance Ln"), new Contact("George",
            new Date(46, 6, 6), "77 Lance Ln"));

    /**
     * The main CellTable.
     */
    @UiField(provided = true)
    CellTable<Contact> cellTable;

    /**
     * The pager used to change the range of data.
     */
    @UiField(provided = true)
    SimplePager pager;

    public HtmlBinder() {
        pager = new SimplePager();
        cellTable = new CellTable<Contact>(3);
        initWidget(uiBinder.createAndBindUi(this));
        setupCellTable();
        setupSimplePager();
    }

    private void setupSimplePager() {
        pager.setDisplay(cellTable);
    }

    private void setupCellTable() {
        // Add a text column to show the name.
        TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
            @Override
            public String getValue(Contact object) {
                return object.getName();
            }
        };
        cellTable.addColumn(nameColumn, "Name");

        // Add a date column to show the birthday.
        DateCell dateCell = new DateCell();
        Column<Contact, Date> dateColumn = new Column<Contact, Date>(dateCell) {
            @Override
            public Date getValue(Contact object) {
                return object.getBirthday();
            }
        };
        cellTable.addColumn(dateColumn, "Birthday");

        // Add a text column to show the address.
        TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
            @Override
            public String getValue(Contact object) {
                return object.getAddress();
            }
        };
        cellTable.addColumn(addressColumn, "Address");

        // Associate an async data provider to the table
        // XXX: Use AsyncCallback in the method onRangeChanged
        // to actaully get the data from the server side
        AsyncDataProvider<Contac开发者_JAVA百科t> provider = new AsyncDataProvider<Contact>() {
            @Override
            protected void onRangeChanged(HasData<Contact> display) {
                int start = display.getVisibleRange().getStart();
                int end = start + display.getVisibleRange().getLength();
                end = end >= CONTACTS.size() ? CONTACTS.size() : end;
                List<Contact> sub = CONTACTS.subList(start, end);
                updateRowData(start, sub);
            }
        };
        provider.addDataDisplay(cellTable);
        provider.updateRowCount(CONTACTS.size(), true);
    }
}

Entrypoint ...

public void onModuleLoad() {
        RootLayoutPanel.get().add(new HtmlBinder());
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜