Subversion Repositories eFlore/Applications.coel

Rev

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