Subversion Repositories eFlore/Applications.coel

Rev

Rev 91 | Go to most recent revision | Details | 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;
7
import com.google.gwt.http.client.Request;
8
import com.google.gwt.http.client.RequestBuilder;
9
import com.google.gwt.http.client.RequestCallback;
10
import com.google.gwt.http.client.RequestException;
11
import com.google.gwt.http.client.Response;
12
import com.google.gwt.json.client.JSONArray;
13
import com.google.gwt.json.client.JSONParser;
14
import com.google.gwt.json.client.JSONValue;
15
 
16
public class ValeurListeAsyncDao {
17
 
18
	private Rafraichissable rafraichissement = null;
19
 
20
	public ValeurListeAsyncDao(Rafraichissable r) {
21
		rafraichissement = r;
22
	}
23
 
24
	public void obtenirListe(String cle) {
25
    	// Demande de toutes les structures
26
    	String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
27
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url+"CoelListe/id/"+cle);
28
 
29
		try {
30
			rb.sendRequest(null, new RequestCallback() {
31
 
32
				public void onError(Request request, Throwable exception) {
33
					// TODO Auto-generated method stub
34
 
35
				}
36
 
37
				public void onResponseReceived(Request request, Response response) {
38
					final JSONValue responseValue = JSONParser.parse(response.getText());
39
 
40
					// Si la requête est un succès, reception d'un tableau
41
					if (responseValue.isArray() != null) {
42
						final JSONArray reponse = responseValue.isArray();
43
						// Transformation du tableau JSON réponse en Liste
44
						ValeurListe liste = new ValeurListe(reponse);
45
						// et on met à jour le demandeur des données
46
						rafraichissement.rafraichir(liste);
47
					}
48
 
49
				}
50
			});
51
		} catch (RequestException e) {
52
			e.printStackTrace();
53
		}
54
	}
55
	public ValeurListeAsyncDao() {
56
		// TODO Auto-generated constructor stub
57
	}
58
 
59
}