Changeset 670


Ignore:
Timestamp:
Apr 23, 2012, 2:58:46 PM (5 years ago)
Author:
mark9630@…
Message:

refactored activity for unit tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/code/conceptwiki/web/web-gwt/src/main/java/nl/nbic/conceptwiki/web/gwt/client/activity/SearchActivity.java

    r605 r670  
    3434    }
    3535   
     36    AcceptsOneWidget panel;
     37    EventBus eventBus;
     38    SearchView searchView;
     39
     40    AsyncCallback<ArrayList<SearchResult>> setResultsCallback = new setResultsCallbackClass();
     41   
     42    protected class setResultsCallbackClass implements AsyncCallback<ArrayList<SearchResult>> {
     43        @Override
     44        public void onSuccess(final ArrayList<SearchResult> results) {
     45               
     46                searchView.setCurrentQuery(query);
     47                if(! query.isEmpty()) {
     48                        searchView.setResults(results);
     49                }
     50            panel.setWidget(searchView.asWidget());
     51        }
     52        @Override
     53        public void onFailure(final Throwable caught) {
     54            Window.alert("We're terribly sorry, but something appears to have gone wrong while retrieving the search results");
     55        }
     56    };
     57
     58    //    protected class TextToServerCallback implements AsyncCallback<String> {
     59    //AsyncCallback<SearchView> viewCallback = new getViewCallback();
     60    protected class getResultsCallback implements AsyncCallback<SearchView> {
     61        @Override
     62        public void onSuccess(final SearchView view) {
     63                searchView = view;
     64            view.setPresenter(SearchActivity.this);
     65            view.reset();
     66           
     67            if (query.isEmpty()) {
     68                panel.setWidget(view.asWidget());
     69            } else {
     70                rpcService.searchConcepts(query, 20, 0, setResultsCallback);
     71            }
     72        }
     73       
     74        @Override
     75        public void onFailure(Throwable caught) {
     76            Window.alert("We're terribly sorry, but something appears to have gone wrong while creating the search page");
     77        }
     78    };
     79       
    3680    public void start(final AcceptsOneWidget panel, final EventBus eventBus) {
    37         injector.getSearchView().get(new AsyncCallback<SearchView>() {
    38             @Override
    39             public void onSuccess(final SearchView view) {
    40                 view.setPresenter(SearchActivity.this);
    41                 view.reset();
    42                
    43                 if (query.isEmpty()) {
    44                     panel.setWidget(view.asWidget());
    45                 } else {
    46                     rpcService.searchConcepts(query, 20, 0, new AsyncCallback<ArrayList<SearchResult>>() {
    47                         @Override
    48                         public void onSuccess(final ArrayList<SearchResult> results) {
    49                                
    50                                 view.setCurrentQuery(query);
    51                                 if(! query.isEmpty()) {
    52                                         view.setResults(results);
    53                                 }
    54                             panel.setWidget(view.asWidget());
    55                         }
    56                         @Override
    57                         public void onFailure(final Throwable caught) {
    58                             Window.alert("We're terribly sorry, but something appears to have gone wrong while retrieving the search results");
    59                         }
    60                     });
    61                 }
    62             }
    63            
    64             @Override
    65             public void onFailure(Throwable caught) {
    66                 Window.alert("We're terribly sorry, but something appears to have gone wrong while creating the search page");
    67             }
    68         });
     81        this.panel = panel;
     82        this.eventBus = eventBus;
     83        injector.getSearchView().get(new getResultsCallback());
    6984    }
    7085
Note: See TracChangeset for help on using the changeset viewer.