477 |
benjamin |
1 |
package org.tela_botanica.del.client.composants.observations;
|
436 |
benjamin |
2 |
|
|
|
3 |
import java.util.List;
|
|
|
4 |
|
608 |
aurelien |
5 |
import org.tela_botanica.del.client.composants.fenetreoverlay.FenetreOverlayDefilantePresenteur;
|
|
|
6 |
import org.tela_botanica.del.client.composants.fenetreoverlay.FenetreOverlayDefilanteVue;
|
477 |
benjamin |
7 |
import org.tela_botanica.del.client.composants.images.DetailImagePresenteur;
|
|
|
8 |
import org.tela_botanica.del.client.composants.images.DetailImageVue;
|
436 |
benjamin |
9 |
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
|
|
|
10 |
import org.tela_botanica.del.client.modeles.Image;
|
|
|
11 |
import org.tela_botanica.del.client.modeles.Observation;
|
|
|
12 |
|
|
|
13 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
14 |
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
15 |
import com.google.gwt.event.dom.client.HasClickHandlers;
|
|
|
16 |
import com.google.gwt.user.client.ui.HasWidgets;
|
|
|
17 |
import com.google.gwt.user.client.ui.IsWidget;
|
|
|
18 |
|
|
|
19 |
public class ObservationImagesPresenteur extends Presenteur {
|
|
|
20 |
|
|
|
21 |
public abstract interface Vue extends IsWidget {
|
|
|
22 |
public HasClickHandlers getPhotoPrincipale();
|
|
|
23 |
public HasWidgets getPhotos();
|
|
|
24 |
public void chargerImagePrincipale(org.tela_botanica.del.client.modeles.Image image);
|
|
|
25 |
public void ajouterPhoto(Image image, ClickHandler gestionnaireClic);
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
private Vue vue;
|
|
|
29 |
|
|
|
30 |
private Observation observation;
|
|
|
31 |
|
|
|
32 |
private Image imagePrincipale;
|
437 |
aurelien |
33 |
|
|
|
34 |
private List<Image> listeImages;
|
436 |
benjamin |
35 |
|
|
|
36 |
public ObservationImagesPresenteur(Vue vue, Observation observation) {
|
|
|
37 |
this.observation = observation;
|
|
|
38 |
this.vue = vue;
|
|
|
39 |
}
|
|
|
40 |
|
|
|
41 |
public void chargerImagesObservation() {
|
|
|
42 |
|
437 |
aurelien |
43 |
listeImages = observation.getImages();
|
448 |
aurelien |
44 |
|
|
|
45 |
if (listeImages.size() > 0){
|
953 |
gduche |
46 |
imagePrincipale = listeImages.get(0);
|
444 |
aurelien |
47 |
vue.chargerImagePrincipale(imagePrincipale);
|
448 |
aurelien |
48 |
vue.getPhotoPrincipale().addClickHandler(creerGestionnaireClic(0, imagePrincipale));
|
444 |
aurelien |
49 |
}
|
436 |
benjamin |
50 |
|
437 |
aurelien |
51 |
int nbImage = 0;
|
953 |
gduche |
52 |
for (Image imageCourante : listeImages) {
|
437 |
aurelien |
53 |
if(!imageCourante.equals(imagePrincipale)) {
|
|
|
54 |
int nbImageEncours = nbImage;
|
|
|
55 |
vue.ajouterPhoto(imageCourante, creerGestionnaireClic(nbImageEncours, imageCourante));
|
436 |
benjamin |
56 |
}
|
437 |
aurelien |
57 |
nbImage++;
|
436 |
benjamin |
58 |
}
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
public void go(HasWidgets composite) {
|
|
|
62 |
composite.add(vue.asWidget());
|
|
|
63 |
chargerImagesObservation();
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
protected void gererEvenements() {
|
448 |
aurelien |
67 |
|
437 |
aurelien |
68 |
}
|
|
|
69 |
|
|
|
70 |
protected ClickHandler creerGestionnaireClic(final int indexImage, final Image imageCourante) {
|
|
|
71 |
ClickHandler gestionnaireClic = new ClickHandler() {
|
436 |
benjamin |
72 |
public void onClick(ClickEvent event) {
|
437 |
aurelien |
73 |
FenetreOverlayDefilantePresenteur presenteurGalerie = new FenetreOverlayDefilantePresenteur(indexImage, new FenetreOverlayDefilanteVue()) {
|
|
|
74 |
|
|
|
75 |
@Override
|
|
|
76 |
public void surClicBoutonSuivant() {
|
|
|
77 |
int index = getIndexElementAffiche() + 1;
|
|
|
78 |
if(index >= listeImages.size()) {
|
|
|
79 |
index = 0;
|
|
|
80 |
}
|
|
|
81 |
setContenuFenetreModale(index, new DetailImagePresenteur(listeImages.get(index), new DetailImageVue()));
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
@Override
|
|
|
85 |
public void surClicBoutonPrecedent() {
|
|
|
86 |
int index = getIndexElementAffiche() - 1;
|
|
|
87 |
if(index < 0) {
|
|
|
88 |
index = listeImages.size() - 1;
|
|
|
89 |
}
|
|
|
90 |
setContenuFenetreModale(index, new DetailImagePresenteur(listeImages.get(index), new DetailImageVue()));
|
|
|
91 |
}
|
|
|
92 |
};
|
|
|
93 |
presenteurGalerie.ouvrirFenetreModaleDefilante(indexImage, new DetailImagePresenteur(imageCourante, new DetailImageVue()));
|
440 |
aurelien |
94 |
presenteurGalerie.afficherBoutonsSuivantsPrecedents((listeImages.size() > 1));
|
436 |
benjamin |
95 |
}
|
437 |
aurelien |
96 |
};
|
|
|
97 |
return gestionnaireClic;
|
436 |
benjamin |
98 |
}
|
|
|
99 |
}
|