Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
69 jpm 1
package org.tela_botanica.client.modeles;
2
 
3
import org.tela_botanica.client.interfaces.Rafraichissable;
299 gduche 4
import org.tela_botanica.client.util.UtilDAO;
69 jpm 5
 
6
import com.google.gwt.http.client.Request;
7
import com.google.gwt.http.client.RequestBuilder;
8
import com.google.gwt.http.client.RequestCallback;
9
import com.google.gwt.http.client.RequestException;
10
import com.google.gwt.http.client.Response;
11
import com.google.gwt.json.client.JSONArray;
91 jpm 12
import com.google.gwt.json.client.JSONObject;
69 jpm 13
import com.google.gwt.json.client.JSONParser;
91 jpm 14
import com.google.gwt.json.client.JSONString;
69 jpm 15
import com.google.gwt.json.client.JSONValue;
16
 
17
public class ValeurListeAsyncDao {
268 jp_milcent 18
	private static final String SERVICE_NOM = "CoelValeurListe";
69 jpm 19
 
268 jp_milcent 20
	private Rafraichissable vue = null;
69 jpm 21
 
268 jp_milcent 22
	public ValeurListeAsyncDao() {
23
		// TODO Auto-generated constructor stub
69 jpm 24
	}
25
 
268 jp_milcent 26
	public ValeurListeAsyncDao(Rafraichissable vueARafraichir) {
27
		vue = vueARafraichir;
28
	}
29
 
299 gduche 30
	public void obtenirListe(Integer cle)	{
303 gduche 31
		selectionner("id", cle, "*", "*");
292 gduche 32
	}
33
 
303 gduche 34
	public void selectionner(String type, Integer cleParent, String abv, String idValeur) {
299 gduche 35
 
36
    	// Ajout des paramètres et données à selectionner dans l'URL
303 gduche 37
		String[] parametres = new String[4];
299 gduche 38
		parametres[0] = type;
303 gduche 39
		parametres[1] = cleParent.toString();
40
		parametres[2] = "*";
299 gduche 41
 
303 gduche 42
    	if (!type.equals("id"))	{
43
    		parametres[2] = abv;
292 gduche 44
    	}
299 gduche 45
 
303 gduche 46
    	parametres[3] = idValeur;
47
 
48
 
49
 
299 gduche 50
    	RequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
69 jpm 51
		try {
52
			rb.sendRequest(null, new RequestCallback() {
53
 
54
				public void onError(Request request, Throwable exception) {
55
					// TODO Auto-generated method stub
56
 
57
				}
58
 
59
				public void onResponseReceived(Request request, Response response) {
91 jpm 60
 
69 jpm 61
					final JSONValue responseValue = JSONParser.parse(response.getText());
62
 
63
					// Si la requête est un succès, reception d'un tableau
91 jpm 64
					if (responseValue.isObject() != null) {
303 gduche 65
 
91 jpm 66
						try {
67
							final JSONObject reponse = responseValue.isObject();
68
							JSONString listeId = reponse.get("id").isString();
69
							JSONArray listeValeurs = reponse.get("valeurs").isArray();
303 gduche 70
							if (listeId != null)	{
71
								// Transformation du tableau JSON réponse en Liste
72
								ValeurListe liste = new ValeurListe(listeId, listeValeurs);
73
								// et on met à jour le demandeur des données
74
								vue.rafraichir(liste);
75
							}
91 jpm 76
						} catch (NullPointerException e) {
77
							e.printStackTrace();
78
						}
69 jpm 79
					}
80
 
81
				}
82
			});
83
		} catch (RequestException e) {
84
			e.printStackTrace();
85
		}
86
	}
292 gduche 87
 
88
 
69 jpm 89
}