Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
60 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
 
69 jpm 16
public class StructureListeAsyncDao {
60 jpm 17
 
69 jpm 18
	private StructureListe institutions = null;
60 jpm 19
	private Rafraichissable rafraichissement = null;
20
 
69 jpm 21
	public StructureListeAsyncDao(Rafraichissable r) {
60 jpm 22
		rafraichissement = r;
23
	}
24
 
25
	public void obtenirListeInstitution() {
26
    	// Demande de toutes les structures
27
    	String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
28
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url+"CoelStructureListe/");
29
 
30
		try {
31
			rb.sendRequest(null, new RequestCallback() {
32
 
33
				public void onError(Request request, Throwable exception) {
34
					// TODO Auto-generated method stub
35
 
36
				}
37
 
38
				public void onResponseReceived(Request request, Response response) {
39
					final JSONValue responseValue = JSONParser.parse(response.getText());
40
 
41
					// Si la requête est un succès, reception d'un tableau
42
					if (responseValue.isArray() != null) {
43
						final JSONArray reponse = responseValue.isArray();
44
						// Transformation du tableau JSON réponse en ListeInstitution
69 jpm 45
						institutions = new StructureListe(reponse);
60 jpm 46
						// et on met à jour le demandeur des données
47
						rafraichissement.rafraichir(institutions);
48
					}
49
 
50
				}
51
			});
52
		} catch (RequestException e) {
53
			e.printStackTrace();
54
		}
55
	}
56
}