Subversion Repositories eFlore/Applications.cel

Rev

Rev 15 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 15 Rev 32
Line 3... Line 3...
3
import org.tela_botanica.client.Util;
3
import org.tela_botanica.client.Util;
4
import org.tela_botanica.client.interfaces.FournisseurListe;
4
import org.tela_botanica.client.interfaces.FournisseurListe;
5
import org.tela_botanica.client.interfaces.Rafraichissable;
5
import org.tela_botanica.client.interfaces.Rafraichissable;
6
import org.tela_botanica.client.observation.ObservationModele;
6
import org.tela_botanica.client.observation.ObservationModele;
Line -... Line 7...
-
 
7
 
-
 
8
import com.google.gwt.http.client.Request;
-
 
9
import com.google.gwt.http.client.RequestBuilder;
-
 
10
import com.google.gwt.http.client.RequestCallback;
-
 
11
import com.google.gwt.http.client.RequestException;
7
 
12
import com.google.gwt.http.client.Response;
8
import com.google.gwt.json.client.JSONArray;
13
import com.google.gwt.json.client.JSONArray;
9
import com.google.gwt.json.client.JSONParser;
14
import com.google.gwt.json.client.JSONParser;
10
import com.google.gwt.json.client.JSONString;
15
import com.google.gwt.json.client.JSONString;
11
import com.google.gwt.json.client.JSONValue;
16
import com.google.gwt.json.client.JSONValue;
Line 41... Line 46...
41
	 */
46
	 */
Line 42... Line 47...
42
	
47
	
43
	
48
	
44
	public void obtenirListeDonnees(final Rafraichissable r, String critere)
-
 
Line 45... Line -...
45
	{
-
 
46
				
49
	public void obtenirListeDonnees(final Rafraichissable r, String critere)
Line -... Line 50...
-
 
50
	{
-
 
51
		
-
 
52
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET, observationModele.getConfig().getServiceBaseUrl()+"/NameSearch/"+critere) ;
Line 47... Line 53...
47
		
53
		
48
		// on envoie le get asynchrone
54
		try {
-
 
55
			
-
 
56
			rb.sendRequest(null, new RequestCallback() {
Line -... Line 57...
-
 
57
 
-
 
58
				public void onError(Request request, Throwable exception) {
Line 49... Line 59...
49
		HTTPRequest.asyncGet(observationModele.getConfig().getServiceBaseUrl()+"/NameSearch/"+critere, new ResponseTextHandler() {
59
					// TODO Auto-generated method stub
50
		
-
 
51
 
-
 
52
			// si tout se passe bien on reçoit une réponse JSON
-
 
53
			public void onCompletion(String responseText) {
-
 
54
 
-
 
55
					
-
 
56
				final ListeReferentielNom referentielNomData ;
-
 
57
				
-
 
Line 58... Line -...
58
				final JSONValue responseValue = JSONParser.parse(responseText);
-
 
59
				
60
					
Line -... Line 61...
-
 
61
				}
-
 
62
 
-
 
63
				public void onResponseReceived(Request request,
-
 
64
						Response response) {
-
 
65
					
-
 
66
					final ListeReferentielNom referentielNomData ;
-
 
67
					
-
 
68
					final JSONValue responseValue = JSONParser.parse(response.getText());
-
 
69
					
60
				JSONArray reponse=null;
70
					JSONArray reponse=null;
61
	
71
		
62
	
72
		
63
				// si c'est un tableau
73
					// si c'est un tableau
64
				if ((reponse=responseValue.isArray()) != null) {
74
					if ((reponse=responseValue.isArray()) != null) {
65
					
75
						
66
					JSONArray noms;
76
						JSONArray noms;
67
					final int taillemax = reponse.size();
77
						final int taillemax = reponse.size();
68
					
78
						
69
					referentielNomData = new ListeReferentielNom(taillemax);
79
						referentielNomData = new ListeReferentielNom(taillemax);
70
					
80
						
71
					for (int i = 0; i < taillemax; i++) {
81
						for (int i = 0; i < taillemax; i++) {
72
						if ((noms=reponse.get(i).isArray()) != null) {
82
							if ((noms=reponse.get(i).isArray()) != null) {
73
							
83
								
74
							 
84
								 
75
							
85
								
-
 
86
								String nom=Util.toCelString(((JSONString) noms.get(0)).toString());
-
 
87
								String numeroNom=Util.toCelString(((JSONString) noms.get(1)).toString());
76
							String nom=Util.toCelString(((JSONString) noms.get(0)).toString());
88
								
77
							String numeroNom=Util.toCelString(((JSONString) noms.get(1)).toString());
89
								ReferentielNom nomScientifique=new ReferentielNom(nom, numeroNom);
78
							
-
 
79
							ReferentielNom nomScientifique=new ReferentielNom(nom, numeroNom);
90
				
Line -... Line 91...
-
 
91
								// FIXME : et si le numero de nom n'est pas unique ? (cas de multirefrentiel....)
-
 
92
								
80
			
93
								referentielNomData.put(nomScientifique.getNumeroNom(),nomScientifique);
81
							// FIXME : et si le numero de nom n'est pas unique ? (cas de multirefrentiel....)
94
		
82
							
95
								
Line 83... Line 96...
83
							referentielNomData.put(nomScientifique.getNumeroNom(),nomScientifique);
96
							}
-
 
97
		
84
	
98
						}
-
 
99
					} else {
-
 
100
						
85
							
101
						referentielNomData = new ListeReferentielNom(0) ;
-
 
102
					}
-
 
103
					
86
						}
104
					// dans tous les cas on transmet la liste crée au rafraichissable en lui demandant de répandre les données car il est
87
	
105
					// le premier à les recevoir
88
					}
106
				
89
						
107
					r.rafraichir(referentielNomData,true);
90
													
108