/trunk/src/org/tela_botanica/client/modeles/commentaire/CommentaireListe.java |
---|
1,14 → 1,26 |
package org.tela_botanica.client.modeles.commentaire; |
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; |
public class CommentaireListe extends aDonneeListe<Commentaire> { |
public class CommentaireListe extends aDonneeListe<Commentaire> implements ListePaginable { |
private static final long serialVersionUID = 2600314321196345072L; |
private int currentPage = 0; |
private int nbElementsPage = Integer.valueOf(((Dictionary) Dictionary.getDictionary("configuration")).get("nbElementsPage")); |
private int nbElementsTotal; |
private Rafraichissable vueARafraichir; |
public CommentaireListe() { |
super(); |
} |
35,4 → 47,99 |
} |
} |
} |
public CommentaireListe(JSONArray commentaireListe, JSONNumber nbElements, Rafraichissable vueARafraichir) { |
super(commentaireListe.size()); |
this.nbElementsTotal = Integer.valueOf(nbElements.toString()); |
final int taillemax = commentaireListe.size(); |
for (int i = 0; i < taillemax; i++) { |
JSONObject commentaire = commentaireListe.get(i).isObject() ; |
if (commentaire != null) { |
Commentaire commentaireCourant = new Commentaire(commentaire); |
this.put(commentaireCourant.getId(), commentaireCourant); |
} |
} |
this.vueARafraichir = vueARafraichir; |
} |
@Override |
public void changerNumeroPage(int pageCourante) { |
currentPage = pageCourante; |
selectionnerCommentaire(); |
} |
@Override |
public void changerTaillePage(int nouvelleTaillePage) { |
nbElementsPage = nouvelleTaillePage; |
selectionnerCommentaire(); |
} |
@Override |
public void recharger() { |
selectionnerCommentaire(); |
} |
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 selectionnerCommentaire() { |
Mediateur mediateur =(Mediateur) Registry.get(RegistreId.MEDIATEUR); |
mediateur.selectionnerCommentaire(vueARafraichir, null, null, currentPage, nbElementsPage); |
} |
public void filtrerParNom(String nom) { |
Mediateur mediateur =(Mediateur) Registry.get(RegistreId.MEDIATEUR); |
System.out.println("la : " + nom); |
mediateur.selectionnerCommentaireParTitre(vueARafraichir, nom); |
} |
} |
/trunk/src/org/tela_botanica/client/modeles/commentaire/CommentaireAsyncDao.java |
---|
1,5 → 1,7 |
package org.tela_botanica.client.modeles.commentaire; |
import java.util.HashMap; |
import org.tela_botanica.client.Mediateur; |
import org.tela_botanica.client.RegistreId; |
import org.tela_botanica.client.http.JsonRestRequestBuilder; |
6,6 → 8,7 |
import org.tela_botanica.client.http.JsonRestRequestCallback; |
import org.tela_botanica.client.interfaces.Rafraichissable; |
import org.tela_botanica.client.modeles.Information; |
import org.tela_botanica.client.modeles.structure.StructureListe; |
import org.tela_botanica.client.util.UtilDAO; |
import com.extjs.gxt.ui.client.Registry; |
25,17 → 28,24 |
utilisateurId = ((Mediateur) Registry.get(RegistreId.MEDIATEUR)).getUtilisateurId(); |
} |
public void selectionner(final String commentaireId, String projetId, String titre) { |
public void selectionner(final String commentaireId, String projetId, String titre, final int pageCourante, final int nbElements) { |
String[] parametres = {projetId, commentaireId, titre}; |
final JsonRestRequestBuilder rb = UtilDAO.construireRequete(SERVICE_NOM, parametres); |
HashMap<String, String> restrictions = new HashMap<String, String>(); |
restrictions.put("start", String.valueOf(pageCourante)); |
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, réception 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(); |
// Transformation du tableau JSON réponse en ListeInstitution |
Commentaire commentaire = new Commentaire(reponse); |
// et on met à jour le demandeur des données |
42,7 → 52,15 |
vueARafraichir.rafraichir(commentaire); |
} else if (responseValue.isArray() != null) { |
final JSONArray reponse = responseValue.isArray(); |
CommentaireListe commentaires = new CommentaireListe(reponse); |
CommentaireListe commentaires; |
if (reponse.get(1).isObject() != null) { |
commentaires = new CommentaireListe(reponse.get(1).isArray()); |
} else { |
commentaires = new CommentaireListe(reponse.get(1).isArray(), reponse.get(0).isNumber(), vueARafraichir); |
} |
commentaires.setTaillePage(nbElements); |
commentaires.setPageCourante(pageCourante); |
vueARafraichir.rafraichir(commentaires); |
} else { |
GWT.log("La réponse n'est pas un objet ou un talbeau JSON et vaut : "+responseValue.toString(), null); |
/trunk/src/org/tela_botanica/client/vues/commentaire/CommentaireListeVue.java |
---|
18,7 → 18,9 |
import org.tela_botanica.client.modeles.aDonnee; |
import org.tela_botanica.client.modeles.commentaire.Commentaire; |
import org.tela_botanica.client.modeles.commentaire.CommentaireListe; |
import org.tela_botanica.client.modeles.structure.StructureListe; |
import org.tela_botanica.client.util.Debug; |
import org.tela_botanica.client.vues.BarrePaginationVue; |
import com.extjs.gxt.ui.client.Registry; |
import com.extjs.gxt.ui.client.Style.SortDir; |
61,6 → 63,8 |
private Button modifier; |
private Button supprimer; |
private BarrePaginationVue pagination = null; |
private CommentaireListe commentaires = null; |
protected boolean commentairesChargementOk = false; |
162,6 → 166,10 |
} |
}); |
add(grille); |
// Définition de la barre de pagination |
pagination = new BarrePaginationVue(new StructureListe(), mediateur); |
setBottomComponent(pagination); |
} |
private ColumnConfig creerColonneType() { |
239,6 → 247,10 |
public void rafraichir(Object nouvellesDonnees) { |
if (nouvellesDonnees instanceof CommentaireListe) { |
commentaires = (CommentaireListe) nouvellesDonnees; |
pagination.setlistePaginable(commentaires); |
pagination.rafraichir(commentaires.getPageTable()); |
commentairesChargementOk = true; |
} else if (nouvellesDonnees instanceof ValeurListe) { |
ValeurListe listeValeursReceptionnee = (ValeurListe) nouvellesDonnees; |