Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GWT MVP with a table

Tags:

mvp

gwt

When working with MVP in GWT how would you work with a table? For example if you had a table of users does your view look like this?

public interface MyDisplay{

HasValue<User> users();

}

or would it be more like this?

public interface MyDisplay{

HasValue<TableRow> rows();

}

MVP makes a ton of sense until you start dealing with widgets that need to display lists of non-primitive data. Can anybody shed some light?

This mailing list archive appears to ask the same question but never reaches a solid resolution...

http://www.mail-archive.com/[email protected]/msg24546.html

like image 893
benstpierre Avatar asked Sep 22 '09 18:09

benstpierre


1 Answers

HasValue<User> or HasValue<TableRow> would not work in this case, because this would only permit handling a single row. You could maybe use a HasValue<List<User>> but that would mean, that your view has to render the entire table on each change.

I might be wrong, but I think for tables its best to use a Supervising Presenter instead of the Passive View. Have a look at the PagingScrollTable widget in the GWT Incubator:

public class PagingScrollTable<RowType> extends AbstractScrollTable implements
    HasTableDefinition<RowType>, ... {
  ...
  TableModel<RowType> getTableModel() 
  ...
}

For a PagingScrollTable, a MutableTableModel<RowType> is used as implementation of TableModel<RowType>.

MutableTableModel<RowType> in turn implements the following interfaces:

HasRowCountChangeHandlers, HasRowInsertionHandlers, HasRowRemovalHandlers, HasRowValueChangeHandlers<RowType>

The PagingScrollTable registers itself as listener on the MutableTableModel and therefore gets very fine-grained notifications of updates. The resulting implementation should be very performant.

like image 134
Nightscape Avatar answered Oct 31 '22 04:10

Nightscape