Subversion Repositories eFlore/Applications.coel

Rev

Rev 114 | Go to most recent revision | Details | 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) {
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
 
46
						final JSONArray reponse = responseValue.isArray();
47
						// Transformation du tableau JSON réponse en ListeInstitution
48
						publications = new PublicationListe(reponse);
49
						// et on met à jour le demandeur des données
50
						rafraichissement.rafraichir(publications);
51
					}
52
					else
53
					{
54
						publications = new PublicationListe(0);
55
						rafraichissement.rafraichir(publications);
56
					}
57
 
58
				}
59
			});
60
		} catch (RequestException e) {
61
			e.printStackTrace();
62
		}
63
	}
64
 
65
}