Subversion Repositories eFlore/Applications.coel

Rev

Rev 303 | Rev 581 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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