Rev 1687 | Blame | Compare with Previous | Last modification | View Log | RSS feed
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.util.UtilString;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;/*** Classe contenant les informations sur les Commentaires renvoyées par un objet de type DAO.** @author Jean-Pascal MILCENT**/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();}public CommentaireListe(int taille) {super(taille);}/*** Constructeur pour une liste de commentaires* @param dates*/public CommentaireListe(JSONArray ListeDeCommentaires) {super(ListeDeCommentaires.size());initialiserCommentaireListe(ListeDeCommentaires);}public CommentaireListe(JSONArray ListeDeCommentaires, JSONNumber nbElements, Rafraichissable vueARafraichir) {super(ListeDeCommentaires.size());this.nbElementsTotal = Integer.valueOf(nbElements.toString());this.vueARafraichir = vueARafraichir;initialiserCommentaireListe(ListeDeCommentaires);}private void initialiserCommentaireListe(JSONArray ListeDeCommentaires) {boolean chargerCollectionACommentaire = true;final int taillemax = ListeDeCommentaires.size();for (int i = 0; i < taillemax; i++) {JSONObject commentaireCourant = ListeDeCommentaires.get(i).isObject() ;if (commentaireCourant != null) {Commentaire commentaire = new Commentaire(commentaireCourant, chargerCollectionACommentaire);if (!UtilString.isEmpty(commentaire.getCollectionACommentaire().getId())) {this.put(commentaire.getCollectionACommentaire().getId(), commentaire);}else {this.put(commentaire.getId(), commentaire);}}}}public void changerNumeroPage(int pageCourante) {currentPage = pageCourante;selectionnerCommentaire();}public void changerTaillePage(int nouvelleTaillePage) {nbElementsPage = nouvelleTaillePage;selectionnerCommentaire();}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 totalpage[0] = calculerNbPages();// Page En Courspage[1] = currentPage;// nbElementsParPagepage[2] = nbElementsPage;// et le dernier le nombre total d'élémentspage[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() {// À cause de la bétise 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 supérieur.double nPage = (1.0 * nbElementsTotal) / (1.0 * nbElementsPage);double nPageRound = Math.ceil(nPage);Double nPageInt = new Double(nPageRound);// Convertion en entierreturn nPageInt.intValue();}public void selectionnerCommentaire() {Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);mediateur.selectionnerCommentaire(vueARafraichir, null, null, currentPage, nbElementsPage, null);}public void filtrerParNom(String nom) {Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);mediateur.selectionnerCommentaireParTitre(vueARafraichir, "%" + nom + "%", null);}public void filtrerParNomEtPage(String nom, int pageCourante) {currentPage = pageCourante;Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);mediateur.selectionnerCommentaire(vueARafraichir, null, "%" + nom + "%", currentPage, nbElementsPage, null);}}