Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
106 aurelien 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
import com.google.gwt.user.client.Window;
16
 
17
public class PublicationListeAsyncDao {
18
 
19
	private PublicationListe publications = null;
20
	private Rafraichissable rafraichissement = null;
21
 
22
	public PublicationListeAsyncDao(Rafraichissable r) {
23
 
24
		rafraichissement = r ;
25
	}
26
 
27
	public void obtenirListePublication() {
28
    	// Demande de toutes les structures
29
    	String url = ((Configuration) Registry.get(RegistreId.CONFIG)).getServiceBaseUrl();
30
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, url+"CoelPublicationListe/");
31
 
32
		try {
33
			rb.sendRequest(null, new RequestCallback() {
34
 
35
				public void onError(Request request, Throwable exception) {
36
					// TODO Auto-generated method stub
37
 
38
				}
39
 
40
				public void onResponseReceived(Request request, Response response) {
114 jpm 41
					Boolean defaut = true;
42
					if (response.getText().length() != 0 && response.getText() != null) {
43
						final JSONValue responseValue = JSONParser.parse(response.getText());
106 aurelien 44
 
114 jpm 45
						// Si la requête est un succès, reception d'un tableau
46
						if (responseValue.isArray() != null) {
47
							final JSONArray reponse = responseValue.isArray();
48
							// Transformation du tableau JSON réponse en ListeInstitution
49
							publications = new PublicationListe(reponse);
50
							// et on met à jour le demandeur des données
51
							rafraichissement.rafraichir(publications);
52
							// Tout c'est bien déroulé, on courcircuite l'affichage par défaut
53
							defaut = false;
54
						}
106 aurelien 55
					}
114 jpm 56
					if (defaut == true) {
106 aurelien 57
						publications = new PublicationListe(0);
58
						rafraichissement.rafraichir(publications);
59
					}
60
				}
61
			});
62
		} catch (RequestException e) {
63
			e.printStackTrace();
64
		}
65
	}
66
 
67
}