使用UiBinder创建CellBrowser

时间:2011-07-30 13:49:35

标签: gwt cellbrowser

我正在尝试在GWT中创建简单的单元格浏览器,但它显示为空白。这里我的代码显示为空白,请检查

import java.util.ArrayList;
import java.util.List;
import com.google.gwt.cell.client.AbstractCell;
import com.google.gwt.cell.client.Cell;
import com.google.gwt.core.client.GWT;
import com.google.gwt.safehtml.shared.SafeHtmlBuilder;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.user.cellview.client.CellBrowser;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Widget;
import com.google.gwt.view.client.ListDataProvider;
import com.google.gwt.view.client.SingleSelectionModel;
import com.google.gwt.view.client.TreeViewModel;
public class ContactCellBrowser extends Composite{

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

interface ContactCellBrowserUiBinder extends
        UiBinder<Widget, ContactCellBrowser> {
}

@UiField(provided=true)
CellBrowser cellBrowser;

@UiField
Label selectedLabel;

public ContactCellBrowser() {
    CustomTreeView treeModel=new CustomTreeView();
    cellBrowser=new  CellBrowser(treeModel, null);
    cellBrowser.setAnimationEnabled(true);
    initWidget(uiBinder.createAndBindUi(this));
}

private static class CustomTreeView implements TreeViewModel
{
    private final List<String> contacts;
    private final SingleSelectionModel<String> singleSelectionModel=new SingleSelectionModel<String>();

    public CustomTreeView() {
        contacts=new ArrayList<String>();
        for(int i=0;i<5;i++)
        {
            contacts.add("Name "+i);
        }
    }


    @Override
    public <T> NodeInfo<?> getNodeInfo(T value) {
        if(value==null)
        {
            ListDataProvider<String> dataProvider=new ListDataProvider<String>();

            for(int i=0;i<5;i++)
            {
                dataProvider.getList().add("Name "+i);
            }

            Cell<String> cell=new AbstractCell<String>() {

                @Override
                public void render(
                        com.google.gwt.cell.client.Cell.Context context,
                        String value, SafeHtmlBuilder sb) {
                    if(value!=null)
                    {
                        sb.appendEscaped(value);
                    }
                }
            };
            return new DefaultNodeInfo<String>(dataProvider, cell);
        }
        return null;
    }


    @Override
    public boolean isLeaf(Object value) {
        // The maximum length of a value is ten characters.
          return true;
    }

}

1 个答案:

答案 0 :(得分:0)

显示您必须插入的cellBrowser

@UiFactory CellBrowser makeCellBrowser() { // method name is insignificant
    CellBrowser cellBrowser = new CellBrowser(treeModel, null);
    return cellBrowser;
}