985 |
jpm |
1 |
package org.tela_botanica.client.modeles.commentaire;
|
|
|
2 |
|
1049 |
gduche |
3 |
import org.tela_botanica.client.Mediateur;
|
|
|
4 |
import org.tela_botanica.client.RegistreId;
|
|
|
5 |
import org.tela_botanica.client.interfaces.ListePaginable;
|
|
|
6 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
985 |
jpm |
7 |
import org.tela_botanica.client.modeles.aDonneeListe;
|
1305 |
cyprien |
8 |
import org.tela_botanica.client.util.Debug;
|
985 |
jpm |
9 |
|
1049 |
gduche |
10 |
import com.extjs.gxt.ui.client.Registry;
|
1305 |
cyprien |
11 |
import com.extjs.gxt.ui.client.util.Util;
|
1049 |
gduche |
12 |
import com.google.gwt.i18n.client.Dictionary;
|
985 |
jpm |
13 |
import com.google.gwt.json.client.JSONArray;
|
1049 |
gduche |
14 |
import com.google.gwt.json.client.JSONNumber;
|
985 |
jpm |
15 |
import com.google.gwt.json.client.JSONObject;
|
|
|
16 |
|
1166 |
jpm |
17 |
/**
|
|
|
18 |
* Classe contenant les informations sur les Commentaires renvoyées par un objet de type DAO.
|
|
|
19 |
*
|
|
|
20 |
* @author Jean-Pascal MILCENT
|
|
|
21 |
*
|
|
|
22 |
*/
|
1049 |
gduche |
23 |
public class CommentaireListe extends aDonneeListe<Commentaire> implements ListePaginable {
|
985 |
jpm |
24 |
|
|
|
25 |
private static final long serialVersionUID = 2600314321196345072L;
|
1049 |
gduche |
26 |
private int currentPage = 0;
|
|
|
27 |
private int nbElementsPage = Integer.valueOf(((Dictionary) Dictionary.getDictionary("configuration")).get("nbElementsPage"));
|
|
|
28 |
private int nbElementsTotal;
|
|
|
29 |
private Rafraichissable vueARafraichir;
|
|
|
30 |
|
985 |
jpm |
31 |
public CommentaireListe() {
|
|
|
32 |
super();
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
public CommentaireListe(int taille) {
|
|
|
36 |
super(taille);
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Constructeur pour une liste de commentaires
|
|
|
41 |
* @param dates
|
|
|
42 |
*/
|
1166 |
jpm |
43 |
public CommentaireListe(JSONArray ListeDeCommentaires) {
|
|
|
44 |
super(ListeDeCommentaires.size());
|
|
|
45 |
initialiserCommentaireListe(ListeDeCommentaires);
|
985 |
jpm |
46 |
}
|
1049 |
gduche |
47 |
|
1166 |
jpm |
48 |
public CommentaireListe(JSONArray ListeDeCommentaires, JSONNumber nbElements, Rafraichissable vueARafraichir) {
|
1305 |
cyprien |
49 |
super(ListeDeCommentaires.size());
|
1049 |
gduche |
50 |
this.nbElementsTotal = Integer.valueOf(nbElements.toString());
|
1166 |
jpm |
51 |
this.vueARafraichir = vueARafraichir;
|
|
|
52 |
initialiserCommentaireListe(ListeDeCommentaires);
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
private void initialiserCommentaireListe(JSONArray ListeDeCommentaires) {
|
|
|
56 |
boolean chargerCollectionACommentaire = true;
|
|
|
57 |
final int taillemax = ListeDeCommentaires.size();
|
1305 |
cyprien |
58 |
|
1049 |
gduche |
59 |
for (int i = 0; i < taillemax; i++) {
|
1166 |
jpm |
60 |
JSONObject commentaireCourant = ListeDeCommentaires.get(i).isObject() ;
|
|
|
61 |
if (commentaireCourant != null) {
|
|
|
62 |
Commentaire commentaire = new Commentaire(commentaireCourant, chargerCollectionACommentaire);
|
1305 |
cyprien |
63 |
|
|
|
64 |
if (!Util.isEmptyString(commentaire.getCollectionACommentaire().getId())) {
|
|
|
65 |
this.put(commentaire.getCollectionACommentaire().getId(), commentaire);
|
|
|
66 |
}
|
|
|
67 |
else {
|
|
|
68 |
this.put(commentaire.getId(), commentaire);
|
|
|
69 |
}
|
1049 |
gduche |
70 |
}
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
public void changerNumeroPage(int pageCourante) {
|
|
|
75 |
currentPage = pageCourante;
|
|
|
76 |
selectionnerCommentaire();
|
|
|
77 |
}
|
|
|
78 |
|
|
|
79 |
public void changerTaillePage(int nouvelleTaillePage) {
|
|
|
80 |
nbElementsPage = nouvelleTaillePage;
|
|
|
81 |
selectionnerCommentaire();
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
public void recharger() {
|
|
|
85 |
selectionnerCommentaire();
|
|
|
86 |
}
|
|
|
87 |
|
|
|
88 |
public void setPageCourante(int pageCourante) {
|
|
|
89 |
this.currentPage = pageCourante;
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
public void setTaillePage(int taillePage) {
|
|
|
93 |
this.nbElementsPage = taillePage;
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
public int[] getPageTable() {
|
|
|
97 |
int[] page = new int[4];
|
|
|
98 |
// nombre de pages au total
|
|
|
99 |
page[0] = calculerNbPages();
|
|
|
100 |
// Page En Cours
|
|
|
101 |
page[1] = currentPage;
|
|
|
102 |
// nbElementsParPage
|
|
|
103 |
page[2] = nbElementsPage;
|
|
|
104 |
// et le dernier le nombre total d'éléments
|
|
|
105 |
page[3] = nbElementsTotal;
|
|
|
106 |
return page;
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
/**
|
|
|
110 |
* Calcule le nombre de pages nécessaires pour afficher un nombre d'élements
|
|
|
111 |
* donnés en fonction de la taille de page en cours
|
|
|
112 |
*
|
|
|
113 |
* @return le nombre de pages
|
|
|
114 |
*/
|
|
|
115 |
public int calculerNbPages() {
|
1305 |
cyprien |
116 |
// À cause de la bétise de java pour les conversions implicites, on fait quelques conversions manuellement
|
1166 |
jpm |
117 |
// pour eviter qu'il arrondisse mal la division nombre de pages = (nombre d'element / taille de la page)
|
|
|
118 |
// arrondie à l'entier supérieur.
|
1049 |
gduche |
119 |
double nPage = (1.0 * nbElementsTotal) / (1.0 * nbElementsPage);
|
|
|
120 |
double nPageRound = Math.ceil(nPage);
|
|
|
121 |
Double nPageInt = new Double(nPageRound);
|
|
|
122 |
|
1166 |
jpm |
123 |
// Convertion en entier
|
1049 |
gduche |
124 |
return nPageInt.intValue();
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
public void selectionnerCommentaire() {
|
1166 |
jpm |
128 |
Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);
|
1305 |
cyprien |
129 |
mediateur.selectionnerCommentaire(vueARafraichir, null, null, currentPage, nbElementsPage);
|
1049 |
gduche |
130 |
}
|
|
|
131 |
|
|
|
132 |
public void filtrerParNom(String nom) {
|
1166 |
jpm |
133 |
Mediateur mediateur = (Mediateur) Registry.get(RegistreId.MEDIATEUR);
|
1057 |
gduche |
134 |
mediateur.selectionnerCommentaireParTitre(vueARafraichir, "%" + nom + "%");
|
1049 |
gduche |
135 |
}
|
1166 |
jpm |
136 |
}
|