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); |
|
} |
|
|
} |