Ok so I added a pager to the users list in the GXT example to test GXT
proxy, BeanModelReader/BeanFactory & Loader.
/* Presenter */
public class UserListPresenter extends
Presenter<UserListViewInterface> {
//private static BeanModelFactory factory = BeanModelLookup.get
().getFactory( UserBean.class );
protected int indexSelected = -1;
private UserServiceAsync service = null;
private PagingLoader<PagingLoadResult<ModelData>> loader = null;
private ListStore<BeanModel> store = null;
@SuppressWarnings( "unchecked" )
@Override
public void bind() {
RpcProxy<PagingLoadResult<UserBean>> proxy = new
RpcProxy<PagingLoadResult<UserBean>>() {
public void load( Object loadConfig,
AsyncCallback<PagingLoadResult<UserBean>> callback ) {
service.getUsers( (PagingLoadConfig)loadConfig, callback );
}
};
// loader
loader = new BasePagingLoader<PagingLoadResult<ModelData>>( proxy,
new BeanModelReader() );
store = new ListStore<BeanModel>( loader );
view.getToolBar().bind( loader );
view.buildWidget( store );
...
}
public void onStart() {
eventBus.dispatch( EventsEnum.CHANGE_TOP_WIDGET, view.getViewWidget
() );
loader.load(0, 4);
...
}
}
/* View */
public class UserListView extends ContentPanel implements
UserListViewInterface, MyWidgetInterface {
private MySimpleGXTButton delete = new MySimpleGXTButton( "Delete" );
private MySimpleGXTButton newButton = new MySimpleGXTButton( "New" );
private MySimpleGXTButton yes = new MySimpleGXTButton( "Yes" );
private MySimpleGXTButton no = new MySimpleGXTButton( "No" );
private MyLabel confirmText = new MyLabel( "Are you Sure?" );
private MyGXTTable userList = null;
private MyGXTPagingToolBar toolBar = new MyGXTPagingToolBar( 4 );
public UserListView() {
setBodyBorder( false );
setHeading( "Users" );
setButtonAlign( HorizontalAlignment.CENTER );
HorizontalPanel buttons = new HorizontalPanel();
buttons.setSpacing( 4 );
buttons.add( delete );
buttons.add( newButton );
buttons.add( confirmText );
buttons.add( yes );
buttons.add( no );
add( buttons );
setBottomComponent( toolBar );
}
public void buildWidget( ListStore<BeanModel> store ) {
List<ColumnConfig> configs = new ArrayList<ColumnConfig>();
configs.add( new ColumnConfig( "username", "Username", 150 ) );
configs.add( new ColumnConfig( "firstName", "First Name", 150 ) );
configs.add( new ColumnConfig( "lastName", "Last Name", 150 ) );
configs.add( new ColumnConfig( "email", "Email", 150 ) );
configs.add( new ColumnConfig( "department", "Department", 150 ) );
ColumnModel cm = new ColumnModel( configs );
userList = new MyGXTTable( store, cm );
userList.setBorders( true );
userList.setAutoHeight( true );
userList.setStripeRows( true );
add( userList );
}
...
}
I added the proxy to the presenter because proxy needs to have access
to services and only the presenter must know the services.
I also added to the presenter:
-the loader because this class is part of the business, not of the
display
-the ListStore because I think it will be easier to have the same
model for the presenter and GXT widgets (even if in the MVP model only
the presenter is supposed to have access to it).
The problem I had is that I had to delay the construction of the grid
(MyGXTTable extends GXT Grid) because to build the grid, I needed to
build the proxy and the loader first. That's why I had to create the
buildWidget method.
I commited the changes under
http://code.google.com/p/mvp4g/source/browse/#svn/trunk/examples/EmployeeAdminWithGXT
The one thing I don't like with this solution is that I can't test it
directly with JUnit because
Loader calls BeanModelReader that calls GWT.create(-) at one point.
I'm gonna try to see if I can resolve the problem using
GWTMockUtilities.
> GXT example >>>
http://www.extjs.com/blog/2008/07/14/preview-java-bean-support-with-e...
> ...
>
> read more »- Hide quoted text -