1

As suggested in gwt documentation, I try to follow the MVP design pattern while creating my application. When using simple tree, the example in the documentation is straight forwards and makes good example of MVP and gwt. In the example the view is created and the data is given to the view to display. As far as I understand this is exactly the way to keep view, model and presenter separated.

With CellTree, the data populating happens inside the TreeViewModel's data provider. Data provider cannot be taken outside the cell tree and therefore I need to do all data populating inside the cell tree, which is in the view. Now, the view needs to know about the model and the MVP patter is broken. I wan't to dynamically populate data to the cell tree prior to showing it to user, I need to edit the data in cell tree and save it later for different format.

My question goes how to implement CellTree, or in general Cell widgets, in MVP design patter?

4

2 回答 2

2

我已经将 CellTable 与 MVP 一起使用。

用户界面:

<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 数据,并在视图中调用一个方法来设置数据。

我没有用过细胞树。但是您一般都询问了 Cell 小部件。因此想到分享这个。希望这可以帮助。

于 2012-05-09T17:01:10.367 回答
0

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

于 2012-05-12T02:27:15.020 回答