Rev 682 | Rev 1292 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package org.tela_botanica.client.modeles;
import java.util.HashMap;
import org.tela_botanica.client.http.JsonRestRequestBuilder;
import org.tela_botanica.client.http.JsonRestRequestCallback;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.util.UtilDAO;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONString;
import com.google.gwt.json.client.JSONValue;
public class ValeurListeAsyncDao {
private static HashMap<Integer, ValeurListe> ontologieCache = new HashMap<Integer, ValeurListe>();
private static final String SERVICE_NOM = "CoelValeurListe";
private Rafraichissable vueARafraichir = null;
public ValeurListeAsyncDao(Rafraichissable vueCourante) {
vueARafraichir = vueCourante;
}
public void obtenirListe(Integer cle) {
selectionner("id", cle, null, null);
}
public void selectionner(String type, final Integer cleParent, String abv, String idValeur) {
if (ontologieCache.containsKey(cleParent)) {
vueARafraichir.rafraichir(ontologieCache.get(cleParent));
} else {
String paramAbv = (type.equals("id") ? null : abv);
String[] parametres = {type, cleParent.toString(), paramAbv, idValeur};
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
rb.envoyerRequete(null, new JsonRestRequestCallback() {
@Override
public void surReponse(JSONValue responseValue) {
if (responseValue.isObject() != null) {
final JSONObject reponse = responseValue.isObject();
JSONString listeId = reponse.get("id").isString();
JSONArray listeValeurs = reponse.get("valeurs").isArray();
if (listeId != null) {
// Transformation du tableau JSON réponse en Liste
ValeurListe liste = new ValeurListe(listeId, listeValeurs);
// Stockage en cache
ontologieCache.put(cleParent, liste);
// et on met à jour le demandeur des données
vueARafraichir.rafraichir(liste);
}
}
}
});
}
}
}