On Sunday, January 23, 2011 3:34:43 AM UTC-8, Tolwi wrote:
>
> Hi all
> I'm trying to implement simple search form like
>
> <ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
> xmlns:g="urn:import:com.google.gwt.user.client.ui"
> xmlns:c="urn:import:com.google.gwt.user.cellview.client">
>  <g:HTMLPanel>
> <g:TextBox ui:field="searchField"/>
> <g:Button ui:field="searchButton"> Search </g:Button>
> <c:CellTable ui:field='cellTable' /> 
> <c:SimplePager ui:field='pager'/>
> </g:HTMLPanel>
> </ui:UiBinder> 
>
> Assuming, that amount of data will be 
> ~1000000/(searchField.getValue().length()+1) rows I decided to use 
> AsyncDataProvider.
>
> My simple implementation of this form is the following
>
> public class SearchView extends Composite {
> private static SearchViewUiBinder uiBinder = 
> GWT.create(SearchViewUiBinder.class);
> interface SearchViewUiBinder extends UiBinder<Widget, SearchView> {}
>  @UiField(provided = true) SimplePager pager;
> @UiField CellTable<String> cellTable;
> @UiField TextBox searchField;
>  private AsyncDataProvider<String> dataProvider;
>
> public SearchView() {
> SimplePager.Resources pagerResources = 
> GWT.create(SimplePager.Resources.class);
> pager = new SimplePager(TextLocation.CENTER, pagerResources, false, 1, 
> true);
> initWidget(uiBinder.createAndBindUi(this));
> cellTable.addColumn(new TextColumn<String>() { // with one simple string 
> column
>
> @Override
> public String getValue(String object) {
> return object;
> }
> });
>  dataProvider = new AsyncDataProvider<String>() {
> private int callCount = 0; // lets count refresh calls
> @Override
> protected void onRangeChanged(HasData<String> display) {
> callCount++;
> String text = searchField.getValue();
> // fill result with dummy data
> List<String> data = new ArrayList<String>();
> int visibleItemCount = pager.getPageSize();
> for (int i = 0; i<visibleItemCount; i++){
> data.add("Search for '"+text+"' (callCount = "+callCount+")");
> }
>  display.setRowCount(1000000, true); // update row count (may be someone 
> has changed it!)
> display.setRowData(display.getVisibleRange().getStart(), data); // push dat 
> to the table
>  }
> };
> dataProvider.addDataDisplay(cellTable); *// POINT 1*
>
>  pager.setDisplay(cellTable);
>  // Grid needs to fit whole window
> Window.addResizeHandler(new ResizeHandler() { 
> public void onResize(ResizeEvent event) {
>     // -200 : search form + pager; 25 - row height
> pager.setPageSize((event.getHeight() - 200) / 25);  *// POINT 2*
> }
> });
>  }
>
> @UiHandler("searchButton")
> void onClick(ClickEvent e) {
> // validate input and refresh table (to the first page!)
> }
> }
>
> And with such simple form I already have problems:
>
> 1. onRangeChange event has been fired at POINT 1 and POINT 2 - but I want 
> to refresh the table manually for the first time (by pressing search button)
> (and I want to validate search text like (if (length()>0) {refresh()} else 
> {clear()}))
>
> My workaround - create local field like boolean refreshVetoed; and play 
> with it. With this solution I need to add setRowCount(0); to remove loading 
> indicator.
>

This seems reasonable.
 

> 2. there is no refresh() method neither in cellTable nor in dataProvider
> the only solution I have is the following:
>  Range currentRange = hasData.getVisibleRange();
> if (currentRange.getStart() != 0){
> cellTable.setVisibleRange(0, currentRange.getLength()); // it will refresh 
> the data only if the page is changed!
> } else {
> // call for data manually and set it to the table (even cant call 
> dataProvider.onRangeChanged() because it is not visible)
>  }
>
> Can someone explain me how to implement such a simple form correctly ????
>

There is no need for a refresh method.  setRowCount() and setRowData on a 
display is the way to refresh the table (display).  And dataProvider keeps a 
list of all displays, and displays know about their visible ranges.  Just 
iterate through all displays and refresh their visible ranges.

May be I'm not aware of all the tricks one can do with a CellTable, but your 
approach is what I would do in this scenario.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to