Subversion Repositories eFlore/Applications.del

Rev

Rev 591 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 591 Rev 593
Line 1... Line 1...
1
package org.tela_botanica.del.client.vues.rechercheimages.resultats;
1
package org.tela_botanica.del.client.vues.rechercheimages.resultats;
Line 2... Line 2...
2
 
2
 
3
import java.util.List;
-
 
4
 
3
import java.util.List;
5
import org.tela_botanica.del.client.cache.CacheClient;
4
import org.tela_botanica.del.client.cache.CacheClient;
6
import org.tela_botanica.del.client.composants.pagination.PaginationPresenteur;
5
import org.tela_botanica.del.client.composants.pagination.PaginationPresenteur;
7
import org.tela_botanica.del.client.composants.pagination.PaginationVue;
6
import org.tela_botanica.del.client.composants.pagination.PaginationVue;
8
import org.tela_botanica.del.client.modeles.Image;
7
import org.tela_botanica.del.client.modeles.Image;
Line 17... Line 16...
17
import org.tela_botanica.del.client.services.rest.ProtocoleService;
16
import org.tela_botanica.del.client.services.rest.ProtocoleService;
18
import org.tela_botanica.del.client.services.rest.async.ImagesParTaxonCallback;
17
import org.tela_botanica.del.client.services.rest.async.ImagesParTaxonCallback;
19
import org.tela_botanica.del.client.utils.MockDatasource;
18
import org.tela_botanica.del.client.utils.MockDatasource;
20
import org.tela_botanica.del.client.vues.rechercheimages.resultats.images.ImagePresenteur;
19
import org.tela_botanica.del.client.vues.rechercheimages.resultats.images.ImagePresenteur;
21
import org.tela_botanica.del.client.vues.rechercheimages.resultats.images.ImageVue;
20
import org.tela_botanica.del.client.vues.rechercheimages.resultats.images.ImageVue;
22
 
-
 
23
import com.google.gwt.event.dom.client.ChangeEvent;
21
import com.google.gwt.event.dom.client.ChangeEvent;
24
import com.google.gwt.event.dom.client.ChangeHandler;
22
import com.google.gwt.event.dom.client.ChangeHandler;
25
import com.google.gwt.event.dom.client.ClickEvent;
23
import com.google.gwt.event.dom.client.ClickEvent;
26
import com.google.gwt.event.dom.client.ClickHandler;
24
import com.google.gwt.event.dom.client.ClickHandler;
27
import com.google.gwt.event.dom.client.HasChangeHandlers;
25
import com.google.gwt.event.dom.client.HasChangeHandlers;
28
import com.google.gwt.event.dom.client.HasClickHandlers;
26
import com.google.gwt.event.dom.client.HasClickHandlers;
29
import com.google.gwt.user.client.ui.HTMLPanel;
27
import com.google.gwt.user.client.ui.HTMLPanel;
30
import com.google.gwt.user.client.ui.HasWidgets;
28
import com.google.gwt.user.client.ui.HasWidgets;
31
import com.google.gwt.user.client.ui.IsWidget;
29
import com.google.gwt.user.client.ui.IsWidget;
32
import com.google.gwt.user.client.ui.ListBox;
30
import com.google.gwt.user.client.ui.ListBox;
33
 
-
 
34
public class ResultatRechercheImagePresenteur {
31
public class ResultatRechercheImagePresenteur {
35
 
-
 
36
	public interface Vue extends IsWidget {
32
	public interface Vue extends IsWidget {
37
		public void startChargement();
33
		public void startChargement();
Line 38... Line 34...
38
 
34
 
Line 59... Line 55...
59
		public void afficherElementsAucunResultatTrouve();
55
		public void afficherElementsAucunResultatTrouve();
Line 60... Line 56...
60
 
56
 
Line 61... Line 57...
61
		public void afficherElementsResultatsTrouve();
57
		public void afficherElementsResultatsTrouve();
62
 
58
 
63
		public HTMLPanel getImageTable();
59
		public HTMLPanel getImageTable();
Line 64... Line 60...
64
		
60
 
65
		public String getNomProtocolSelectionne();
61
		public String getNomProtocolSelectionne();
66
 
62
 
67
		public int getIdProtocoleSelectionne();
63
		public int getIdProtocoleSelectionne();
68
		
64
 
69
		public void setListeProtocoles(ListBox listeProtocoles);
65
		public void setListeProtocoles(ListBox listeProtocoles);
70
		
66
 
Line 71... Line 67...
71
		public HasChangeHandlers getListeProtocoles();
67
		public HasChangeHandlers getListeProtocoles();
72
		
68
 
73
		public void ajouterProtocole(String protocole);
69
		public void ajouterProtocole(String protocole);
74
 
70
 
75
		public void selectionnerProtocole(int index);
71
		public void selectionnerProtocole(int index);
Line 76... Line 72...
76
		
72
 
77
		public HasClickHandlers getLabelVote();
73
		public HasClickHandlers getLabelVote();
78
		
74
 
79
		public void masquerVoteAscendant();
75
		public void masquerVoteAscendant();
80
 
76
 
81
		public void masquerVoteDescendant();
77
		public void masquerVoteDescendant();
82
				
78
 
83
		public void afficherVoteAscendant();
79
		public void afficherVoteAscendant();
84
		
80
 
Line 85... Line 81...
85
		public void afficherVoteDescendant();
81
		public void afficherVoteDescendant();
86
		
82
 
87
		public HasClickHandlers getLabelDate();
83
		public HasClickHandlers getLabelDate();
88
		
84
 
89
		public void masquerDateAscendant();
85
		public void masquerDateAscendant();
90
 
86
 
91
		public void masquerDateDescendant();
-
 
92
				
87
		public void masquerDateDescendant();
93
		public void afficherDateAscendant();
88
 
94
		
-
 
95
		public void afficherDateDescendant();
89
		public void afficherDateAscendant();
96
	}
90
 
97
 
-
 
98
	private Vue vue;
91
		public void afficherDateDescendant();
99
	private ImageService imageService;
92
	}
100
	
93
	private Vue vue;
101
	private final ProtocoleService protocoleService = MockDatasource.getInstance();
94
	private ImageService imageService;
102
	private List<Protocole> protocoles;
95
	private final ProtocoleService protocoleService = MockDatasource.getInstance();
103
 
96
	private List<Protocole> protocoles;
104
	private String protocoleParDefaut = Protocole.ESTHETISME;
97
	private String protocoleParDefaut = Protocole.ESTHETISME;
105
	private ModeTri triCourantVote = ModeTri.TRI_ASCENDANT;
98
	private ModeTri triCourantVote = ModeTri.TRI_ASCENDANT;
Line 121... Line 114...
121
		vue.masquerDateDescendant();
114
		vue.masquerDateDescendant();
122
		vue.masquerDateAscendant();
115
		vue.masquerDateAscendant();
123
	}
116
	}
Line 124... Line 117...
124
 
117
 
125
	public void gererEvenements() {
-
 
126
 
118
	public void gererEvenements() {
127
		vue.getListeProtocoles().addChangeHandler(new ChangeHandler() {
-
 
128
 
119
		vue.getListeProtocoles().addChangeHandler(new ChangeHandler() {
129
			@Override
120
			@Override
130
			public void onChange(ChangeEvent event) {
121
			public void onChange(ChangeEvent event) {
131
				surChangementProtocole();
122
				surChangementProtocole();
132
			}
123
			}
Line 133... Line -...
133
		});
-
 
134
		
124
		});
135
		
125
		
136
		vue.getLabelVote().addClickHandler(new ClickHandler() {
126
		ClickHandler surClicTriVote = new ClickHandler() {
137
			@Override
-
 
138
			public void onClick(ClickEvent event) {
-
 
139
				
-
 
140
				vue.masquerDateDescendant();
-
 
141
				vue.masquerDateAscendant();
-
 
142
				
-
 
143
				if (triCourantVote == ModeTri.TRI_ASCENDANT) {
-
 
144
					triCourantVote = ModeTri.TRI_DESCENDANT;
-
 
145
					vue.masquerVoteAscendant();
-
 
146
					vue.afficherVoteDescendant();
-
 
147
				} else {
-
 
148
					triCourantVote = ModeTri.TRI_ASCENDANT;
127
			@Override
149
					vue.masquerVoteDescendant();
-
 
150
					vue.afficherVoteAscendant();
-
 
151
				}
-
 
152
				
-
 
153
				InformationsRecherche informationsRechercheImages = CacheClient.getInstance().getInformationsRechercheImage();
-
 
154
				int IdProtocole = CacheClient.getInstance().getProtocoleCourant().getId();
-
 
155
				informationsRechercheImages.setTriParNbVotes(triCourantVote);
-
 
156
				informationsRechercheImages.setIdProtocoleSelectionne(IdProtocole + "");
-
 
157
				informationsRechercheImages.setTriParDate(ModeTri.PAS_DE_TRI);
-
 
158
				chargerEtAfficherImagesPageEnCours();
128
			public void onClick(ClickEvent event) {
159
				
129
				surClicTriVote();
Line -... Line 130...
-
 
130
			}
-
 
131
		};
-
 
132
		
Line 160... Line 133...
160
			}
133
		vue.getLabelVote().addClickHandler(surClicTriVote);
161
		});
134
		vue.getTriParNbVotesAscendant().addClickHandler(surClicTriVote);
162
		
135
		vue.getTriParNbVotesDescendant().addClickHandler(surClicTriVote);
163
		
-
 
164
		vue.getLabelDate().addClickHandler(new ClickHandler() {
-
 
165
			@Override
136
		
166
			public void onClick(ClickEvent event) {
-
 
167
				
-
 
168
				vue.masquerVoteDescendant();
-
 
169
				vue.masquerVoteAscendant();
-
 
170
				
-
 
171
				if (triCourantDate == ModeTri.TRI_ASCENDANT) {
-
 
172
					triCourantDate = ModeTri.TRI_DESCENDANT;
-
 
173
					vue.masquerDateAscendant();
-
 
174
					vue.afficherDateDescendant();
-
 
175
				} else {
-
 
176
					triCourantDate = ModeTri.TRI_ASCENDANT;
-
 
177
					vue.masquerDateDescendant();
-
 
178
					vue.afficherDateAscendant();
-
 
179
				}
-
 
180
				
-
 
181
				InformationsRecherche informationsRechercheImages = CacheClient.getInstance().getInformationsRechercheImage();
-
 
182
				informationsRechercheImages.setTriParDate(triCourantDate);
137
		ClickHandler surClicTriImage = new ClickHandler() {
183
				informationsRechercheImages.setTriParNbVotes(ModeTri.PAS_DE_TRI);
138
			@Override
-
 
139
			public void onClick(ClickEvent event) {
-
 
140
				surClicTriImage();
-
 
141
			}
-
 
142
		};
184
				chargerEtAfficherImagesPageEnCours();
143
		
185
				
144
		vue.getLabelDate().addClickHandler(surClicTriImage);
186
			}
145
		vue.getTriParDateAscendant().addClickHandler(surClicTriImage);
187
		});
146
		vue.getTriParDateDescendant().addClickHandler(surClicTriImage);
188
 
147
		
189
		BusEvenementiel.getInstance().addHandler(EvenementChangementProtocole.TYPE, new GestionnaireEvenementChangementProtocole() {
148
		BusEvenementiel.getInstance().addHandler(EvenementChangementProtocole.TYPE, new GestionnaireEvenementChangementProtocole() {
Line 196... Line 155...
196
				}
155
				}
197
			}
156
			}
198
		});
157
		});
199
	}
158
	}
Line -... Line 159...
-
 
159
 
-
 
160
	public void surClicTriVote() {
-
 
161
		vue.masquerDateDescendant();
-
 
162
		vue.masquerDateAscendant();
-
 
163
		if (triCourantVote == ModeTri.TRI_ASCENDANT) {
-
 
164
			triCourantVote = ModeTri.TRI_DESCENDANT;
-
 
165
			vue.masquerVoteAscendant();
-
 
166
			vue.afficherVoteDescendant();
-
 
167
		} else {
-
 
168
			triCourantVote = ModeTri.TRI_ASCENDANT;
-
 
169
			vue.masquerVoteDescendant();
-
 
170
			vue.afficherVoteAscendant();
-
 
171
		}
-
 
172
		InformationsRecherche informationsRechercheImages = CacheClient.getInstance().getInformationsRechercheImage();
-
 
173
		int IdProtocole = CacheClient.getInstance().getProtocoleCourant().getId();
-
 
174
		informationsRechercheImages.setTriParNbVotes(triCourantVote);
-
 
175
		informationsRechercheImages.setIdProtocoleSelectionne(IdProtocole + "");
-
 
176
		informationsRechercheImages.setTriParDate(ModeTri.PAS_DE_TRI);
-
 
177
		chargerEtAfficherImagesPageEnCours();
-
 
178
	}
-
 
179
 
-
 
180
	public void surClicTriImage() {
-
 
181
		vue.masquerVoteDescendant();
-
 
182
		vue.masquerVoteAscendant();
-
 
183
		if (triCourantDate == ModeTri.TRI_ASCENDANT) {
-
 
184
			triCourantDate = ModeTri.TRI_DESCENDANT;
-
 
185
			vue.masquerDateAscendant();
-
 
186
			vue.afficherDateDescendant();
-
 
187
		} else {
-
 
188
			triCourantDate = ModeTri.TRI_ASCENDANT;
-
 
189
			vue.masquerDateDescendant();
-
 
190
			vue.afficherDateAscendant();
-
 
191
		}
-
 
192
		InformationsRecherche informationsRechercheImages = CacheClient.getInstance().getInformationsRechercheImage();
-
 
193
		informationsRechercheImages.setTriParDate(triCourantDate);
-
 
194
		informationsRechercheImages.setTriParNbVotes(ModeTri.PAS_DE_TRI);
-
 
195
		chargerEtAfficherImagesPageEnCours();
-
 
196
	}
200
 
197
 
201
	public void surChangementProtocole() {
198
	public void surChangementProtocole() {
202
		Protocole protocoleCourant = null;
199
		Protocole protocoleCourant = null;
203
		for (Protocole protocole : protocoles) {
200
		for (Protocole protocole : protocoles) {
204
			if (protocole.getId() == vue.getIdProtocoleSelectionne()) {
201
			if (protocole.getId() == vue.getIdProtocoleSelectionne()) {
205
				protocoleCourant = protocole;
202
				protocoleCourant = protocole;
206
			}
203
			}
207
		}
-
 
208
 
204
		}
209
		CacheClient.getInstance().setProtocoleCourant(protocoleCourant);
205
		CacheClient.getInstance().setProtocoleCourant(protocoleCourant);
210
		EvenementChangementProtocole evenement = new EvenementChangementProtocole(protocoleCourant);
206
		EvenementChangementProtocole evenement = new EvenementChangementProtocole(protocoleCourant);
211
		BusEvenementiel.getInstance().fireEvent(evenement);
207
		BusEvenementiel.getInstance().fireEvent(evenement);
212
	}
208
	}
213
	
209
 
214
	private void chargerProtocoles() {
210
	private void chargerProtocoles() {
215
		protocoles = protocoleService.getProtocoles();
211
		protocoles = protocoleService.getProtocoles();
216
		for (Protocole protocole : protocoles) {
212
		for (Protocole protocole : protocoles) {
217
			vue.ajouterProtocole(protocole.getNom());
213
			vue.ajouterProtocole(protocole.getNom());
218
		}
214
		}
219
		vue.selectionnerProtocole(protocoles.indexOf(CacheClient.getInstance().getProtocoleCourant()));
215
		vue.selectionnerProtocole(protocoles.indexOf(CacheClient.getInstance().getProtocoleCourant()));
220
	}
-
 
221
	
-
 
Line -... Line 216...
-
 
216
	}
222
	public void rechercherImagesEtCreerWidgetPagination() {
217
 
223
 
218
	public void rechercherImagesEtCreerWidgetPagination() {
224
		// appel du service d'image pour avoir le nb total d'elements pour la
219
		// appel du service d'image pour avoir le nb total d'elements pour la
225
		// pagination
220
		// pagination
226
		ImagesParTaxonCallback callback = new ImagesParTaxonCallback() {
221
		ImagesParTaxonCallback callback = new ImagesParTaxonCallback() {
227
			@Override
222
			@Override
228
			public void surImagesRecues(ImageServiceResultat imagesRecues) {
223
			public void surImagesRecues(ImageServiceResultat imagesRecues) {
229
				creerWidgetPagination(imagesRecues.getNbTotalImagesPourLaRecherche());
224
				creerWidgetPagination(imagesRecues.getNbTotalImagesPourLaRecherche());
230
				afficherImages(imagesRecues);
225
				afficherImages(imagesRecues);
231
			}
-
 
232
		};
226
			}
233
 
227
		};
234
		final int debut = (CacheClient.getInstance().getPageCouranteRechercheImage() - 1) * CacheClient.getInstance().getPasPagination();
228
		final int debut = (CacheClient.getInstance().getPageCouranteRechercheImage() - 1) * CacheClient.getInstance().getPasPagination();
235
		final int fin = (CacheClient.getInstance().getPageCouranteRechercheImage()) * CacheClient.getInstance().getPasPagination();
229
		final int fin = (CacheClient.getInstance().getPageCouranteRechercheImage()) * CacheClient.getInstance().getPasPagination();
Line 236... Line 230...
236
		imageService.getImagesParTaxon(CacheClient.getInstance().getInformationsRechercheImage(), debut, fin, callback);
230
		imageService.getImagesParTaxon(CacheClient.getInstance().getInformationsRechercheImage(), debut, fin, callback);
237
	}
231
	}
238
 
232
 
239
	private void chargerEtAfficherImages(final int premier, final int dernier) {
-
 
240
		vue.startChargement();
233
	private void chargerEtAfficherImages(final int premier, final int dernier) {
241
		vue.nettoyer();
234
		vue.startChargement();
242
 
235
		vue.nettoyer();
243
		ImagesParTaxonCallback callback = new ImagesParTaxonCallback() {
236
		ImagesParTaxonCallback callback = new ImagesParTaxonCallback() {
244
			@Override
237
			@Override
245
			public void surImagesRecues(ImageServiceResultat imagesRecues) {
238
			public void surImagesRecues(ImageServiceResultat imagesRecues) {
246
				afficherImages(imagesRecues);
239
				afficherImages(imagesRecues);
247
			}
-
 
248
		};
240
			}
Line 249... Line 241...
249
		imageService.getImagesParTaxon(CacheClient.getInstance().getInformationsRechercheImage(), premier, dernier, callback);
241
		};
250
 
-
 
251
	}
242
		imageService.getImagesParTaxon(CacheClient.getInstance().getInformationsRechercheImage(), premier, dernier, callback);
252
 
-
 
253
	public void afficherImages(ImageServiceResultat imageServiceResult) {
243
	}
254
 
244
 
255
		List<Image> images = imageServiceResult.getImages();
-
 
256
 
-
 
257
		if (images == null || images.size() == 0) {
245
	public void afficherImages(ImageServiceResultat imageServiceResult) {
258
			vue.afficherElementsAucunResultatTrouve();
246
		List<Image> images = imageServiceResult.getImages();
259
		}
247
		if (images == null || images.size() == 0) {
260
 
248
			vue.afficherElementsAucunResultatTrouve();
261
		else {
249
		} else {
262
			vue.afficherElementsResultatsTrouve();
250
			vue.afficherElementsResultatsTrouve();
263
			for (Image image : images) {
251
			for (Image image : images) {
264
				ImagePresenteur imagePresenteur = new ImagePresenteur(image, CacheClient.getInstance().getProtocoleCourant(), new ImageVue());
252
				ImagePresenteur imagePresenteur = new ImagePresenteur(image, CacheClient.getInstance().getProtocoleCourant(), new ImageVue());
265
				imagePresenteur.go(vue.getImageTable());
253
				imagePresenteur.go(vue.getImageTable());
Line 266... Line 254...
266
			}
254
			}
267
		}
-
 
268
		vue.stopChargement();
255
		}
269
	}
256
		vue.stopChargement();
270
 
257
	}
271
	private void creerWidgetPagination(int nbImages) {
258
 
272
 
259
	private void creerWidgetPagination(int nbImages) {
273
		PaginationPresenteur imagesPaginationPresenteurHaut = creerPresenteurPagination(nbImages);
260
		PaginationPresenteur imagesPaginationPresenteurHaut = creerPresenteurPagination(nbImages);
274
		PaginationPresenteur imagesPaginationPresenteurBas = creerPresenteurPagination(nbImages);
261
		PaginationPresenteur imagesPaginationPresenteurBas = creerPresenteurPagination(nbImages);
Line 275... Line 262...
275
		imagesPaginationPresenteurHaut.setGroupePagination("pagination_images");
262
		imagesPaginationPresenteurHaut.setGroupePagination("pagination_images");
276
		imagesPaginationPresenteurBas.setGroupePagination("pagination_images");
263
		imagesPaginationPresenteurBas.setGroupePagination("pagination_images");
-
 
264
		imagesPaginationPresenteurHaut.go(vue.getPanneauPaginationHaut());
277
		imagesPaginationPresenteurHaut.go(vue.getPanneauPaginationHaut());
265
		imagesPaginationPresenteurBas.go(vue.getPanneauPagination());
278
		imagesPaginationPresenteurBas.go(vue.getPanneauPagination());
266
	}
279
	}
-
 
280
 
267
 
281
	public PaginationPresenteur creerPresenteurPagination(int nbImages) {
268
	public PaginationPresenteur creerPresenteurPagination(int nbImages) {
282
		PaginationPresenteur imagesPaginationPresenteur = new PaginationPresenteur(new PaginationVue(), nbImages, CacheClient.getInstance().getPasPagination(), CacheClient.getInstance().getPageCouranteRechercheImage()) {
269
		PaginationPresenteur imagesPaginationPresenteur = new PaginationPresenteur(new PaginationVue(), nbImages, CacheClient.getInstance().getPasPagination(), CacheClient.getInstance()
Line 283... Line 270...
283
			@Override
270
				.getPageCouranteRechercheImage()) {