Example usage for com.google.gwt.view.client AsyncDataProvider updateRowCount

List of usage examples for com.google.gwt.view.client AsyncDataProvider updateRowCount

Introduction

In this page you can find the example usage for com.google.gwt.view.client AsyncDataProvider updateRowCount.

Prototype

@Override
    public void updateRowCount(int size, boolean exact) 

Source Link

Usage

From source file:com.mycompany.celltableexmaple.client.CellTableExample.java

License:Open Source License

public void onModuleLoad() {
    // Create a CellTable.
    final CellTable<GalleryApp> galleryTable = new CellTable<GalleryApp>();
    // Display 3 rows in one page
    galleryTable.setPageSize(5);/*from ww w.  j  a  va  2s.  c  om*/

    // Add a text column to show the title.
    TextColumn<GalleryApp> titleColumn = new TextColumn<GalleryApp>() {
        @Override
        public String getValue(GalleryApp object) {
            return object.title;
        }
    };
    galleryTable.addColumn(titleColumn, "Title");

    // Add a text column to show the title.
    TextColumn<GalleryApp> descColumn = new TextColumn<GalleryApp>() {
        @Override
        public String getValue(GalleryApp object) {
            return object.description;
        }
    };
    galleryTable.addColumn(descColumn, "Description");

    // Add a text column to show the address.
    TextColumn<GalleryApp> imageColumn = new TextColumn<GalleryApp>() {
        @Override
        public String getValue(GalleryApp object) {
            return object.image;
        }
    };
    galleryTable.addColumn(imageColumn, "Image URL");

    /*
     * Associate an async data provider to the table.
     */
    AsyncDataProvider<GalleryApp> provider = new AsyncDataProvider<GalleryApp>() {
        //      @Override
        //       /*
        //        * The default event listener which involves no remote data handling,
        //        * replace the onRangeChanged below with this for a simpler demo.
        //        */
        //      protected void onRangeChanged(HasData<GalleryApp> display) {
        //        int start = display.getVisibleRange().getStart();
        //        int end = start + display.getVisibleRange().getLength();
        //        end = end >= GALLERYAPPS.size() ? GALLERYAPPS.size() : end;
        //        List<GalleryApp> sub = GALLERYAPPS.subList(start, end);
        //        updateRowData(start, sub);
        //      }

        @Override
        /*
         * Event handler that will grab data from remote server in async fashion
         * @see com.google.gwt.view.client.AbstractDataProvider#onRangeChanged(com.google.gwt.view.client.HasData)
         */
        protected void onRangeChanged(HasData<GalleryApp> display) {
            final int start = display.getVisibleRange().getStart();
            int length = display.getVisibleRange().getLength();
            AsyncCallback<List<GalleryApp>> callback = new AsyncCallback<List<GalleryApp>>() {
                @Override
                public void onFailure(Throwable caught) {
                    Window.alert(caught.getMessage());
                }

                @Override
                public void onSuccess(List<GalleryApp> result) {
                    // The result here will be the returned value in the async callback
                    updateRowData(start, result);
                }
            };
            // The remote service that should be implemented
            greetingService.getApps(start, length, callback);
        }
    };

    provider.addDataDisplay(galleryTable);
    provider.updateRowCount(GALLERYAPPS.size(), true);

    SimplePager pager = new SimplePager();
    pager.setDisplay(galleryTable);

    VerticalPanel vp = new VerticalPanel();
    vp.add(galleryTable);
    vp.add(pager);

    // Add it to the root panel.
    RootPanel.get().add(vp);
}