Subversion Repositories eFlore/Applications.coel

Rev

Rev 91 | 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.RegistreId;
import org.tela_botanica.client.interfaces.Rafraichissable;

import com.extjs.gxt.ui.client.Registry;
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.JSONValue;

public class ValeurListeAsyncDao {
        
        private Rafraichissable rafraichissement = null;
        
        public ValeurListeAsyncDao(Rafraichissable r) {
                rafraichissement = r;
        }
        
        public void obtenirListe(String cle) {
        // Demande de toutes les structures
        String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
                RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url+"CoelListe/id/"+cle);

                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) {
                                        final JSONValue responseValue = JSONParser.parse(response.getText());

                                        // Si la requête est un succès, reception d'un tableau
                                        if (responseValue.isArray() != null) {
                                                final JSONArray reponse = responseValue.isArray();
                                                // Transformation du tableau JSON réponse en Liste
                                                ValeurListe liste = new ValeurListe(reponse);
                                                // et on met à jour le demandeur des données
                                                rafraichissement.rafraichir(liste);
                                        }

                                }
                        });
                } catch (RequestException e) {
                        e.printStackTrace();
                }
        }
        public ValeurListeAsyncDao() {
                // TODO Auto-generated constructor stub
        }

}