I am using GWT MVP and I would like to handle events in columns of DataGrid from Presenter. From GWT DataGrid ShowCase ...
// First name.
Column<ContactInfo, String> firstNameColumn =
new Column<ContactInfo, String>(new EditTextCell()) {
@Override
public String getValue(ContactInfo object) {
return object.getFirstName();
}
};
firstNameColumn.setSortable(true);
sortHandler.setComparator(firstNameColumn, new Comparator<ContactInfo>() {
@Override
public int compare(ContactInfo o1, ContactInfo o2) {
return o1.getFirstName().compareTo(o2.getFirstName());
}
});
dataGrid.addColumn(firstNameColumn, constants.cwDataGridColumnFirstName());
firstNameColumn.setFieldUpdater(new FieldUpdater<ContactInfo, String>() {
@Override
public void update(int index, ContactInfo object, String value) {
// Here I would like to call RPC methods
}
});
dataGrid.setColumnWidth(firstNameColumn, 20, Unit.PCT);
Above example , this code is writing in View side and it just really example. As mvp pattern , I just need to call rpc request to update database. This can't be done in View side but I have no idea how to set FieldUpdater from my presenter. Please help me how can I figure it out ? Thanks greatly .
There are two ways to do this (MVP I or MVP II way):
MVP 1 style:
http://www.gwtproject.org/articles/mvp-architecture.html
Create a
setter
on yourView
(i.e.setFieldUpdater(FieldUpdater<ContactInfo, String>)
) that takes aFieldUpdater
and adds it to the column. From thePresenter
you can call (provided thatview
is the reference to your View).Presenter:
MVP2 style:
http://www.gwtproject.org/articles/mvp-architecture-2.html
If you have a reference from your
View
back to yourPresenter
. Then you can call a function on yourPresenter
.View: