Subversion Repositories eFlore/Applications.coel

Rev

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

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