Subversion Repositories eFlore/Applications.coel

Rev

Rev 106 | Rev 230 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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