I am trying to create simple cell browser in GWT but it displays blank.Here i have code that displays blank so please check
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开发者_如何学JAVA 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;
}
}
to show a cellBrowser you have to insert
@UiFactory CellBrowser makeCellBrowser() { // method name is insignificant
CellBrowser cellBrowser = new CellBrowser(treeModel, null);
return cellBrowser;
}
精彩评论