Gwt 如何用MVP模式创建CellTree

Gwt 如何用MVP模式创建CellTree,gwt,Gwt,正如gwt文档中所建议的,我在创建应用程序时尝试遵循MVP设计模式。当使用简单树时,文档中的描述是直截了当的,是MVP和gwt的好例子。在本例中,将创建视图,并将数据提供给要显示的视图。据我所知,这正是保持视图、模型和演示者分离的方法 使用CellTree,数据填充发生在TreeViewModel的数据提供程序中。数据提供者不能在单元树之外,因此我需要在视图中的单元树内部填充所有数据。现在,视图需要了解模型,MVP模式被打破。在将数据显示给用户之前,我不想动态地将数据填充到单元树中,我需要编辑单

正如gwt文档中所建议的,我在创建应用程序时尝试遵循MVP设计模式。当使用简单树时,文档中的描述是直截了当的,是MVP和gwt的好例子。在本例中,将创建视图,并将数据提供给要显示的视图。据我所知,这正是保持视图、模型和演示者分离的方法

使用CellTree,数据填充发生在TreeViewModel的数据提供程序中。数据提供者不能在单元树之外,因此我需要在视图中的单元树内部填充所有数据。现在,视图需要了解模型,MVP模式被打破。在将数据显示给用户之前,我不想动态地将数据填充到单元树中,我需要编辑单元树中的数据,然后将其保存为不同的格式


我的问题是如何在MVP设计模式中实现CellTree,或者在一般的CellWidget中?

我已经将CellTable与MVP结合使用

用户界面:


查看界面:

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);
    }
}
公共接口SomeCellListView扩展IsWidget{
void setPresenter(Presenter侦听器);
//方法设置单元格表数据
void setCellList(数组列表);
公共界面演示者{
无效后藤(地点);
无效剂量测定(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);
}
公共类SomeCellListViewImpl扩展复合实现SomeCellListView{
…所有的Ui活页夹都在这里
@UiField(提供的=真)
CellTablecellTable=新的CellTable();
SomeCellListViewImpl(){
TextColumn someColumn=新建TextColumn(){
@凌驾
公共字符串getValue(ObjectDTO){
返回o.getSomeFieldValue();
}
};
addColumn(someColumn,“column1”);
…在此处添加其他列
}
//从Presenter调用此方法以设置CellTable数据
公共无效集合单元列表(ArrayList列表){
cellTable.setRowCount(list.size(),true);
cellTable.setRowData(0,列表);
}
}

活动(或演示者):

//在构造函数中设置视图和服务(从ClientFactory获取视图)

public void start(AcceptsOneWidget containerWidget、EventBus和EventBus){

//进行RPC调用
这是服务
.getCellList(新的AsyncCallback(){
@凌驾
失败时的公共无效(可丢弃){
view.setError(“获取详细信息时出错”);
}
@凌驾
成功时公共无效(ArArrayList结果){
view.setCelllist(结果);
}
});
view.setPresenter(此);
containerWidget.setWidget(view.asWidget());
}

在这里,视图已经由ClientFactory创建。视图仅包含CellTable的布局。创建视图时不加载数据。当一个活动启动时(又名Presenter),就会调用“start”方法。在这里,我们使用RPC来获取单元格数据,并在视图中调用一个方法来设置数据


我没用过CellTree。但是你问了关于手机小部件的一般情况。因此,我想分享这个。希望这有帮助。

我对OP也有同样的问题。我阅读了MVP教程第二部分,然后尝试在我的应用程序中使用CellTable,同时仍然保留MVP架构师。但我在这一部分感到困惑:教程使用了类似Presenter的语法,但为什么只使用Presenter

   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);
}
// 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());