我正在尝试在 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;
}
}