178 |
benjamin |
1 |
package org.tela_botanica.del.client.vues.rechercheimages.resultats;
|
|
|
2 |
|
|
|
3 |
import java.util.List;
|
|
|
4 |
|
|
|
5 |
import org.tela_botanica.del.client.cache.CacheClient;
|
359 |
benjamin |
6 |
import org.tela_botanica.del.client.composants.pagination.PaginationPresenteur;
|
391 |
aurelien |
7 |
import org.tela_botanica.del.client.composants.pagination.PaginationVue;
|
344 |
aurelien |
8 |
import org.tela_botanica.del.client.modeles.Image;
|
|
|
9 |
import org.tela_botanica.del.client.modeles.ImageServiceResultat;
|
459 |
benjamin |
10 |
import org.tela_botanica.del.client.modeles.InformationsRecherche;
|
|
|
11 |
import org.tela_botanica.del.client.modeles.ModeTri;
|
590 |
gduche |
12 |
import org.tela_botanica.del.client.modeles.Protocole;
|
509 |
aurelien |
13 |
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
|
|
|
14 |
import org.tela_botanica.del.client.navigation.evenement.changementprotocole.EvenementChangementProtocole;
|
|
|
15 |
import org.tela_botanica.del.client.navigation.evenement.changementprotocole.GestionnaireEvenementChangementProtocole;
|
312 |
gduche |
16 |
import org.tela_botanica.del.client.services.rest.ImageService;
|
590 |
gduche |
17 |
import org.tela_botanica.del.client.services.rest.ProtocoleService;
|
344 |
aurelien |
18 |
import org.tela_botanica.del.client.services.rest.async.ImagesParTaxonCallback;
|
590 |
gduche |
19 |
import org.tela_botanica.del.client.utils.MockDatasource;
|
178 |
benjamin |
20 |
import org.tela_botanica.del.client.vues.rechercheimages.resultats.images.ImagePresenteur;
|
311 |
gduche |
21 |
import org.tela_botanica.del.client.vues.rechercheimages.resultats.images.ImageVue;
|
359 |
benjamin |
22 |
|
590 |
gduche |
23 |
import com.google.gwt.event.dom.client.ChangeEvent;
|
|
|
24 |
import com.google.gwt.event.dom.client.ChangeHandler;
|
459 |
benjamin |
25 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
26 |
import com.google.gwt.event.dom.client.ClickHandler;
|
590 |
gduche |
27 |
import com.google.gwt.event.dom.client.HasChangeHandlers;
|
459 |
benjamin |
28 |
import com.google.gwt.event.dom.client.HasClickHandlers;
|
564 |
benjamin |
29 |
import com.google.gwt.user.client.ui.HTMLPanel;
|
178 |
benjamin |
30 |
import com.google.gwt.user.client.ui.HasWidgets;
|
379 |
gduche |
31 |
import com.google.gwt.user.client.ui.IsWidget;
|
590 |
gduche |
32 |
import com.google.gwt.user.client.ui.ListBox;
|
178 |
benjamin |
33 |
|
|
|
34 |
public class ResultatRechercheImagePresenteur {
|
|
|
35 |
|
534 |
benjamin |
36 |
public interface Vue extends IsWidget {
|
379 |
gduche |
37 |
public void startChargement();
|
436 |
benjamin |
38 |
|
379 |
gduche |
39 |
public void nettoyer();
|
436 |
benjamin |
40 |
|
379 |
gduche |
41 |
public void creerPanneauxObservations(int size);
|
436 |
benjamin |
42 |
|
379 |
gduche |
43 |
public void stopChargement();
|
436 |
benjamin |
44 |
|
534 |
benjamin |
45 |
public List<HasWidgets> getPanneauxImages();
|
436 |
benjamin |
46 |
|
379 |
gduche |
47 |
public HasWidgets getPanneauPagination();
|
436 |
benjamin |
48 |
|
379 |
gduche |
49 |
public HasWidgets getPanneauPaginationHaut();
|
459 |
benjamin |
50 |
|
|
|
51 |
public HasClickHandlers getTriParNbVotesAscendant();
|
|
|
52 |
|
|
|
53 |
public HasClickHandlers getTriParNbVotesDescendant();
|
|
|
54 |
|
|
|
55 |
public HasClickHandlers getTriParDateAscendant();
|
|
|
56 |
|
|
|
57 |
public HasClickHandlers getTriParDateDescendant();
|
564 |
benjamin |
58 |
|
|
|
59 |
public void afficherElementsAucunResultatTrouve();
|
|
|
60 |
|
|
|
61 |
public void afficherElementsResultatsTrouve();
|
|
|
62 |
|
|
|
63 |
public HTMLPanel getImageTable();
|
590 |
gduche |
64 |
|
|
|
65 |
public String getNomProtocolSelectionne();
|
|
|
66 |
|
|
|
67 |
public int getIdProtocoleSelectionne();
|
|
|
68 |
|
|
|
69 |
public void setListeProtocoles(ListBox listeProtocoles);
|
|
|
70 |
|
|
|
71 |
public HasChangeHandlers getListeProtocoles();
|
|
|
72 |
|
|
|
73 |
public void ajouterProtocole(String protocole);
|
|
|
74 |
|
|
|
75 |
public void selectionnerProtocole(int index);
|
|
|
76 |
|
591 |
gduche |
77 |
public HasClickHandlers getLabelVote();
|
|
|
78 |
|
|
|
79 |
public void masquerVoteAscendant();
|
|
|
80 |
|
|
|
81 |
public void masquerVoteDescendant();
|
|
|
82 |
|
|
|
83 |
public void afficherVoteAscendant();
|
|
|
84 |
|
|
|
85 |
public void afficherVoteDescendant();
|
|
|
86 |
|
|
|
87 |
public HasClickHandlers getLabelDate();
|
|
|
88 |
|
|
|
89 |
public void masquerDateAscendant();
|
|
|
90 |
|
|
|
91 |
public void masquerDateDescendant();
|
|
|
92 |
|
|
|
93 |
public void afficherDateAscendant();
|
|
|
94 |
|
|
|
95 |
public void afficherDateDescendant();
|
379 |
gduche |
96 |
}
|
436 |
benjamin |
97 |
|
379 |
gduche |
98 |
private Vue vue;
|
344 |
aurelien |
99 |
private ImageService imageService;
|
590 |
gduche |
100 |
|
|
|
101 |
private final ProtocoleService protocoleService = MockDatasource.getInstance();
|
|
|
102 |
private List<Protocole> protocoles;
|
436 |
benjamin |
103 |
|
590 |
gduche |
104 |
private String protocoleParDefaut = Protocole.ESTHETISME;
|
591 |
gduche |
105 |
private ModeTri triCourantVote = ModeTri.TRI_ASCENDANT;
|
|
|
106 |
private ModeTri triCourantDate = ModeTri.TRI_ASCENDANT;
|
590 |
gduche |
107 |
|
379 |
gduche |
108 |
public ResultatRechercheImagePresenteur(ImageService imageService, Vue vue) {
|
|
|
109 |
this.vue = vue;
|
344 |
aurelien |
110 |
this.imageService = imageService;
|
178 |
benjamin |
111 |
}
|
|
|
112 |
|
|
|
113 |
public void go(HasWidgets composite) {
|
379 |
gduche |
114 |
composite.add(vue.asWidget());
|
361 |
benjamin |
115 |
vue.startChargement();
|
445 |
benjamin |
116 |
rechercherImagesEtCreerWidgetPagination();
|
459 |
benjamin |
117 |
gererEvenements();
|
590 |
gduche |
118 |
chargerProtocoles();
|
591 |
gduche |
119 |
vue.masquerVoteDescendant();
|
|
|
120 |
vue.masquerVoteAscendant();
|
|
|
121 |
vue.masquerDateDescendant();
|
|
|
122 |
vue.masquerDateAscendant();
|
445 |
benjamin |
123 |
}
|
|
|
124 |
|
459 |
benjamin |
125 |
public void gererEvenements() {
|
|
|
126 |
|
590 |
gduche |
127 |
vue.getListeProtocoles().addChangeHandler(new ChangeHandler() {
|
|
|
128 |
|
|
|
129 |
@Override
|
|
|
130 |
public void onChange(ChangeEvent event) {
|
|
|
131 |
surChangementProtocole();
|
|
|
132 |
}
|
|
|
133 |
});
|
|
|
134 |
|
591 |
gduche |
135 |
|
|
|
136 |
vue.getLabelVote().addClickHandler(new ClickHandler() {
|
459 |
benjamin |
137 |
@Override
|
591 |
gduche |
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;
|
|
|
149 |
vue.masquerVoteDescendant();
|
|
|
150 |
vue.afficherVoteAscendant();
|
|
|
151 |
}
|
|
|
152 |
|
459 |
benjamin |
153 |
InformationsRecherche informationsRechercheImages = CacheClient.getInstance().getInformationsRechercheImage();
|
509 |
aurelien |
154 |
int IdProtocole = CacheClient.getInstance().getProtocoleCourant().getId();
|
591 |
gduche |
155 |
informationsRechercheImages.setTriParNbVotes(triCourantVote);
|
534 |
benjamin |
156 |
informationsRechercheImages.setIdProtocoleSelectionne(IdProtocole + "");
|
491 |
benjamin |
157 |
informationsRechercheImages.setTriParDate(ModeTri.PAS_DE_TRI);
|
459 |
benjamin |
158 |
chargerEtAfficherImagesPageEnCours();
|
591 |
gduche |
159 |
|
459 |
benjamin |
160 |
}
|
|
|
161 |
});
|
591 |
gduche |
162 |
|
|
|
163 |
|
|
|
164 |
vue.getLabelDate().addClickHandler(new ClickHandler() {
|
459 |
benjamin |
165 |
@Override
|
591 |
gduche |
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 |
|
459 |
benjamin |
181 |
InformationsRecherche informationsRechercheImages = CacheClient.getInstance().getInformationsRechercheImage();
|
591 |
gduche |
182 |
informationsRechercheImages.setTriParDate(triCourantDate);
|
491 |
benjamin |
183 |
informationsRechercheImages.setTriParNbVotes(ModeTri.PAS_DE_TRI);
|
459 |
benjamin |
184 |
chargerEtAfficherImagesPageEnCours();
|
591 |
gduche |
185 |
|
459 |
benjamin |
186 |
}
|
|
|
187 |
});
|
|
|
188 |
|
509 |
aurelien |
189 |
BusEvenementiel.getInstance().addHandler(EvenementChangementProtocole.TYPE, new GestionnaireEvenementChangementProtocole() {
|
|
|
190 |
@Override
|
|
|
191 |
public void onChangementProtocole(EvenementChangementProtocole event) {
|
|
|
192 |
InformationsRecherche informationsRechercheImages = CacheClient.getInstance().getInformationsRechercheImage();
|
534 |
benjamin |
193 |
if (informationsRechercheImages.getTriParNbVotes() != ModeTri.PAS_DE_TRI) {
|
|
|
194 |
informationsRechercheImages.setIdProtocoleSelectionne(event.getProtocole().getId() + "");
|
509 |
aurelien |
195 |
chargerEtAfficherImagesPageEnCours();
|
|
|
196 |
}
|
|
|
197 |
}
|
|
|
198 |
});
|
459 |
benjamin |
199 |
}
|
|
|
200 |
|
590 |
gduche |
201 |
public void surChangementProtocole() {
|
|
|
202 |
Protocole protocoleCourant = null;
|
|
|
203 |
for (Protocole protocole : protocoles) {
|
|
|
204 |
if (protocole.getId() == vue.getIdProtocoleSelectionne()) {
|
|
|
205 |
protocoleCourant = protocole;
|
|
|
206 |
}
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
CacheClient.getInstance().setProtocoleCourant(protocoleCourant);
|
|
|
210 |
EvenementChangementProtocole evenement = new EvenementChangementProtocole(protocoleCourant);
|
|
|
211 |
BusEvenementiel.getInstance().fireEvent(evenement);
|
|
|
212 |
}
|
|
|
213 |
|
|
|
214 |
private void chargerProtocoles() {
|
|
|
215 |
protocoles = protocoleService.getProtocoles();
|
|
|
216 |
for (Protocole protocole : protocoles) {
|
|
|
217 |
vue.ajouterProtocole(protocole.getNom());
|
|
|
218 |
}
|
|
|
219 |
vue.selectionnerProtocole(protocoles.indexOf(CacheClient.getInstance().getProtocoleCourant()));
|
|
|
220 |
}
|
|
|
221 |
|
445 |
benjamin |
222 |
public void rechercherImagesEtCreerWidgetPagination() {
|
455 |
benjamin |
223 |
|
359 |
benjamin |
224 |
// appel du service d'image pour avoir le nb total d'elements pour la
|
|
|
225 |
// pagination
|
|
|
226 |
ImagesParTaxonCallback callback = new ImagesParTaxonCallback() {
|
|
|
227 |
@Override
|
|
|
228 |
public void surImagesRecues(ImageServiceResultat imagesRecues) {
|
|
|
229 |
creerWidgetPagination(imagesRecues.getNbTotalImagesPourLaRecherche());
|
455 |
benjamin |
230 |
afficherImages(imagesRecues);
|
359 |
benjamin |
231 |
}
|
|
|
232 |
};
|
455 |
benjamin |
233 |
|
|
|
234 |
final int debut = (CacheClient.getInstance().getPageCouranteRechercheImage() - 1) * CacheClient.getInstance().getPasPagination();
|
|
|
235 |
final int fin = (CacheClient.getInstance().getPageCouranteRechercheImage()) * CacheClient.getInstance().getPasPagination();
|
|
|
236 |
imageService.getImagesParTaxon(CacheClient.getInstance().getInformationsRechercheImage(), debut, fin, callback);
|
178 |
benjamin |
237 |
}
|
|
|
238 |
|
360 |
benjamin |
239 |
private void chargerEtAfficherImages(final int premier, final int dernier) {
|
390 |
aurelien |
240 |
vue.startChargement();
|
361 |
benjamin |
241 |
vue.nettoyer();
|
359 |
benjamin |
242 |
|
344 |
aurelien |
243 |
ImagesParTaxonCallback callback = new ImagesParTaxonCallback() {
|
|
|
244 |
@Override
|
|
|
245 |
public void surImagesRecues(ImageServiceResultat imagesRecues) {
|
455 |
benjamin |
246 |
afficherImages(imagesRecues);
|
344 |
aurelien |
247 |
}
|
|
|
248 |
};
|
359 |
benjamin |
249 |
imageService.getImagesParTaxon(CacheClient.getInstance().getInformationsRechercheImage(), premier, dernier, callback);
|
|
|
250 |
|
178 |
benjamin |
251 |
}
|
|
|
252 |
|
534 |
benjamin |
253 |
public void afficherImages(ImageServiceResultat imageServiceResult) {
|
360 |
benjamin |
254 |
|
361 |
benjamin |
255 |
List<Image> images = imageServiceResult.getImages();
|
|
|
256 |
|
564 |
benjamin |
257 |
if (images == null || images.size() == 0) {
|
|
|
258 |
vue.afficherElementsAucunResultatTrouve();
|
|
|
259 |
}
|
359 |
benjamin |
260 |
|
564 |
benjamin |
261 |
else {
|
|
|
262 |
vue.afficherElementsResultatsTrouve();
|
|
|
263 |
for (Image image : images) {
|
|
|
264 |
ImagePresenteur imagePresenteur = new ImagePresenteur(image, CacheClient.getInstance().getProtocoleCourant(), new ImageVue());
|
|
|
265 |
imagePresenteur.go(vue.getImageTable());
|
|
|
266 |
}
|
178 |
benjamin |
267 |
}
|
359 |
benjamin |
268 |
vue.stopChargement();
|
178 |
benjamin |
269 |
}
|
|
|
270 |
|
359 |
benjamin |
271 |
private void creerWidgetPagination(int nbImages) {
|
178 |
benjamin |
272 |
|
445 |
benjamin |
273 |
PaginationPresenteur imagesPaginationPresenteurHaut = creerPresenteurPagination(nbImages);
|
|
|
274 |
PaginationPresenteur imagesPaginationPresenteurBas = creerPresenteurPagination(nbImages);
|
446 |
aurelien |
275 |
imagesPaginationPresenteurHaut.setGroupePagination("pagination_images");
|
|
|
276 |
imagesPaginationPresenteurBas.setGroupePagination("pagination_images");
|
445 |
benjamin |
277 |
imagesPaginationPresenteurHaut.go(vue.getPanneauPaginationHaut());
|
|
|
278 |
imagesPaginationPresenteurBas.go(vue.getPanneauPagination());
|
|
|
279 |
}
|
359 |
benjamin |
280 |
|
445 |
benjamin |
281 |
public PaginationPresenteur creerPresenteurPagination(int nbImages) {
|
|
|
282 |
PaginationPresenteur imagesPaginationPresenteur = new PaginationPresenteur(new PaginationVue(), nbImages, CacheClient.getInstance().getPasPagination(), CacheClient.getInstance().getPageCouranteRechercheImage()) {
|
263 |
gduche |
283 |
@Override
|
445 |
benjamin |
284 |
public void chargerElements(int debut, int fin) {
|
436 |
benjamin |
285 |
|
445 |
benjamin |
286 |
chargerEtAfficherImages(debut, fin);
|
365 |
gduche |
287 |
CacheClient.getInstance().setPageCouranteRechercheImages(getPageCourante());
|
|
|
288 |
}
|
|
|
289 |
|
|
|
290 |
@Override
|
|
|
291 |
public void actualiserPasCache(int pas) {
|
|
|
292 |
CacheClient.getInstance().setPasPagination(pas);
|
|
|
293 |
}
|
|
|
294 |
};
|
445 |
benjamin |
295 |
return imagesPaginationPresenteur;
|
178 |
benjamin |
296 |
}
|
459 |
benjamin |
297 |
|
|
|
298 |
public void chargerEtAfficherImagesPageEnCours() {
|
|
|
299 |
final int debut = (CacheClient.getInstance().getPageCouranteRechercheImage() - 1) * CacheClient.getInstance().getPasPagination();
|
|
|
300 |
final int fin = (CacheClient.getInstance().getPageCouranteRechercheImage()) * CacheClient.getInstance().getPasPagination();
|
|
|
301 |
chargerEtAfficherImages(debut, fin);
|
|
|
302 |
}
|
534 |
benjamin |
303 |
|
|
|
304 |
public Vue getVue() {
|
|
|
305 |
return vue;
|
|
|
306 |
}
|
178 |
benjamin |
307 |
}
|