5,6 → 5,11 |
import org.tela_botanica.client.interfaces.Rafraichissable; |
import org.tela_botanica.client.observation.ObservationModele; |
|
import com.google.gwt.http.client.Request; |
import com.google.gwt.http.client.RequestBuilder; |
import com.google.gwt.http.client.RequestCallback; |
import com.google.gwt.http.client.RequestException; |
import com.google.gwt.http.client.Response; |
import com.google.gwt.json.client.JSONArray; |
import com.google.gwt.json.client.JSONParser; |
import com.google.gwt.json.client.JSONString; |
44,7 → 49,66 |
|
public void obtenirListeDonnees(final Rafraichissable r, String critere) |
{ |
|
RequestBuilder rb = new RequestBuilder(RequestBuilder.GET,observationModele.getConfig().getServiceBaseUrl()+"/LocationSearch/"+critere) ; |
|
try { |
|
rb.sendRequest(null, new RequestCallback() { |
|
public void onError(Request request, Throwable exception) { |
// TODO Auto-generated method stub |
|
} |
|
public void onResponseReceived(Request request, |
Response response) { |
|
final ListeReferentielCommune referentielCommuneData ; |
|
final JSONValue responseValue = JSONParser.parse(response.getText()); |
|
JSONArray reponse=null; |
|
|
// si c'est un tableau |
if ((reponse=responseValue.isArray()) != null) { |
|
JSONArray communes; |
final int taillemax = reponse.size(); |
|
referentielCommuneData = new ListeReferentielCommune(taillemax); |
|
for (int i = 0; i < taillemax; i++) { |
if ((communes=reponse.get(i).isArray()) != null) { |
|
String commune=((JSONString) communes.get(0)).stringValue(); |
String departement=((JSONString) communes.get(1)).stringValue(); |
|
|
ReferentielCommune com=new ReferentielCommune(commune, departement); |
|
referentielCommuneData.put(com.getCommune()+com.getDepartement(),com); |
|
} |
} |
} else { |
|
referentielCommuneData = new ListeReferentielCommune(0) ; |
|
} |
// dans tous les cas on transmet la liste crée au rafraichissable en lui demandant de répandre les données car il est |
// le premier à les recevoir |
r.rafraichir(referentielCommuneData,true); |
|
} |
|
}) ; |
|
} catch (RequestException e) { |
|
e.printStackTrace() ; |
} |
|
// on envoie le get asynchrone |
HTTPRequest.asyncGet(observationModele.getConfig().getServiceBaseUrl()+"/LocationSearch/"+critere, new ResponseTextHandler() { |
54,43 → 118,7 |
public void onCompletion(String responseText) { |
|
|
final ListeReferentielCommune referentielCommuneData ; |
|
final JSONValue responseValue = JSONParser.parse(responseText); |
|
JSONArray reponse=null; |
|
|
// si c'est un tableau |
if ((reponse=responseValue.isArray()) != null) { |
|
JSONArray communes; |
final int taillemax = reponse.size(); |
|
referentielCommuneData = new ListeReferentielCommune(taillemax); |
|
for (int i = 0; i < taillemax; i++) { |
if ((communes=reponse.get(i).isArray()) != null) { |
|
String commune=((JSONString) communes.get(0)).stringValue(); |
String departement=((JSONString) communes.get(1)).stringValue(); |
|
|
ReferentielCommune com=new ReferentielCommune(commune, departement); |
|
referentielCommuneData.put(com.getCommune()+com.getDepartement(),com); |
|
|
} |
|
} |
|
|
// dans tous les cas on transmet la liste crée au rafraichissable en lui demandant de répandre les données car il est |
// le premier à les recevoir |
|
r.rafraichir(referentielCommuneData,true); |
} |
} |
|
|