Subversion Repositories eFlore/Applications.del

Rev

Rev 2050 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2050 Rev 2054
1
package org.tela_botanica.del.client.vues.identiplante.resultats;
1
package org.tela_botanica.del.client.vues.identiplante.resultats;
2
 
2
 
3
import java.util.List;
3
import java.util.List;
4
 
4
 
5
import org.tela_botanica.del.client.cache.CacheClient;
5
import org.tela_botanica.del.client.cache.CacheClient;
6
import org.tela_botanica.del.client.composants.pagination.PaginationPresenteur;
6
import org.tela_botanica.del.client.composants.pagination.PaginationPresenteur;
7
import org.tela_botanica.del.client.composants.pagination.PaginationVue;
7
import org.tela_botanica.del.client.composants.pagination.PaginationVue;
8
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
8
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
9
import org.tela_botanica.del.client.gestionhistorique.ConstantesNavigation;
9
import org.tela_botanica.del.client.gestionhistorique.ConstantesNavigation;
-
 
10
import org.tela_botanica.del.client.modeles.ActiviteUtilisateur;
10
import org.tela_botanica.del.client.modeles.Image;
11
import org.tela_botanica.del.client.modeles.Image;
11
import org.tela_botanica.del.client.modeles.InformationsRecherche;
12
import org.tela_botanica.del.client.modeles.InformationsRecherche;
12
import org.tela_botanica.del.client.modeles.ModeTri;
13
import org.tela_botanica.del.client.modeles.ModeTri;
13
import org.tela_botanica.del.client.modeles.Observation;
14
import org.tela_botanica.del.client.modeles.Observation;
14
import org.tela_botanica.del.client.modeles.ObservationServiceResultat;
15
import org.tela_botanica.del.client.modeles.ObservationServiceResultat;
15
import org.tela_botanica.del.client.modeles.Utilisateur;
16
import org.tela_botanica.del.client.modeles.Utilisateur;
16
import org.tela_botanica.del.client.services.rest.ObservationService;
17
import org.tela_botanica.del.client.services.rest.ObservationService;
-
 
18
import org.tela_botanica.del.client.services.rest.UtilisateurServiceConcret;
-
 
19
import org.tela_botanica.del.client.services.rest.async.ActiviteUtilisateurCallback;
17
import org.tela_botanica.del.client.services.rest.async.ObservationsCallback;
20
import org.tela_botanica.del.client.services.rest.async.ObservationsCallback;
18
import org.tela_botanica.del.client.utils.StringUtils;
21
import org.tela_botanica.del.client.utils.StringUtils;
19
import org.tela_botanica.del.client.vues.identiplante.resultats.observations.ObservationPresenteur;
22
import org.tela_botanica.del.client.vues.identiplante.resultats.observations.ObservationPresenteur;
20
import org.tela_botanica.del.client.vues.identiplante.resultats.observations.ObservationVue;
23
import org.tela_botanica.del.client.vues.identiplante.resultats.observations.ObservationVue;
21
 
24
 
22
import com.google.gwt.event.dom.client.ClickEvent;
25
import com.google.gwt.event.dom.client.ClickEvent;
23
import com.google.gwt.event.dom.client.ClickHandler;
26
import com.google.gwt.event.dom.client.ClickHandler;
24
import com.google.gwt.event.dom.client.HasClickHandlers;
27
import com.google.gwt.event.dom.client.HasClickHandlers;
-
 
28
import com.google.gwt.user.client.Timer;
25
import com.google.gwt.user.client.Window;
29
import com.google.gwt.user.client.Window;
26
import com.google.gwt.user.client.ui.HasWidgets;
30
import com.google.gwt.user.client.ui.HasWidgets;
27
import com.google.gwt.user.client.ui.IsWidget;
31
import com.google.gwt.user.client.ui.IsWidget;
28
import com.google.gwt.user.client.ui.Label;
32
import com.google.gwt.user.client.ui.Label;
29
 
33
 
30
public class ResultatsIdentiplantePresenteur extends Presenteur {
34
public class ResultatsIdentiplantePresenteur extends Presenteur {
31
 
35
 
32
	/**
36
	/**
33
	 * Interface vue : création des composants graphiques
37
	 * Interface vue : création des composants graphiques
34
	 * */
38
	 * */
35
	public abstract interface Vue extends IsWidget {
39
	public abstract interface Vue extends IsWidget {
36
		public HasWidgets getZoneObservations();
40
		public HasWidgets getZoneObservations();
37
 
41
 
38
		public HasWidgets getZonePaginationHaut();
42
		public HasWidgets getZonePaginationHaut();
39
 
43
 
40
		public HasWidgets getZonePaginationBas();
44
		public HasWidgets getZonePaginationBas();
41
 
45
 
42
		public void startChargement();
46
		public void startChargement();
43
 
47
 
44
		public void stopChargement();
48
		public void stopChargement();
45
 
49
 
46
		public void nettoyer();
50
		public void nettoyer();
47
 
51
 
48
		public HasClickHandlers getTriParDateObservationAscendant();
52
		public HasClickHandlers getTriParDateObservationAscendant();
49
 
53
 
50
		public HasClickHandlers getTriParDateObservationDescendant();
54
		public HasClickHandlers getTriParDateObservationDescendant();
51
		
55
		
52
		public HasClickHandlers getTriParDatePublicationAscendant();
56
		public HasClickHandlers getTriParDatePublicationAscendant();
53
 
57
 
54
		public HasClickHandlers getTriParDatePublicationDescendant();
58
		public HasClickHandlers getTriParDatePublicationDescendant();
55
		
59
		
56
		public HasClickHandlers getTriParNbCommentairesAscendant();
60
		public HasClickHandlers getTriParNbCommentairesAscendant();
57
 
61
 
58
		public HasClickHandlers getTriParNbCommentairesDescendant();
62
		public HasClickHandlers getTriParNbCommentairesDescendant();
59
 
63
 
60
		public void afficherElementsAucunResultatTrouve();
64
		public void afficherElementsAucunResultatTrouve();
61
 
65
 
62
		public void afficherElementsResultatsTrouves();
66
		public void afficherElementsResultatsTrouves();
63
 
67
 
64
		public HasClickHandlers getLabelDateObservation();
68
		public HasClickHandlers getLabelDateObservation();
65
		
69
		
66
		public HasClickHandlers getLabelDatePublication();
70
		public HasClickHandlers getLabelDatePublication();
67
		
71
		
68
		public HasClickHandlers getLabelNbCommentaires();
72
		public HasClickHandlers getLabelNbCommentaires();
69
 
73
 
70
		void setModeTriPublication(ModeTri mode);
74
		void setModeTriPublication(ModeTri mode);
71
 
75
 
72
		void setModeTriObservation(ModeTri mode);
76
		void setModeTriObservation(ModeTri mode);
73
 
77
 
74
		void setModeTriNbCommentaires(ModeTri mode);
78
		void setModeTriNbCommentaires(ModeTri mode);
75
		
79
		
76
		void afficherCacherZoneTri(boolean afficher);
80
		void afficherCacherZoneTri(boolean afficher);
77
	}
81
	}
78
 
82
 
79
	private Vue vue;
83
	private Vue vue;
80
	private ObservationService serviceObs;
84
	private ObservationService serviceObs;
81
	private ModeTri triCourantDatePublication = ModeTri.TRI_DESCENDANT;
85
	private ModeTri triCourantDatePublication = ModeTri.TRI_DESCENDANT;
82
	private ModeTri triCourantDateObservation = ModeTri.PAS_DE_TRI;
86
	private ModeTri triCourantDateObservation = ModeTri.PAS_DE_TRI;
83
	private ModeTri triCourantNbCommentaires = ModeTri.PAS_DE_TRI;
87
	private ModeTri triCourantNbCommentaires = ModeTri.PAS_DE_TRI;
84
	private CacheClient cache = CacheClient.getInstance();
88
	private CacheClient cache = CacheClient.getInstance();
85
	private String statut;
89
	private String statut;
86
 
90
 
87
	/**
91
	/**
88
	 * Constructeur de la classe
92
	 * Constructeur de la classe
89
	 * 
93
	 * 
90
	 * @param ObservationService
94
	 * @param ObservationService
91
	 *            serviceObs le service pour récupérer les observations
95
	 *            serviceObs le service pour récupérer les observations
92
	 * @Vue Vue l'objet implémentant l'interface
96
	 * @Vue Vue l'objet implémentant l'interface
93
	 * */
97
	 * */
94
	public ResultatsIdentiplantePresenteur(ObservationService serviceObs, Vue vue) {
98
	public ResultatsIdentiplantePresenteur(ObservationService serviceObs, Vue vue) {
95
		String statut = CacheClient.getInstance().getFiltreStatut();
99
		String statut = CacheClient.getInstance().getFiltreStatut();
96
		this.vue = vue;
100
		this.vue = vue;
97
		InformationsRecherche infos = CacheClient.getInstance().getInformationsRechercheObservation();
101
		InformationsRecherche infos = CacheClient.getInstance().getInformationsRechercheObservation();
98
		
102
		
99
		if (infos.getTriParDatePublication() != ModeTri.PAS_DE_TRI) {
103
		if (infos.getTriParDatePublication() != ModeTri.PAS_DE_TRI) {
100
			triCourantDatePublication = infos.getTriParDatePublication();
104
			triCourantDatePublication = infos.getTriParDatePublication();
101
			vue.setModeTriPublication(triCourantDatePublication);
105
			vue.setModeTriPublication(triCourantDatePublication);
102
		}
106
		}
103
		
107
		
104
		if (infos.getTriParDateObservation() != ModeTri.PAS_DE_TRI) {
108
		if (infos.getTriParDateObservation() != ModeTri.PAS_DE_TRI) {
105
			triCourantDateObservation = infos.getTriParDateObservation();
109
			triCourantDateObservation = infos.getTriParDateObservation();
106
			vue.setModeTriObservation(triCourantDatePublication);
110
			vue.setModeTriObservation(triCourantDatePublication);
107
		}
111
		}
108
			
112
			
109
		if (infos.getTriParNbCommentaires() != ModeTri.PAS_DE_TRI) {
113
		if (infos.getTriParNbCommentaires() != ModeTri.PAS_DE_TRI) {
110
			triCourantNbCommentaires = infos.getTriParNbCommentaires();
114
			triCourantNbCommentaires = infos.getTriParNbCommentaires();
111
			vue.setModeTriNbCommentaires(triCourantNbCommentaires);
115
			vue.setModeTriNbCommentaires(triCourantNbCommentaires);
112
		}
116
		}
113
		
117
		
114
		this.serviceObs = serviceObs;
118
		this.serviceObs = serviceObs;
115
		this.statut = statut;
119
		this.statut = statut;
116
	}
120
	}
117
 
121
 
118
	/**
122
	/**
119
	 * Lancer l'affichage de la recherche dans le composant passé en paramètre
123
	 * Lancer l'affichage de la recherche dans le composant passé en paramètre
120
	 * 
124
	 * 
121
	 * @param HasWidgets composite le conteneur de widgets dans lequel ajouter la vue
125
	 * @param HasWidgets composite le conteneur de widgets dans lequel ajouter la vue
122
	 * */
126
	 * */
123
	public void go(HasWidgets composite) {
127
	public void go(HasWidgets composite) {
124
		composite.add(vue.asWidget());
128
		composite.add(vue.asWidget());
125
		lancerRechercheEtCreerWidgetPagination();
129
		lancerRechercheEtCreerWidgetPagination();
126
		gererEvenements();
130
		gererEvenements();
127
	}
131
	}
128
 
132
 
129
	/**
133
	/**
130
	 * Initier un callback pour créer le widget de pagination et afficher les
134
	 * Initier un callback pour créer le widget de pagination et afficher les
131
	 * observations recues et lancer la recherche avec le service
135
	 * observations recues et lancer la recherche avec le service
132
	 * */
136
	 * */
133
	public void lancerRechercheEtCreerWidgetPagination() {
137
	public void lancerRechercheEtCreerWidgetPagination() {
134
		
138
		
135
		int debut = (cache.getPageCouranteRechercheObservations() - 1) * cache.getPasPagination();
139
		int debut = (cache.getPageCouranteRechercheObservations() - 1) * cache.getPasPagination();
136
		int fin = cache.getPageCouranteRechercheObservations() * cache.getPasPagination();
140
		int fin = cache.getPageCouranteRechercheObservations() * cache.getPasPagination();
137
 
141
 
138
		ObservationsCallback callback = new ObservationsCallback() {
142
		ObservationsCallback callback = new ObservationsCallback() {
139
 
143
 
140
			@Override
144
			@Override
141
			public void surRetour(ObservationServiceResultat observationsRecues) {
145
			public void surRetour(ObservationServiceResultat observationsRecues) {
142
				creerWidgetPagination(observationsRecues.getNbTotalObservationsPourLaRecherche());
146
				creerWidgetPagination(observationsRecues.getNbTotalObservationsPourLaRecherche());
143
				afficherObservations(observationsRecues);
147
				afficherObservations(observationsRecues);
144
 
148
 
145
			}
149
			}
146
 
150
 
147
			@Override
151
			@Override
148
			public void surErreur(String messageErreur) {
152
			public void surErreur(String messageErreur) {
149
				Window.alert(messageErreur);
153
				Window.alert(messageErreur);
150
 
154
 
151
			}
155
			}
152
		};
156
		};
153
 
157
 
154
		serviceObs.getObservations(cache.getInformationsRechercheObservation(), debut, fin, statut, callback);
158
		serviceObs.getObservations(cache.getInformationsRechercheObservation(), debut, fin, statut, callback);
155
	}
159
	}
156
 
160
 
157
	/**
161
	/**
158
	 * Créer les widgets de pagination en fonction du nombre d'observation
162
	 * Créer les widgets de pagination en fonction du nombre d'observation
159
	 * 
163
	 * 
160
	 * @param int nbObservations le nombre d'observations à afficher
164
	 * @param int nbObservations le nombre d'observations à afficher
161
	 * */
165
	 * */
162
	private void creerWidgetPagination(int nbObservations) {
166
	private void creerWidgetPagination(int nbObservations) {
163
		vue.getZonePaginationHaut().clear();
167
		vue.getZonePaginationHaut().clear();
164
		PaginationPresenteur paginationPresenteurHaut = creerPresenteurPagination(nbObservations);
168
		PaginationPresenteur paginationPresenteurHaut = creerPresenteurPagination(nbObservations);
165
		paginationPresenteurHaut.setGroupePagination("pagination_observations");
169
		paginationPresenteurHaut.setGroupePagination("pagination_observations");
166
		paginationPresenteurHaut.go(vue.getZonePaginationHaut());
170
		paginationPresenteurHaut.go(vue.getZonePaginationHaut());
167
 
171
 
168
		vue.getZonePaginationBas().clear();
172
		vue.getZonePaginationBas().clear();
169
		PaginationPresenteur paginationPresenteurBas = creerPresenteurPagination(nbObservations);
173
		PaginationPresenteur paginationPresenteurBas = creerPresenteurPagination(nbObservations);
170
		paginationPresenteurBas.setGroupePagination("pagination_observations");
174
		paginationPresenteurBas.setGroupePagination("pagination_observations");
171
		paginationPresenteurBas.go(vue.getZonePaginationBas());
175
		paginationPresenteurBas.go(vue.getZonePaginationBas());
172
	}
176
	}
173
 
177
 
174
	/**
178
	/**
175
	 * Créer un présenteur du widget pagination
179
	 * Créer un présenteur du widget pagination
176
	 * 
180
	 * 
177
	 * @param int nbObservations le nombre total d'observation à afficher
181
	 * @param int nbObservations le nombre total d'observation à afficher
178
	 * */
182
	 * */
179
	private PaginationPresenteur creerPresenteurPagination(int nbObservations) {
183
	private PaginationPresenteur creerPresenteurPagination(int nbObservations) {
180
		PaginationPresenteur presenteur = new PaginationPresenteur(new PaginationVue(), nbObservations, cache.getPasPagination(), cache.getPageCouranteRechercheObservations()) {
184
		PaginationPresenteur presenteur = new PaginationPresenteur(new PaginationVue(), nbObservations, cache.getPasPagination(), cache.getPageCouranteRechercheObservations()) {
181
 
185
 
182
			@Override
186
			@Override
183
			public void chargerElements(int debut, int fin) {
187
			public void chargerElements(int debut, int fin) {
184
				chargerEtAfficherObservations(debut, fin);
188
				chargerEtAfficherObservations(debut, fin);
185
				cache.setPageCouranteRechercheObservations(getPageCourante());
189
				cache.setPageCouranteRechercheObservations(getPageCourante());
186
			}
190
			}
187
 
191
 
188
			@Override
192
			@Override
189
			public void actualiserPasCache(int pas) {
193
			public void actualiserPasCache(int pas) {
190
				cache.setPasPagination(pas);
194
				cache.setPasPagination(pas);
191
			}
195
			}
192
 
196
 
193
		};
197
		};
194
		return presenteur;
198
		return presenteur;
195
	}
199
	}
196
 
200
 
197
	/**
201
	/**
198
	 * Gestion des évènements de la vue recherche Observation
202
	 * Gestion des évènements de la vue recherche Observation
199
	 * */
203
	 * */
200
	protected void gererEvenements() {
204
	protected void gererEvenements() {
201
 
205
 
202
		ClickHandler surClicDateObservation = new ClickHandler() {
206
		ClickHandler surClicDateObservation = new ClickHandler() {
203
			/**
207
			/**
204
			 * Gestion du clic sur l'option de tri par date d'observation Masque
208
			 * Gestion du clic sur l'option de tri par date d'observation Masque
205
			 * les éléments de tri qui sont en cours et affiche les autres
209
			 * les éléments de tri qui sont en cours et affiche les autres
206
			 * */
210
			 * */
207
			public void onClick(ClickEvent event) {
211
			public void onClick(ClickEvent event) {
208
				toggleModeTriObservation();
212
				toggleModeTriObservation();
209
 
213
 
210
				InformationsRecherche informationsRechercheObservations = cache.getInformationsRechercheObservation();
214
				InformationsRecherche informationsRechercheObservations = cache.getInformationsRechercheObservation();
211
				informationsRechercheObservations.setTriParDatePublication(ModeTri.PAS_DE_TRI);
215
				informationsRechercheObservations.setTriParDatePublication(ModeTri.PAS_DE_TRI);
212
				informationsRechercheObservations.setTriParNbCommentaires(ModeTri.PAS_DE_TRI);
216
				informationsRechercheObservations.setTriParNbCommentaires(ModeTri.PAS_DE_TRI);
213
				informationsRechercheObservations.setTriParDateObservation(triCourantDateObservation);
217
				informationsRechercheObservations.setTriParDateObservation(triCourantDateObservation);
214
				chercherEtAfficherObservationsPageEnCours();
218
				chercherEtAfficherObservationsPageEnCours();
215
			}
219
			}
216
		};
220
		};
217
		
221
		
218
		ClickHandler surClicDatePublication = new ClickHandler() {
222
		ClickHandler surClicDatePublication = new ClickHandler() {
219
			/**
223
			/**
220
			 * Gestion du clic sur l'option de tri par date d'observation Masque
224
			 * Gestion du clic sur l'option de tri par date d'observation Masque
221
			 * les éléments de tri qui sont en cours et affiche les autres
225
			 * les éléments de tri qui sont en cours et affiche les autres
222
			 * */
226
			 * */
223
			public void onClick(ClickEvent event) {
227
			public void onClick(ClickEvent event) {
224
				toggleModeTriPublication();
228
				toggleModeTriPublication();
225
 
229
 
226
				InformationsRecherche informationsRechercheObservations = cache.getInformationsRechercheObservation();
230
				InformationsRecherche informationsRechercheObservations = cache.getInformationsRechercheObservation();
227
				informationsRechercheObservations.setTriParDateObservation(ModeTri.PAS_DE_TRI);
231
				informationsRechercheObservations.setTriParDateObservation(ModeTri.PAS_DE_TRI);
228
				informationsRechercheObservations.setTriParNbCommentaires(ModeTri.PAS_DE_TRI);
232
				informationsRechercheObservations.setTriParNbCommentaires(ModeTri.PAS_DE_TRI);
229
				informationsRechercheObservations.setTriParDatePublication(triCourantDatePublication);
233
				informationsRechercheObservations.setTriParDatePublication(triCourantDatePublication);
230
 
234
 
231
				chercherEtAfficherObservationsPageEnCours();
235
				chercherEtAfficherObservationsPageEnCours();
232
			}
236
			}
233
		};
237
		};
234
		
238
		
235
		ClickHandler surClicNbCommentaires = new ClickHandler() {
239
		ClickHandler surClicNbCommentaires = new ClickHandler() {
236
			/**
240
			/**
237
			 * Même comportement qu'au dessus mais pour le tri par nb de commentaires
241
			 * Même comportement qu'au dessus mais pour le tri par nb de commentaires
238
			 */
242
			 */
239
			public void onClick(ClickEvent event) {
243
			public void onClick(ClickEvent event) {
240
				toggleModeTriNbCommentaires();
244
				toggleModeTriNbCommentaires();
241
 
245
 
242
				InformationsRecherche informationsRechercheObservations = cache.getInformationsRechercheObservation();
246
				InformationsRecherche informationsRechercheObservations = cache.getInformationsRechercheObservation();
243
				informationsRechercheObservations.setTriParDateObservation(ModeTri.PAS_DE_TRI);
247
				informationsRechercheObservations.setTriParDateObservation(ModeTri.PAS_DE_TRI);
244
				informationsRechercheObservations.setTriParDatePublication(ModeTri.PAS_DE_TRI);
248
				informationsRechercheObservations.setTriParDatePublication(ModeTri.PAS_DE_TRI);
245
				informationsRechercheObservations.setTriParNbCommentaires(triCourantNbCommentaires);
249
				informationsRechercheObservations.setTriParNbCommentaires(triCourantNbCommentaires);
246
				chercherEtAfficherObservationsPageEnCours();
250
				chercherEtAfficherObservationsPageEnCours();
247
			}
251
			}
248
		};
252
		};
249
 
253
 
250
		vue.getLabelDateObservation().addClickHandler(surClicDateObservation);
254
		vue.getLabelDateObservation().addClickHandler(surClicDateObservation);
251
		vue.getTriParDateObservationAscendant().addClickHandler(surClicDateObservation);
255
		vue.getTriParDateObservationAscendant().addClickHandler(surClicDateObservation);
252
		vue.getTriParDateObservationDescendant().addClickHandler(surClicDateObservation);
256
		vue.getTriParDateObservationDescendant().addClickHandler(surClicDateObservation);
253
		
257
		
254
		vue.getLabelDatePublication().addClickHandler(surClicDatePublication);
258
		vue.getLabelDatePublication().addClickHandler(surClicDatePublication);
255
		vue.getTriParDatePublicationAscendant().addClickHandler(surClicDatePublication);
259
		vue.getTriParDatePublicationAscendant().addClickHandler(surClicDatePublication);
256
		vue.getTriParDatePublicationDescendant().addClickHandler(surClicDatePublication);
260
		vue.getTriParDatePublicationDescendant().addClickHandler(surClicDatePublication);
257
		
261
		
258
		vue.getLabelNbCommentaires().addClickHandler(surClicNbCommentaires);
262
		vue.getLabelNbCommentaires().addClickHandler(surClicNbCommentaires);
259
		vue.getTriParNbCommentairesAscendant().addClickHandler(surClicNbCommentaires);
263
		vue.getTriParNbCommentairesAscendant().addClickHandler(surClicNbCommentaires);
260
		vue.getTriParNbCommentairesDescendant().addClickHandler(surClicNbCommentaires);
264
		vue.getTriParNbCommentairesDescendant().addClickHandler(surClicNbCommentaires);
261
	}
265
	}
262
 
266
 
263
	/**
267
	/**
264
	 * Inverser le mode de tri en fonction du précédent
268
	 * Inverser le mode de tri en fonction du précédent
265
	 * */
269
	 * */
266
	public void toggleModeTriPublication() {
270
	public void toggleModeTriPublication() {
267
		if (triCourantDatePublication == ModeTri.TRI_ASCENDANT) {
271
		if (triCourantDatePublication == ModeTri.TRI_ASCENDANT) {
268
			triCourantDatePublication = ModeTri.TRI_DESCENDANT;
272
			triCourantDatePublication = ModeTri.TRI_DESCENDANT;
269
		} else if(triCourantDatePublication == ModeTri.TRI_DESCENDANT) {
273
		} else if(triCourantDatePublication == ModeTri.TRI_DESCENDANT) {
270
			triCourantDatePublication = ModeTri.TRI_ASCENDANT;
274
			triCourantDatePublication = ModeTri.TRI_ASCENDANT;
271
		} else {
275
		} else {
272
			triCourantDatePublication = ModeTri.TRI_DESCENDANT;
276
			triCourantDatePublication = ModeTri.TRI_DESCENDANT;
273
		}
277
		}
274
		
278
		
275
		triCourantDateObservation = ModeTri.PAS_DE_TRI;
279
		triCourantDateObservation = ModeTri.PAS_DE_TRI;
276
		triCourantNbCommentaires = ModeTri.PAS_DE_TRI;
280
		triCourantNbCommentaires = ModeTri.PAS_DE_TRI;
277
 
281
 
278
		vue.setModeTriPublication(triCourantDatePublication);
282
		vue.setModeTriPublication(triCourantDatePublication);
279
	}
283
	}
280
	
284
	
281
	/**
285
	/**
282
	 * Inverser le mode de tri en fonction du précédent
286
	 * Inverser le mode de tri en fonction du précédent
283
	 * */
287
	 * */
284
	public void toggleModeTriObservation() {
288
	public void toggleModeTriObservation() {
285
		if (triCourantDateObservation == ModeTri.TRI_ASCENDANT) {
289
		if (triCourantDateObservation == ModeTri.TRI_ASCENDANT) {
286
			triCourantDateObservation = ModeTri.TRI_DESCENDANT;
290
			triCourantDateObservation = ModeTri.TRI_DESCENDANT;
287
		} else if(triCourantDateObservation == ModeTri.TRI_DESCENDANT) {
291
		} else if(triCourantDateObservation == ModeTri.TRI_DESCENDANT) {
288
			triCourantDateObservation = ModeTri.TRI_ASCENDANT;
292
			triCourantDateObservation = ModeTri.TRI_ASCENDANT;
289
		} else {
293
		} else {
290
			triCourantDateObservation = ModeTri.TRI_DESCENDANT;
294
			triCourantDateObservation = ModeTri.TRI_DESCENDANT;
291
		}
295
		}
292
		
296
		
293
		triCourantDatePublication = ModeTri.PAS_DE_TRI;
297
		triCourantDatePublication = ModeTri.PAS_DE_TRI;
294
		triCourantNbCommentaires = ModeTri.PAS_DE_TRI;
298
		triCourantNbCommentaires = ModeTri.PAS_DE_TRI;
295
 
299
 
296
		vue.setModeTriObservation(triCourantDateObservation);
300
		vue.setModeTriObservation(triCourantDateObservation);
297
	}
301
	}
298
	
302
	
299
	/**
303
	/**
300
	 * Inverser le mode de tri en fonction du précédent
304
	 * Inverser le mode de tri en fonction du précédent
301
	 * */
305
	 * */
302
	public void toggleModeTriNbCommentaires() {
306
	public void toggleModeTriNbCommentaires() {
303
		if (triCourantNbCommentaires == ModeTri.TRI_ASCENDANT) {
307
		if (triCourantNbCommentaires == ModeTri.TRI_ASCENDANT) {
304
			triCourantNbCommentaires = ModeTri.TRI_DESCENDANT;
308
			triCourantNbCommentaires = ModeTri.TRI_DESCENDANT;
305
		} else if(triCourantNbCommentaires == ModeTri.TRI_DESCENDANT) {
309
		} else if(triCourantNbCommentaires == ModeTri.TRI_DESCENDANT) {
306
			triCourantNbCommentaires = ModeTri.TRI_ASCENDANT;
310
			triCourantNbCommentaires = ModeTri.TRI_ASCENDANT;
307
		} else {
311
		} else {
308
			triCourantNbCommentaires = ModeTri.TRI_DESCENDANT;
312
			triCourantNbCommentaires = ModeTri.TRI_DESCENDANT;
309
		}
313
		}
310
		
314
		
311
		triCourantDateObservation = ModeTri.PAS_DE_TRI;
315
		triCourantDateObservation = ModeTri.PAS_DE_TRI;
312
		triCourantDatePublication = ModeTri.PAS_DE_TRI;
316
		triCourantDatePublication = ModeTri.PAS_DE_TRI;
313
 
317
 
314
		vue.setModeTriNbCommentaires(triCourantNbCommentaires);
318
		vue.setModeTriNbCommentaires(triCourantNbCommentaires);
315
	}
319
	}
316
 
320
 
317
	/**
321
	/**
318
	 * Initialiser les variable de début et fin et lancer le chargement des
322
	 * Initialiser les variable de début et fin et lancer le chargement des
319
	 * observations
323
	 * observations
320
	 * */
324
	 * */
321
	public void chercherEtAfficherObservationsPageEnCours() {
325
	public void chercherEtAfficherObservationsPageEnCours() {
322
		int debut = (cache.getPageCouranteRechercheObservations() - 1) * cache.getPasPagination();
326
		int debut = (cache.getPageCouranteRechercheObservations() - 1) * cache.getPasPagination();
323
		int fin = (cache.getPageCouranteRechercheObservations()) * cache.getPasPagination();
327
		int fin = (cache.getPageCouranteRechercheObservations()) * cache.getPasPagination();
324
		chargerEtAfficherObservations(debut, fin);
328
		chargerEtAfficherObservations(debut, fin);
325
	}
329
	}
326
 
330
 
327
	/**
331
	/**
328
	 * Lancer le service pour charger les observations entre debut et fin et les
332
	 * Lancer le service pour charger les observations entre debut et fin et les
329
	 * afficher
333
	 * afficher
330
	 * 
334
	 * 
331
	 * @param int debut l'entier de départ de la requete
335
	 * @param int debut l'entier de départ de la requete
332
	 * @param int fin l'entier de limite de la requete
336
	 * @param int fin l'entier de limite de la requete
333
	 * */
337
	 * */
334
	public void chargerEtAfficherObservations(int debut, int fin) {
338
	public void chargerEtAfficherObservations(int debut, int fin) {
335
		vue.startChargement();
339
		vue.startChargement();
336
		vue.nettoyer();
340
		vue.nettoyer();
337
 
341
 
338
		ObservationsCallback surReceptionObservation = new ObservationsCallback() {
342
		ObservationsCallback surReceptionObservation = new ObservationsCallback() {
339
 
343
 
340
			@Override
344
			@Override
341
			public void surRetour(ObservationServiceResultat observationsRecues) {
345
			public void surRetour(ObservationServiceResultat observationsRecues) {
342
				afficherObservations(observationsRecues);
346
				afficherObservations(observationsRecues);
343
 
347
 
344
			}
348
			}
345
 
349
 
346
			@Override
350
			@Override
347
			public void surErreur(String messageErreur) {
351
			public void surErreur(String messageErreur) {
348
				Window.alert(messageErreur);
352
				Window.alert(messageErreur);
349
 
353
 
350
			}
354
			}
351
		};
355
		};
352
		serviceObs.getObservations(cache.getInformationsRechercheObservation(), debut, fin, statut, surReceptionObservation);
356
		serviceObs.getObservations(cache.getInformationsRechercheObservation(), debut, fin, statut, surReceptionObservation);
353
	}
357
	}
354
 
358
 
355
	/**
359
	/**
356
	 * Parcrourir les résultats de la recherche pour initier l'affichage de
360
	 * Parcrourir les résultats de la recherche pour initier l'affichage de
357
	 * chaque observation
361
	 * chaque observation
358
	 * 
362
	 * 
359
	 * @param ObservationServiceResultat
363
	 * @param ObservationServiceResultat
360
	 *            resultats les résultats issus de la requête
364
	 *            resultats les résultats issus de la requête
361
	 * */
365
	 * */
362
	private void afficherObservations(ObservationServiceResultat resultats) {
366
	private void afficherObservations(ObservationServiceResultat resultats) {
363
		vue.nettoyer();
367
		vue.nettoyer();
364
 
368
 
365
		if (resultats.getObservations() == null || resultats.getObservations().size() == 0) {
369
		if (resultats.getObservations() == null || resultats.getObservations().size() == 0) {
366
			vue.afficherElementsAucunResultatTrouve();
370
			vue.afficherElementsAucunResultatTrouve();
367
		} else {
371
		} else {
368
			vue.afficherElementsResultatsTrouves();
372
			vue.afficherElementsResultatsTrouves();
369
			
373
			
370
			// Si on consulte l'onglet mon activité, on cache le tri qui n'a pas de sens ici car c'est une timeline
374
			// Si on consulte l'onglet mon activité, on cache le tri qui n'a pas de sens ici car c'est une timeline
371
			vue.afficherCacherZoneTri(!cache.getFiltreStatut().equals(ConstantesNavigation.PARAM_TYPE_MONACTIVITE));
375
			vue.afficherCacherZoneTri(!cache.getFiltreStatut().equals(ConstantesNavigation.PARAM_TYPE_MONACTIVITE));
372
			// S'il y a de nouveau évènements sur l'obs, elle doit être mise en valeur
376
			// S'il y a de nouveau évènements sur l'obs, elle doit être mise en valeur
373
			// les x premieres obs sont affichées un peu différemment (où x est le nombre de nouveaux évènements)
377
			// les x premieres obs sont affichées un peu différemment (où x est le nombre de nouveaux évènements)
374
			int i = 0;
378
			int i = 0;
375
			int nbEvents = CacheClient.getInstance().getUtilisateur().getNbEvenementsInt();
379
			int nbEvents = CacheClient.getInstance().getUtilisateur().getActivite().getNbEvenementsInt();
376
			
380
			
377
			for (Observation observation : resultats.getObservations()) {
381
			for (Observation observation : resultats.getObservations()) {
378
				List<Image> listeImagesObs = observation.getImages();
382
				List<Image> listeImagesObs = observation.getImages();
379
				Image imagePrincipale = null;
383
				Image imagePrincipale = null;
380
				if(listeImagesObs != null && listeImagesObs.size() > 0) {
384
				if(listeImagesObs != null && listeImagesObs.size() > 0) {
381
					imagePrincipale = listeImagesObs.get(0);
385
					imagePrincipale = listeImagesObs.get(0);
382
				}
386
				}
383
				ObservationPresenteur presenteur = new ObservationPresenteur(new ObservationVue(), observation, imagePrincipale);
387
				ObservationPresenteur presenteur = new ObservationPresenteur(new ObservationVue(), observation, imagePrincipale);
384
				presenteur.go(vue.getZoneObservations());
388
				presenteur.go(vue.getZoneObservations());
-
 
389
				
-
 
390
				// La taille de la page s'étant adaptée au nombre de nouveaux évènements, on applique
385
				
391
				// uniquement la mise en valeur sur la premiere
386
				if(nbEvents != 0 && i <= nbEvents) {
392
				if(nbEvents != 0 && i < nbEvents && cache.getPageCouranteRechercheObservations() == 1) {
387
					presenteur.mettreEnValeurEvenementsObs();
393
					presenteur.mettreEnValeurEvenementsObs();
388
				}
394
				}
389
				i++;
395
				i++;
390
			}
396
			}
391
		}
397
		}
392
		CacheClient.getInstance().mettreAjourUrlCourante();
398
		CacheClient.getInstance().mettreAjourUrlCourante();
393
		vue.stopChargement();
399
		vue.stopChargement();
394
	}
400
	}
395
}
401
}