2011-07-30 67 views
0

我想在GWT創建簡單的細胞器,但它顯示blank.Here,我有一個顯示空白的代碼,所以請創建CellBrowser使用UiBinder的

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; 
    } 

} 

回答

0

表明您必須插入

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