Subversion Repositories eFlore/Applications.cel

Rev

Rev 54 | Blame | 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 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;

/**
 * DAO d'accès a une observation
 * 
 * @author aurelien
 * 
 */
public class ImageGeneriqueVueAsynchroneDAO {

        /**
         * Le modele associé au DAO
         */
        private ObservationModele observationModele = null;

        public ImageGeneriqueVueAsynchroneDAO(ObservationModele obs) {
                observationModele = obs;
        }



        /**
         * Recherche Image  associee a un nom 
         * @param r
         * @param identifiant
         * @param numeroNomenclaturalSaisiObservation
         */
        
        public void obtenirURLImage(final Rafraichissable r, String numeroNomenclaturalSaisiObservation) {
        
                
                
                // on envoie le get asynchrone
                RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,observationModele.getConfig().getServiceBaseUrl()
                                +"/NameImage/"+numeroNomenclaturalSaisiObservation) ;
                
                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 responseValue = JSONParser.parse(response.getText());
                                        JSONArray reponse;
                                        String urlImage=null;
                                        String urlImageMax=null;

                                        if ((reponse = responseValue.isArray()) != null) {
                                                // Url Image
                                                urlImage= ((JSONString)reponse.get(0)).stringValue();
                                                urlImageMax= ((JSONString)reponse.get(1)).stringValue();
                                        }
                                        else {
                                                urlImage="";
                                                urlImageMax="";
                                        }
                                        
                                        r.rafraichir(new String[]{urlImage,urlImageMax},true);                          
                                }
                        }) ;

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

                        
}