Subversion Repositories eFlore/Applications.coel

Rev

Details | 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) {
114 jpm 39
					Boolean defaut = true;
40
					if (response.getText().length() != 0 && response.getText() != null) {
41
						final JSONValue responseValue = JSONParser.parse(response.getText());
42
 
43
						// Si la requête est un succès, reception d'un tableau
44
						if (responseValue.isArray() != null) {
45
							final JSONArray reponse = responseValue.isArray();
46
							// Transformation du tableau JSON réponse en ListeInstitution
47
							institutions = new StructureListe(reponse);
48
							// et on met à jour le demandeur des données
49
							rafraichissement.rafraichir(institutions);
50
							// Tout c'est bien déroulé, on courcircuite l'affichage par défaut
51
							defaut = false;
52
						}
53
					}
54
					if (defaut == true) {
55
						institutions = new StructureListe(0);
60 jpm 56
						rafraichissement.rafraichir(institutions);
57
					}
58
				}
59
			});
60
		} catch (RequestException e) {
61
			e.printStackTrace();
62
		}
63
	}
64
}