477 |
benjamin |
1 |
package org.tela_botanica.del.client.composants.observations;
|
436 |
benjamin |
2 |
|
|
|
3 |
import java.util.List;
|
|
|
4 |
|
1006 |
benjamin |
5 |
import org.tela_botanica.del.client.cache.CacheClient;
|
608 |
aurelien |
6 |
import org.tela_botanica.del.client.composants.fenetreoverlay.FenetreOverlayDefilantePresenteur;
|
|
|
7 |
import org.tela_botanica.del.client.composants.fenetreoverlay.FenetreOverlayDefilanteVue;
|
477 |
benjamin |
8 |
import org.tela_botanica.del.client.composants.images.DetailImagePresenteur;
|
|
|
9 |
import org.tela_botanica.del.client.composants.images.DetailImageVue;
|
436 |
benjamin |
10 |
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
|
1042 |
benjamin |
11 |
import org.tela_botanica.del.client.gestionhistorique.ConstantesNavigation;
|
436 |
benjamin |
12 |
import org.tela_botanica.del.client.modeles.Image;
|
|
|
13 |
import org.tela_botanica.del.client.modeles.Observation;
|
1006 |
benjamin |
14 |
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
|
1045 |
benjamin |
15 |
import org.tela_botanica.del.client.navigation.evenement.changementimagevalidation.EvenementChangementImageValidation;
|
|
|
16 |
import org.tela_botanica.del.client.navigation.evenement.changementimagevalidation.GestionnaireEvenementChangementImageValidation;
|
1041 |
benjamin |
17 |
import org.tela_botanica.del.client.navigation.evenement.validationobservation.EvenementValidation;
|
1196 |
gduche |
18 |
import org.tela_botanica.del.client.navigation.evenement.validationobservationpictoflora.EvenementValidationPictoflora;
|
436 |
benjamin |
19 |
|
|
|
20 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
21 |
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
22 |
import com.google.gwt.event.dom.client.HasClickHandlers;
|
1042 |
benjamin |
23 |
import com.google.gwt.user.client.History;
|
1113 |
gduche |
24 |
import com.google.gwt.user.client.Window;
|
1041 |
benjamin |
25 |
import com.google.gwt.user.client.ui.HTML;
|
436 |
benjamin |
26 |
import com.google.gwt.user.client.ui.HasWidgets;
|
|
|
27 |
import com.google.gwt.user.client.ui.IsWidget;
|
|
|
28 |
|
|
|
29 |
public class ObservationImagesPresenteur extends Presenteur {
|
|
|
30 |
|
|
|
31 |
public abstract interface Vue extends IsWidget {
|
|
|
32 |
public HasClickHandlers getPhotoPrincipale();
|
1006 |
benjamin |
33 |
|
436 |
benjamin |
34 |
public HasWidgets getPhotos();
|
1006 |
benjamin |
35 |
|
436 |
benjamin |
36 |
public void chargerImagePrincipale(org.tela_botanica.del.client.modeles.Image image);
|
1006 |
benjamin |
37 |
|
436 |
benjamin |
38 |
public void ajouterPhoto(Image image, ClickHandler gestionnaireClic);
|
1046 |
benjamin |
39 |
|
1041 |
benjamin |
40 |
public void afficherLienPlateformeValidation();
|
1046 |
benjamin |
41 |
|
1041 |
benjamin |
42 |
public HTML getLienPlateforme();
|
436 |
benjamin |
43 |
}
|
|
|
44 |
|
|
|
45 |
private Vue vue;
|
|
|
46 |
|
|
|
47 |
private Observation observation;
|
|
|
48 |
|
|
|
49 |
private Image imagePrincipale;
|
1006 |
benjamin |
50 |
|
437 |
aurelien |
51 |
private List<Image> listeImages;
|
436 |
benjamin |
52 |
|
1113 |
gduche |
53 |
private String page;
|
|
|
54 |
|
|
|
55 |
public ObservationImagesPresenteur(Vue vue, Observation observation, Image imagePrincipale, String page) {
|
436 |
benjamin |
56 |
this.observation = observation;
|
|
|
57 |
this.vue = vue;
|
1039 |
benjamin |
58 |
this.imagePrincipale = imagePrincipale;
|
1113 |
gduche |
59 |
this.page = page;
|
436 |
benjamin |
60 |
}
|
|
|
61 |
|
|
|
62 |
public void chargerImagesObservation() {
|
|
|
63 |
|
437 |
aurelien |
64 |
listeImages = observation.getImages();
|
1039 |
benjamin |
65 |
if (imagePrincipale != null) {
|
444 |
aurelien |
66 |
vue.chargerImagePrincipale(imagePrincipale);
|
1006 |
benjamin |
67 |
vue.getPhotoPrincipale().addClickHandler(creerGestionnaireClicGalerieImages(0, imagePrincipale));
|
444 |
aurelien |
68 |
}
|
436 |
benjamin |
69 |
|
437 |
aurelien |
70 |
int nbImage = 0;
|
953 |
gduche |
71 |
for (Image imageCourante : listeImages) {
|
1039 |
benjamin |
72 |
vue.ajouterPhoto(imageCourante, creerGestionnaireClicChangementImagePrincipale(imageCourante));
|
437 |
aurelien |
73 |
nbImage++;
|
1046 |
benjamin |
74 |
|
1113 |
gduche |
75 |
if (page.equals(ConstantesNavigation.PAGE_RECHERCHE_OBSERVATIONS) && nbImage >= 5) {
|
1041 |
benjamin |
76 |
vue.afficherLienPlateformeValidation();
|
|
|
77 |
break;
|
|
|
78 |
}
|
436 |
benjamin |
79 |
}
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
public void go(HasWidgets composite) {
|
|
|
83 |
composite.add(vue.asWidget());
|
|
|
84 |
chargerImagesObservation();
|
1041 |
benjamin |
85 |
gererEvenements();
|
436 |
benjamin |
86 |
}
|
|
|
87 |
|
|
|
88 |
protected void gererEvenements() {
|
1196 |
gduche |
89 |
if (this.page.equals(ConstantesNavigation.PAGE_VALIDATION)) {
|
|
|
90 |
vue.getLienPlateforme().addClickHandler(new ClickHandler() {
|
|
|
91 |
|
|
|
92 |
@Override
|
|
|
93 |
public void onClick(ClickEvent arg0) {
|
|
|
94 |
BusEvenementiel.getInstance().fireEvent(new EvenementValidation(observation));
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
});
|
|
|
98 |
} else {
|
|
|
99 |
vue.getLienPlateforme().addClickHandler(new ClickHandler() {
|
|
|
100 |
|
|
|
101 |
@Override
|
|
|
102 |
public void onClick(ClickEvent arg0) {
|
|
|
103 |
BusEvenementiel.getInstance().fireEvent(new EvenementValidationPictoflora(observation));
|
|
|
104 |
}
|
|
|
105 |
|
|
|
106 |
});
|
|
|
107 |
}
|
1046 |
benjamin |
108 |
|
1045 |
benjamin |
109 |
BusEvenementiel.getInstance().addHandler(EvenementChangementImageValidation.TYPE, new GestionnaireEvenementChangementImageValidation() {
|
1046 |
benjamin |
110 |
|
1045 |
benjamin |
111 |
@Override
|
|
|
112 |
public void onChangementImage(EvenementChangementImageValidation event) {
|
1046 |
benjamin |
113 |
if (CacheClient.getInstance().getImageCourante().getObservation().getId().equals(observation.getId())) {
|
|
|
114 |
vue.chargerImagePrincipale(CacheClient.getInstance().getImageCourante());
|
|
|
115 |
}
|
1045 |
benjamin |
116 |
}
|
|
|
117 |
});
|
1046 |
benjamin |
118 |
|
437 |
aurelien |
119 |
}
|
1006 |
benjamin |
120 |
|
|
|
121 |
protected ClickHandler creerGestionnaireClicGalerieImages(final int indexImage, final Image imageCourante) {
|
437 |
aurelien |
122 |
ClickHandler gestionnaireClic = new ClickHandler() {
|
436 |
benjamin |
123 |
public void onClick(ClickEvent event) {
|
437 |
aurelien |
124 |
FenetreOverlayDefilantePresenteur presenteurGalerie = new FenetreOverlayDefilantePresenteur(indexImage, new FenetreOverlayDefilanteVue()) {
|
1006 |
benjamin |
125 |
|
437 |
aurelien |
126 |
@Override
|
|
|
127 |
public void surClicBoutonSuivant() {
|
|
|
128 |
int index = getIndexElementAffiche() + 1;
|
1006 |
benjamin |
129 |
if (index >= listeImages.size()) {
|
437 |
aurelien |
130 |
index = 0;
|
|
|
131 |
}
|
|
|
132 |
setContenuFenetreModale(index, new DetailImagePresenteur(listeImages.get(index), new DetailImageVue()));
|
|
|
133 |
}
|
1006 |
benjamin |
134 |
|
437 |
aurelien |
135 |
@Override
|
|
|
136 |
public void surClicBoutonPrecedent() {
|
|
|
137 |
int index = getIndexElementAffiche() - 1;
|
1006 |
benjamin |
138 |
if (index < 0) {
|
437 |
aurelien |
139 |
index = listeImages.size() - 1;
|
|
|
140 |
}
|
|
|
141 |
setContenuFenetreModale(index, new DetailImagePresenteur(listeImages.get(index), new DetailImageVue()));
|
|
|
142 |
}
|
|
|
143 |
};
|
|
|
144 |
presenteurGalerie.ouvrirFenetreModaleDefilante(indexImage, new DetailImagePresenteur(imageCourante, new DetailImageVue()));
|
440 |
aurelien |
145 |
presenteurGalerie.afficherBoutonsSuivantsPrecedents((listeImages.size() > 1));
|
436 |
benjamin |
146 |
}
|
437 |
aurelien |
147 |
};
|
|
|
148 |
return gestionnaireClic;
|
436 |
benjamin |
149 |
}
|
1006 |
benjamin |
150 |
|
|
|
151 |
protected ClickHandler creerGestionnaireClicChangementImagePrincipale(final Image imageCourante) {
|
|
|
152 |
ClickHandler gestionnaireClic = new ClickHandler() {
|
|
|
153 |
public void onClick(ClickEvent event) {
|
|
|
154 |
CacheClient.getInstance().setImageCourante(imageCourante);
|
1045 |
benjamin |
155 |
BusEvenementiel.getInstance().fireEvent(new EvenementChangementImageValidation());
|
1006 |
benjamin |
156 |
}
|
|
|
157 |
};
|
|
|
158 |
return gestionnaireClic;
|
|
|
159 |
}
|
1046 |
benjamin |
160 |
|
436 |
benjamin |
161 |
}
|