Subversion Repositories eFlore/Applications.cel

Rev

Rev 140 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

package org.tela_botanica.client.modeles;

import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.observation.ObservationModele;
import org.tela_botanica.client.util.Util;

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 NomRetenuAsynchroneDao {

        private ObservationModele oModele = null ;
        
        public NomRetenuAsynchroneDao(ObservationModele observationModele) {
                oModele = observationModele ;
        }

        public void obtenirNomRetenu(final Rafraichissable r, final String anum) {
                
                RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,
                                Configuration.getServiceBaseUrl()
                                + "/name/"+anum);

                try {
                        rb.sendRequest(null, new RequestCallback() {

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

                                public void onResponseReceived(Request request,
                                                Response response) {
                                        
                                        JSONValue jsonValue = JSONParser.parse(response.getText());
                    JSONArray jsonArray;

                    if ((jsonArray = jsonValue.isArray()) != null) {
   
                            String aname = Util.toCelString(((JSONString) jsonArray.get(0)).toString());
                           
                            // Nom
                            if (aname.compareTo("null")!=0) {
                                
                                String[] numNom = {aname, anum } ;
                                r.rafraichir(numNom, false);
                            }
                       
                    }
                }
                        });

                } catch (RequestException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                }
        
                
        }

}