Subversion Repositories eFlore/Applications.coel

Rev

Rev 69 | Rev 113 | 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 {
20
 
21
	private Rafraichissable rafraichissement = null;
22
 
23
	public ValeurListeAsyncDao(Rafraichissable r) {
24
		rafraichissement = r;
25
	}
26
 
91 jpm 27
	public void obtenirListe(Integer cle) {
28
		// Demande de toutes les structures
69 jpm 29
    	String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
91 jpm 30
    	url = url+"CoelValeurListe/id/"+cle.toString();
31
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url);
32
		GWT.log(url, null);
69 jpm 33
		try {
34
			rb.sendRequest(null, new RequestCallback() {
35
 
36
				public void onError(Request request, Throwable exception) {
37
					// TODO Auto-generated method stub
38
 
39
				}
40
 
41
				public void onResponseReceived(Request request, Response response) {
91 jpm 42
 
69 jpm 43
					final JSONValue responseValue = JSONParser.parse(response.getText());
44
 
45
					// Si la requête est un succès, reception d'un tableau
91 jpm 46
					if (responseValue.isObject() != null) {
47
						try {
48
							final JSONObject reponse = responseValue.isObject();
49
							JSONString listeId = reponse.get("id").isString();
50
							JSONArray listeValeurs = reponse.get("valeurs").isArray();
51
							// Transformation du tableau JSON réponse en Liste
52
							ValeurListe liste = new ValeurListe(listeId, listeValeurs);
53
							// et on met à jour le demandeur des données
54
							rafraichissement.rafraichir(liste);
55
						} catch (NullPointerException e) {
56
							e.printStackTrace();
57
						}
69 jpm 58
					}
59
 
60
				}
61
			});
62
		} catch (RequestException e) {
63
			e.printStackTrace();
64
		}
65
	}
66
	public ValeurListeAsyncDao() {
67
		// TODO Auto-generated constructor stub
68
	}
69
 
70
}