Subversion Repositories eFlore/Applications.cel

Rev

Rev 147 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.client.modeles;

import org.tela_botanica.client.CarnetEnLigneModele;
import org.tela_botanica.client.interfaces.Rafraichissable;
import com.google.gwt.http.client.Request;
import com.google.gwt.http.client.RequestBuilder;
import com.google.gwt.http.client.RequestCallback;
import com.google.gwt.http.client.RequestException;
import com.google.gwt.http.client.Response;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONParser;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
import com.google.gwt.user.client.Window;

public class ListeUtilisateurAsynchroneDAO {

        CarnetEnLigneModele cModele = null ;
        
        public ListeUtilisateurAsynchroneDAO(CarnetEnLigneModele carnetEnLigneModele) {
                cModele = carnetEnLigneModele ;
        }
        
        public final void obtenirListeUtilisateur(final Rafraichissable r,final String rech, final String utilisateur) {
                
                RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, Configuration.getServiceBaseUrl() + "/InventoryUserList/" + utilisateur+"/"+rech);
                
        
                try {
                        
                        rb.sendRequest(null, new RequestCallback() {

                                public void onError(final Request request, final Throwable exception) {
                                        // TODO Auto-generated method stub
                                        
                                }

                                public void onResponseReceived(final Request request,
                                                final Response response) {
                                        
                                        String[][] util ;
                                        
                                        final JSONValue responseValue = JSONParser.parse(response.getText());
                                        JSONArray reponse = responseValue.isArray();
                                        
                                        if(reponse != null) {
                                                
                                                util = new String[reponse.size()][1];
                                                
                                                for(int i = 0; i < reponse.size() ; i++) {
                                                        
                                                         JSONString item = reponse.get(i).isString(); 
                                                        
                                                        if(item != null) {
                                                                util[i][0] = item.stringValue();
                                                        }
                                                }
                                        }
                                        else {
                                                util = new String[0][1];
                                        }
                                        
                                        r.rafraichir(util, true);
                                }       
                        });
                        
                } catch (RequestException e) {
                        
                        e.printStackTrace();
                }
                
        }

}