Subversion Repositories eFlore/Applications.coel

Rev

Rev 363 | Rev 616 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
102 jpm 1
package org.tela_botanica.client.modeles;
2
 
593 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;
7
 
8
import com.extjs.gxt.ui.client.Registry;
9
import com.google.gwt.i18n.client.Dictionary;
102 jpm 10
import com.google.gwt.json.client.JSONArray;
593 gduche 11
import com.google.gwt.json.client.JSONNumber;
102 jpm 12
import com.google.gwt.json.client.JSONObject;
593 gduche 13
import com.google.gwt.json.client.JSONString;
102 jpm 14
 
15
/**
16
 * Table de hachage composée d'informations sur les Valeurs des listes, renvoyé par un objet de type DAO
17
 * La clé est le nom de l'entite + le nom de l'entite parente
18
 *
19
 * @author david delon
20
 *
21
 */
593 gduche 22
public class PersonneListe extends aDonneeListe<Personne> implements ListePaginable{
102 jpm 23
 
363 jp_milcent 24
	private static final long serialVersionUID = 2930530504922300155L;
593 gduche 25
	private int currentPage = 0;
26
	private int nbElementsPage = Integer.valueOf(((Dictionary) Dictionary.getDictionary("configuration")).get("nbElementsPage"));
27
	private int nbElementsTotal;
28
	private Rafraichissable vueARafraichir;
102 jpm 29
	/**
30
	 * Constructeur sans paramètres
31
	 */
32
	public PersonneListe() {
33
		super();
34
	}
35
 
36
	/**
37
	 * Constructeur avec paramètre
38
	 * @param taille la taille de la table de hachage
39
	 */
40
	public PersonneListe(int taille) {
41
		super(taille);
42
	}
126 gduche 43
 
102 jpm 44
	/**
45
	 * Constructeur pour une liste de personne
46
	 * @param dates
47
	 */
126 gduche 48
	public PersonneListe(JSONArray personneListe) {
49
		super(personneListe.size());
50
 
51
		final int taillemax = personneListe.size();
52
		for (int i = 0; i < taillemax; i++) {
53
			JSONObject personneCourante = personneListe.get(i).isObject() ;
54
 
55
			if (personneCourante != null)	{
56
				Personne personne = new Personne(personneCourante);
138 gduche 57
				this.put(personne.getId(), personne);
126 gduche 58
			}
59
		}
593 gduche 60
	}
61
 
62
	public PersonneListe(JSONArray personneListe, JSONNumber nbElements, Rafraichissable vueARafraichir) {
63
		super(personneListe.size());
126 gduche 64
 
593 gduche 65
		this.nbElementsTotal = Integer.valueOf(nbElements.toString());
66
		final int taillemax = personneListe.size();
67
		for (int i = 0; i < taillemax; i++) {
68
			JSONObject personneCourante = personneListe.get(i).isObject() ;
69
 
70
			if (personneCourante != null)	{
71
				Personne personne = new Personne(personneCourante);
72
				this.put(personne.getId(), personne);
73
			}
74
		}
75
 
76
		this.vueARafraichir = vueARafraichir;
102 jpm 77
	}
593 gduche 78
 
79
	public int[] getPageTable() {
80
 
81
		int[] page = new int[4];
82
 
83
		//nombre de pages au total
84
		page[0] = calculerNbPages();
85
 
86
		//Page En Cours
87
		page[1] = currentPage;
88
 
89
		//nbElementsParPage
90
		page[2] = nbElementsPage;
91
 
92
		// et le dernier le nombre total d'éléments
93
		page[3] = nbElementsTotal;
94
 
95
		return page;
96
	}
97
 
98
	/**
99
	 * Calcule le nombre de pages nécessaires pour afficher un nombre d'élements donnés en fonction de la taille de page
100
	 * en cours
101
	 * @return le nombre de pages
102
	 */
103
	public int calculerNbPages()
104
	{
105
		// A cause de la betise de java pour les conversion implicite on fait quelques conversions manuellement
106
		// pour eviter qu'il arrondisse mal la division
107
		// nombre de pages = (nombre d'element / taille de la page) arrondie à l'entier superieur
108
 
109
		double nPage = (1.0*nbElementsTotal)/(1.0*nbElementsPage) ;
110
		double nPageRound = Math.ceil(nPage) ;
111
		Double nPageInt = new Double(nPageRound) ;
112
 
113
		// on convertit en entier
114
		return nPageInt.intValue() ;
115
	}
116
 
117
	@Override
118
	public void changerNumeroPage(int pageCourante) {
119
 
120
		currentPage = pageCourante;
121
		selectionnerPersonne();
122
	}
123
 
124
	@Override
125
	public void changerTaillePage(int nouvelleTaillePage) {
126
 
127
		nbElementsPage = nouvelleTaillePage;
128
		selectionnerPersonne();
129
	}
130
 
131
 
132
	public void setPageCourante(int pageCourante) {
133
		this.currentPage = pageCourante;
134
 
135
	};
136
 
137
 
138
	public void selectionnerPersonne()	{
139
		Mediateur mediateur =(Mediateur) Registry.get(RegistreId.MEDIATEUR);
140
		mediateur.selectionnerPersonne(vueARafraichir, null, null, currentPage, 15);
141
	}
142
 
143
 
363 jp_milcent 144
}