Subversion Repositories eFlore/Applications.coel

Rev

Rev 1687 | Details | Compare with Previous | Last modification | View Log | RSS feed

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