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 42... Line 47...
42
	 */
47
	 */
Line 43... Line 48...
43
	
48
	
44
	
49
	
45
	public void obtenirListeDonnees(final Rafraichissable r, String critere)
-
 
Line 46... Line -...
46
	{
-
 
47
				
50
	public void obtenirListeDonnees(final Rafraichissable r, String critere)
Line -... Line 51...
-
 
51
	{
-
 
52
		
-
 
53
		RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,observationModele.getConfig().getServiceBaseUrl()+"/LocationSearch/"+critere) ;
Line 48... Line 54...
48
		
54
		
49
		// on envoie le get asynchrone
55
		try {
50
		HTTPRequest.asyncGet(observationModele.getConfig().getServiceBaseUrl()+"/LocationSearch/"+critere, new ResponseTextHandler() {
-
 
Line 51... Line -...
51
		
-
 
52
 
56
			
53
			// si tout se passe bien on reçoit une réponse JSON
-
 
54
			public void onCompletion(String responseText) {
57
			rb.sendRequest(null, new RequestCallback() {
55
 
58
 
56
					
-
 
57
				final ListeReferentielCommune referentielCommuneData ;
-
 
58
				
59
				public void onError(Request request, Throwable exception) {
59
				final JSONValue responseValue = JSONParser.parse(responseText);
-
 
Line 60... Line -...
60
				
-
 
61
				JSONArray reponse=null;
60
					// TODO Auto-generated method stub
Line 62... Line 61...
62
	
61
					
Line -... Line 62...
-
 
62
				}
-
 
63
 
-
 
64
				public void onResponseReceived(Request request,
-
 
65
						Response response) {
-
 
66
					
-
 
67
					final ListeReferentielCommune referentielCommuneData ;
-
 
68
					
-
 
69
					final JSONValue responseValue = JSONParser.parse(response.getText());
-
 
70
					
-
 
71
					JSONArray reponse=null;
-
 
72
		
63
	
73
		
64
				// si c'est un tableau
74
					// si c'est un tableau
65
				if ((reponse=responseValue.isArray()) != null) {
75
					if ((reponse=responseValue.isArray()) != null) {
66
					
76
						
67
					JSONArray communes;
77
						JSONArray communes;
68
					final int taillemax = reponse.size();
78
						final int taillemax = reponse.size();
69
					
79
						
70
					referentielCommuneData = new ListeReferentielCommune(taillemax);
80
						referentielCommuneData = new ListeReferentielCommune(taillemax);
71
					
81
						
72
					for (int i = 0; i < taillemax; i++) {
82
						for (int i = 0; i < taillemax; i++) {
73
						if ((communes=reponse.get(i).isArray()) != null) {
83
							if ((communes=reponse.get(i).isArray()) != null) {
74
							
84
								
75
							String commune=((JSONString) communes.get(0)).stringValue();
85
								String commune=((JSONString) communes.get(0)).stringValue();
-
 
86
								String departement=((JSONString) communes.get(1)).stringValue();
76
							String departement=((JSONString) communes.get(1)).stringValue();
87
								
77
							
88
								
Line 78... Line 89...
78
							
89
								ReferentielCommune com=new ReferentielCommune(commune, departement);
79
							ReferentielCommune com=new ReferentielCommune(commune, departement);
90
				
80
			
91
								referentielCommuneData.put(com.getCommune()+com.getDepartement(),com);
81
							referentielCommuneData.put(com.getCommune()+com.getDepartement(),com);
-
 
82
	
92
										
-
 
93
							}	
83
							
94
						}
-
 
95
					} else {
-
 
96
						
-
 
97
						referentielCommuneData = new ListeReferentielCommune(0) ;
-
 
98
						
-
 
99
					}			
-
 
100
					// dans tous les cas on transmet la liste crée au rafraichissable en lui demandant de répandre les données car il est
-
 
101
					// le premier à les recevoir				
-
 
102
					r.rafraichir(referentielCommuneData,true);
-
 
103
					
-
 
104
				}	
-
 
105
				
-
 
106
			}) ;
-
 
107
			
-
 
108
		} catch (RequestException e) {
-
 
109
			
-
 
110
			e.printStackTrace() ;
-
 
111
		}
84
						}
112
		
Line 85... Line 113...
85
	
113
		// on envoie le get asynchrone
86
					}
114
		HTTPRequest.asyncGet(observationModele.getConfig().getServiceBaseUrl()+"/LocationSearch/"+critere, new ResponseTextHandler() {