Subversion Repositories eFlore/Applications.coel

Compare Revisions

Ignore whitespace Rev 1040 → Rev 1041

/trunk/src/org/tela_botanica/client/modeles/collection/CollectionListe.java
1,8 → 1,16
package org.tela_botanica.client.modeles.collection;
 
import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.interfaces.ListePaginable;
import org.tela_botanica.client.interfaces.Rafraichissable;
import org.tela_botanica.client.modeles.aDonneeListe;
import org.tela_botanica.client.modeles.structure.Structure;
 
import com.extjs.gxt.ui.client.Registry;
import com.google.gwt.i18n.client.Dictionary;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONObject;
 
/**
12,10 → 20,14
* @author david delon
*
*/
public class CollectionListe extends aDonneeListe<Collection> {
public class CollectionListe extends aDonneeListe<Collection> implements ListePaginable{
private static final long serialVersionUID = 8024454926649039456L;
 
private int currentPage = 0;
private int nbElementsPage = Integer.valueOf(((Dictionary) Dictionary.getDictionary("configuration")).get("nbElementsPage"));
private int nbElementsTotal;
private Rafraichissable vueARafraichir;
public CollectionListe() {
super();
}
44,5 → 56,98
}
}
}
public CollectionListe(JSONArray collectionListe, JSONNumber nbElements, Rafraichissable vueARafraichir) {
super(collectionListe.size());
this.nbElementsTotal = Integer.valueOf(nbElements.toString());
final int taillemax = collectionListe.size();
for (int i = 0; i < taillemax; i++) {
JSONObject collection = collectionListe.get(i).isObject() ;
if (collection != null) {
Collection collectionCourante = new Collection(collection);
this.put(collectionCourante.getId(), collectionCourante);
}
}
this.vueARafraichir = vueARafraichir;
}
 
 
@Override
public void changerNumeroPage(int pageCourante) {
currentPage = pageCourante;
selectionnerCollection();
}
 
@Override
public void changerTaillePage(int nouvelleTaillePage) {
nbElementsPage = nouvelleTaillePage;
selectionnerCollection();
}
@Override
public void recharger() {
selectionnerCollection();
}
public void setPageCourante(int pageCourante) {
this.currentPage = pageCourante;
}
 
public void setTaillePage(int taillePage) {
this.nbElementsPage = taillePage;
}
public int[] getPageTable() {
int[] page = new int[4];
 
// nombre de pages au total
page[0] = calculerNbPages();
 
// Page En Cours
page[1] = currentPage;
 
// nbElementsParPage
page[2] = nbElementsPage;
 
// et le dernier le nombre total d'éléments
page[3] = nbElementsTotal;
 
return page;
}
/**
* Calcule le nombre de pages nécessaires pour afficher un nombre d'élements
* donnés en fonction de la taille de page en cours
*
* @return le nombre de pages
*/
public int calculerNbPages() {
// A cause de la betise de java pour les conversion implicite on fait
// quelques conversions manuellement
// pour eviter qu'il arrondisse mal la division
// nombre de pages = (nombre d'element / taille de la page) arrondie à
// l'entier superieur
 
double nPage = (1.0 * nbElementsTotal) / (1.0 * nbElementsPage);
double nPageRound = Math.ceil(nPage);
Double nPageInt = new Double(nPageRound);
 
// on convertit en entier
return nPageInt.intValue();
}
public void selectionnerCollection() {
Mediateur mediateur =(Mediateur) Registry.get(RegistreId.MEDIATEUR);
mediateur.selectionnerCollection(vueARafraichir, null, null, currentPage, nbElementsPage);
}
public void filtrerParNom(String nom) {
Mediateur mediateur =(Mediateur) Registry.get(RegistreId.MEDIATEUR);
mediateur.selectionnerCollection(vueARafraichir, null, nom, 0, nbElementsPage);
}
}
/trunk/src/org/tela_botanica/client/modeles/collection/CollectionAsyncDao.java
1,5 → 1,7
package org.tela_botanica.client.modeles.collection;
 
import java.util.HashMap;
 
import org.tela_botanica.client.Mediateur;
import org.tela_botanica.client.RegistreId;
import org.tela_botanica.client.http.JsonRestRequestBuilder;
14,6 → 16,7
import com.google.gwt.core.client.GWT;
import com.google.gwt.http.client.URL;
import com.google.gwt.json.client.JSONArray;
import com.google.gwt.json.client.JSONNumber;
import com.google.gwt.json.client.JSONObject;
import com.google.gwt.json.client.JSONValue;
 
28,17 → 31,25
utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId();
}
public void selectionner(final String projetId, final String collectionId) {
public void selectionner(final String projetId, final String collectionId, final String nomCollection, final int start, final int nbElements) {
// Ajout des paramètres et données à selectionner dans l'URL
String[] parametres = {projetId, collectionId};
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres);
String[] parametres = {projetId, collectionId, nomCollection};
HashMap<String, String> restrictions = new HashMap<String, String>();
restrictions.put("start", String.valueOf(start));
if (nbElements != -1) {
restrictions.put("limit", String.valueOf(nbElements));
}
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres, restrictions);
rb.envoyerRequete(null, new JsonRestRequestCallback() {
@Override
public void surReponse(JSONValue responseValue) {
if (responseValue != null) {
// Si la requête est un succès, reception d'un objet ou d'un tableau
if (responseValue.isObject() != null) {
final JSONObject reponse = responseValue.isObject();
JSONArray responseArray = responseValue.isArray();
if (responseArray.get(1).isObject() != null) {
final JSONObject reponse = responseArray.get(1).isObject();
Collection collection = new Collection(reponse);
CollectionBotanique collectionBotanique = new CollectionBotanique(reponse);
collection.setBotanique(collectionBotanique);
47,8 → 58,11
info.setDonnee(0, collection);
vueARafraichir.rafraichir(info);
} else if (responseValue.isArray() != null) {
final JSONArray reponse = responseValue.isArray();
CollectionListe collections = new CollectionListe(reponse);
final JSONArray reponse = responseArray.get(1).isArray();
CollectionListe collections = new CollectionListe(reponse, responseArray.get(0).isNumber(), vueARafraichir);
collections.setTaillePage(nbElements);
collections.setPageCourante(start);
vueARafraichir.rafraichir(collections);
} else {
GWT.log(rb.getUrl()+"\n\tLa réponse n'est pas un objet ou un talbeau JSON et vaut : "+responseValue.toString(), null);