Probably you registered more than one the handler.
On 19 October 2014 14:11, Grisha Shoihet <[email protected]> wrote:
> hello,
>
> I am new in GWT and try to implement AsyncDataProvider with DataGrid and
> SimplePager.
> All working as expected except strange behavior
> in SearchResultsAsyncDataProvider.
> I need to update DataGrid each time with new results and it is working ,
> but when I try to use pagination seems that DataGrid fire events for all
> previous results also(maybe its related to history mechanism).
>
> Please advice if you have any idea?
> I use mvp with activities and places parent.
>
> public class SearchResultsAsyncDataProvider extends
> AsyncDataProvider<SearchDocument> {
>
> Logger logger = Logger.getLogger("SearchResultsAsyncDataProvider");
> private final ClientFactory clientFactory;
> private String searchQuery = null;
>
> public SearchResultsAsyncDataProvider(String searchQuery,final
> ClientFactory clientFactory) {
> this.searchQuery = searchQuery;
> this.clientFactory = clientFactory;
> }
>
> /**
> * {@link #onRangeChanged(HasData)} is called when the table requests a new
> * range of data. You can push data back to the displays using
> * {@link #updateRowData(int, List)}.
> */
> @Override
> protected void onRangeChanged(HasData<SearchDocument> display) {
>
> *//here i expect to once access...*
>
> }
>
> ---------------------------------------------------------------------------------------------------------------------------------------------------------------
> public class SearchResultsViewImpl extends Composite implements
> SearchResultsView{
>
> private static SearchResultsViewImplUiBinder uiBinder =
> GWT.create(SearchResultsViewImplUiBinder.class);
>
> interface SearchResultsViewImplUiBinder extends UiBinder<Widget,
> SearchResultsViewImpl> {}
>
> @UiField
> Label labelInformation;
> @UiField(provided = true)
> DataGrid<SearchDocument> dataGridSearchResults;
> @UiField(provided = true)
> SimplePager simplePagerSearchResults;
> private SearchResultsPresenter searchResultsPresenter;
> private SearchResultsAsyncDataProvider searchResultsAsyncDataProvider;
> private final String COLUMN_NAME = "Name";
> private TextColumn<SearchDocument> columnName;
>
> public SearchResultsViewImpl()
> {
> this.dataGridSearchResults = new DataGrid<SearchDocument>();
> this.dataGridSearchResults.setEmptyTableWidget(new Label("No Data to
> Display"));
> this.simplePagerSearchResults = new SimplePager();
> initWidget(uiBinder.createAndBindUi(this));
> //this.setSize("500px", "500px");
> this.dataGridSearchResults.setSize("500px","500px");
> this.buildGrid();
> }
>
> private void buildGrid()
> {
> // Build each of the 7 columns
> columnName = buildColumnName();
>
> // Add the columns to the widget
> this.dataGridSearchResults.addColumn(columnName,
> buildHeader(COLUMN_NAME), buildHeader(COLUMN_NAME));
>
> this.dataGridSearchResults.setColumnWidth(0, 60, Unit.PX);
> // Make efficient for IE
> //this.dataGridSearchResults.setSkipRowHoverCheck(true);
> //this.dataGridSearchResults.setSkipRowHoverFloatElementCheck(true);
> //this.dataGridSearchResults.setSkipRowHoverStyleUpdate(true);
> }
> private TextColumn<SearchDocument> buildColumnName()
> {
> columnName = new TextColumn<SearchDocument>()
> {
> @Override
> public String getValue(SearchDocument object)
> {
> return object.getName();
> }
> };
> columnName.setDataStoreName(COLUMN_NAME);
> columnName.setHorizontalAlignment(HasHorizontalAlignment.ALIGN_LEFT);
> columnName.setVerticalAlignment(HasVerticalAlignment.ALIGN_TOP);
> return columnName;
> }
> private Header<String> buildHeader(final String text){
> Header<String> head = new Header<String>(new TextCell()){
> @Override
> public String getValue() {
> return text;
> }
> };
> return head;
> }
>
> private void addColumnSortAsyncHandling() {
> columnName.setSortable(true);
> // columnTitle.setSortable(true);
> // columnDate.setSortable(true);
>
> ColumnSortEvent.AsyncHandler columnSortHandler =
> new ColumnSortEvent.AsyncHandler(this.dataGridSearchResults);
> this.dataGridSearchResults.addColumnSortHandler(columnSortHandler);
> }
> private void createAsyncDataProvider() {
> this.searchResultsAsyncDataProvider =
> new SearchResultsAsyncDataProvider(
> this.searchResultsPresenter.getSearchQuery(),
> this.searchResultsPresenter.getClientFactory());
> this.dataGridSearchResults.setVisibleRangeAndClearData(new Range(0,15),
> true);
> //this.dataGridSearchResults.setPageSize(15);
> this.simplePagerSearchResults.setDisplay(this.dataGridSearchResults);
> this.simplePagerSearchResults.startLoading();
>
> this.searchResultsAsyncDataProvider.addDataDisplay(this.dataGridSearchResults);
> //call presenter here to get estimation from db for update row count
> this.searchResultsAsyncDataProvider.updateRowCount(55, true);
> this.labelInformation.setText("Search results for :
> \""+this.searchResultsPresenter.getSearchQuery()+"\"");
> //addColumnSortAsyncHandling();
> }
>
> @Override
> public void reset() {
> this.createAsyncDataProvider();
> }
>
> @Override
> public void setSearchResultsPresenter(
> SearchResultsPresenter searchResultsPresenter) {
> this.searchResultsPresenter = searchResultsPresenter;
> }
> }
>
> ---------------------------------------------------------------------------------------------------------------------------------------------------
>
> public class SearchResultsActivity extends AbstractActivity implements
> SearchResultsPresenter{
>
> // Used to obtain views, eventBus, placeController
> private final ClientFactory clientFactory;
> private SearchResultsView searchResultsView = null;
> private SearchResultsPlace searchResultsPlace = null;
> public SearchResultsActivity(SearchResultsPlace searchResultsPlace,
> final ClientFactory clientFactory){
> this.clientFactory = clientFactory;
> this.searchResultsPlace = searchResultsPlace;
> }
> @Override
> public void start(AcceptsOneWidget panel, EventBus eventBus) {
> //reset view here . clear adapter set new keyword etc...
> this.searchResultsView = this.clientFactory.getSearchResultsView(this);
> this.searchResultsView.reset();
> panel.setWidget(this.searchResultsView.asWidget());
> }
> @Override
> public void goTo(Place place) {
> this.clientFactory.getPlaceController().goTo(place);
> }
>
> @Override
> public ClientFactory getClientFactory() {
> return this.clientFactory;
> }
>
> @Override
> public String getSearchQuery() {
> return this.searchResultsPlace.getValue();
> }
> }
>
> --------------------------------------------------------------------------------------------------------------------------------
>
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Web Toolkit" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/google-web-toolkit.
> For more options, visit https://groups.google.com/d/optout.
>
--
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-web-toolkit.
For more options, visit https://groups.google.com/d/optout.