Subversion Repositories eFlore/Applications.coel

Rev

Rev 1046 | Rev 1166 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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