我已經使用了CellTable和MVP。
UI:
<g:HTMLPanel>
<g:ScrollPanel>
<p1:CellTable ui:field="cellTable" width="100%" styleName="style.cellTable" height="100%" />
</g:ScrollPanel>
</g:HTMLPanel>
查看界面:
public interface SomeCellListView extends IsWidget {
void setPresenter(Presenter listener);
// Method to set the CellTable data
void setCellList(ArrayList<ObjectDTO> list);
public interface Presenter {
void goTo(Place place);
void doSomething(int id);
}
}
視圖實現:
public class SomeCellListViewImpl extends Composite implements SomeCellListView {
... all Ui Binder stuff here
@UiField(provided = true)
CellTable<ObjectDTO>cellTable = new CellTable<ObjectDTO>();
SomeCellListViewImpl(){
TextColumn<ObjectDTO> someColumn= new TextColumn<ObjectDTO>(){
@Override
public String getValue(ObjectDTO o) {
return o.getSomeFieldValue();
}
};
cellTable.addColumn(someColumn, "column1");
... add other columns here
}
// This method is called from Presenter to set CellTable data
public void setCellList(ArrayList<ObjectDTO> list) {
cellTable.setRowCount(list.size(), true);
cellTable.setRowData(0, list);
}
}
活性(或演示者):
//在構造函數中設置視圖和服務(獲取從ClientFactory視圖)
公共無效啓動(AcceptsOneWidget containerWidget,EventBus eventBus){
// Make RPC call
this.service
.getCellList(new AsyncCallback<ArrayList<ObjectDTO>>(){
@Override
public void onFailure(Throwable caught) {
view.setError("Error fetching details");
}
@Override
public void onSuccess(ArArrayList<ObjectDTO> result) {
view.setCelllist(result);
}
});
view.setPresenter(this);
containerWidget.setWidget(view.asWidget());
}
這裏,視圖已由ClientFactory創建。 View只包含CellTable的佈局。數據未在創建視圖時加載。當一個Activity開始時(又名Presenter),調用「start」方法。這裏我們讓RPC獲取Cell數據並調用視圖中的方法來設置數據。
我還沒用過CellTree。但是你總體上詢問了Cell小部件。因此想到分享這個。希望這可以幫助。