Subversion Repositories eFlore/Applications.coel

Rev

Rev 268 | Rev 299 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
69 jpm 1
package org.tela_botanica.client.modeles;
2
 
3
import org.tela_botanica.client.RegistreId;
4
import org.tela_botanica.client.interfaces.Rafraichissable;
5
 
6
import com.extjs.gxt.ui.client.Registry;
91 jpm 7
import com.google.gwt.core.client.GWT;
69 jpm 8
import com.google.gwt.http.client.Request;
9
import com.google.gwt.http.client.RequestBuilder;
10
import com.google.gwt.http.client.RequestCallback;
11
import com.google.gwt.http.client.RequestException;
12
import com.google.gwt.http.client.Response;
13
import com.google.gwt.json.client.JSONArray;
91 jpm 14
import com.google.gwt.json.client.JSONObject;
69 jpm 15
import com.google.gwt.json.client.JSONParser;
91 jpm 16
import com.google.gwt.json.client.JSONString;
69 jpm 17
import com.google.gwt.json.client.JSONValue;
18
 
19
public class ValeurListeAsyncDao {
268 jp_milcent 20
	private static final String SERVICE_NOM = "CoelValeurListe";
292 gduche 21
	private String strPays;
69 jpm 22
 
292 gduche 23
 
268 jp_milcent 24
	private Rafraichissable vue = null;
69 jpm 25
 
268 jp_milcent 26
	public ValeurListeAsyncDao() {
27
		// TODO Auto-generated constructor stub
69 jpm 28
	}
29
 
268 jp_milcent 30
	public ValeurListeAsyncDao(Rafraichissable vueARafraichir) {
31
		vue = vueARafraichir;
32
	}
33
 
292 gduche 34
	public ValeurListeAsyncDao(Rafraichissable vueARafraichir, String strPays) {
35
		vue = vueARafraichir;
36
		this.strPays = strPays;
37
	}
38
 
91 jpm 39
	public void obtenirListe(Integer cle) {
40
		// Demande de toutes les structures
69 jpm 41
    	String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
292 gduche 42
    	if (strPays != null)	{
43
    		url = url + SERVICE_NOM + "/abv/" + strPays + "/" + cle.toString();
44
    		System.out.println(url);
45
    	}	else {
46
    		url = url + SERVICE_NOM + "/id/" + cle.toString();
47
    	}
91 jpm 48
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
113 jpm 49
		//GWT.log(url, null);
69 jpm 50
		try {
51
			rb.sendRequest(null, new RequestCallback() {
52
 
53
				public void onError(Request request, Throwable exception) {
54
					// TODO Auto-generated method stub
55
 
56
				}
57
 
58
				public void onResponseReceived(Request request, Response response) {
91 jpm 59
 
69 jpm 60
					final JSONValue responseValue = JSONParser.parse(response.getText());
61
 
62
					// Si la requête est un succès, reception d'un tableau
91 jpm 63
					if (responseValue.isObject() != null) {
64
						try {
65
							final JSONObject reponse = responseValue.isObject();
66
							JSONString listeId = reponse.get("id").isString();
67
							JSONArray listeValeurs = reponse.get("valeurs").isArray();
68
							// Transformation du tableau JSON réponse en Liste
69
							ValeurListe liste = new ValeurListe(listeId, listeValeurs);
70
							// et on met à jour le demandeur des données
268 jp_milcent 71
							vue.rafraichir(liste);
91 jpm 72
						} catch (NullPointerException e) {
73
							e.printStackTrace();
74
						}
69 jpm 75
					}
76
 
77
				}
78
			});
79
		} catch (RequestException e) {
80
			e.printStackTrace();
81
		}
82
	}
292 gduche 83
 
84
 
69 jpm 85
}