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;
|
1553 |
jpm |
11 |
import org.tela_botanica.del.client.config.Config;
|
1042 |
benjamin |
12 |
import org.tela_botanica.del.client.gestionhistorique.ConstantesNavigation;
|
436 |
benjamin |
13 |
import org.tela_botanica.del.client.modeles.Image;
|
|
|
14 |
import org.tela_botanica.del.client.modeles.Observation;
|
1006 |
benjamin |
15 |
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
|
1045 |
benjamin |
16 |
import org.tela_botanica.del.client.navigation.evenement.changementimagevalidation.EvenementChangementImageValidation;
|
|
|
17 |
import org.tela_botanica.del.client.navigation.evenement.changementimagevalidation.GestionnaireEvenementChangementImageValidation;
|
1041 |
benjamin |
18 |
import org.tela_botanica.del.client.navigation.evenement.validationobservation.EvenementValidation;
|
1196 |
gduche |
19 |
import org.tela_botanica.del.client.navigation.evenement.validationobservationpictoflora.EvenementValidationPictoflora;
|
436 |
benjamin |
20 |
|
|
|
21 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
22 |
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
23 |
import com.google.gwt.event.dom.client.HasClickHandlers;
|
1042 |
benjamin |
24 |
import com.google.gwt.user.client.History;
|
1113 |
gduche |
25 |
import com.google.gwt.user.client.Window;
|
1041 |
benjamin |
26 |
import com.google.gwt.user.client.ui.HTML;
|
436 |
benjamin |
27 |
import com.google.gwt.user.client.ui.HasWidgets;
|
|
|
28 |
import com.google.gwt.user.client.ui.IsWidget;
|
|
|
29 |
|
|
|
30 |
public class ObservationImagesPresenteur extends Presenteur {
|
|
|
31 |
|
|
|
32 |
public abstract interface Vue extends IsWidget {
|
|
|
33 |
public HasClickHandlers getPhotoPrincipale();
|
1006 |
benjamin |
34 |
|
436 |
benjamin |
35 |
public HasWidgets getPhotos();
|
1006 |
benjamin |
36 |
|
436 |
benjamin |
37 |
public void chargerImagePrincipale(org.tela_botanica.del.client.modeles.Image image);
|
1006 |
benjamin |
38 |
|
436 |
benjamin |
39 |
public void ajouterPhoto(Image image, ClickHandler gestionnaireClic);
|
1046 |
benjamin |
40 |
|
1041 |
benjamin |
41 |
public void afficherLienPlateformeValidation();
|
1046 |
benjamin |
42 |
|
1041 |
benjamin |
43 |
public HTML getLienPlateforme();
|
436 |
benjamin |
44 |
}
|
|
|
45 |
|
|
|
46 |
private Vue vue;
|
|
|
47 |
|
|
|
48 |
private Observation observation;
|
|
|
49 |
|
|
|
50 |
private Image imagePrincipale;
|
1006 |
benjamin |
51 |
|
437 |
aurelien |
52 |
private List<Image> listeImages;
|
436 |
benjamin |
53 |
|
1553 |
jpm |
54 |
public ObservationImagesPresenteur(Vue vue, Observation observation, Image imagePrincipale) {
|
436 |
benjamin |
55 |
this.observation = observation;
|
|
|
56 |
this.vue = vue;
|
1039 |
benjamin |
57 |
this.imagePrincipale = imagePrincipale;
|
436 |
benjamin |
58 |
}
|
|
|
59 |
|
|
|
60 |
public void chargerImagesObservation() {
|
437 |
aurelien |
61 |
listeImages = observation.getImages();
|
1039 |
benjamin |
62 |
if (imagePrincipale != null) {
|
444 |
aurelien |
63 |
vue.chargerImagePrincipale(imagePrincipale);
|
1006 |
benjamin |
64 |
vue.getPhotoPrincipale().addClickHandler(creerGestionnaireClicGalerieImages(0, imagePrincipale));
|
444 |
aurelien |
65 |
}
|
436 |
benjamin |
66 |
|
1553 |
jpm |
67 |
String urlCourante = Window.Location.getHref();
|
|
|
68 |
Config config = new Config();
|
|
|
69 |
String urlAppliObs = config.getUrl("identiplante");
|
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 |
|
1553 |
jpm |
75 |
if (urlCourante.contains(urlAppliObs) && 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() {
|
1485 |
mathias |
89 |
vue.getLienPlateforme().addClickHandler(new ClickHandler() {
|
1046 |
benjamin |
90 |
|
1485 |
mathias |
91 |
@Override
|
|
|
92 |
public void onClick(ClickEvent arg0) {
|
|
|
93 |
BusEvenementiel.getInstance().fireEvent(new EvenementValidation(observation));
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
});
|
|
|
97 |
|
1045 |
benjamin |
98 |
BusEvenementiel.getInstance().addHandler(EvenementChangementImageValidation.TYPE, new GestionnaireEvenementChangementImageValidation() {
|
1046 |
benjamin |
99 |
|
1045 |
benjamin |
100 |
@Override
|
|
|
101 |
public void onChangementImage(EvenementChangementImageValidation event) {
|
1046 |
benjamin |
102 |
if (CacheClient.getInstance().getImageCourante().getObservation().getId().equals(observation.getId())) {
|
|
|
103 |
vue.chargerImagePrincipale(CacheClient.getInstance().getImageCourante());
|
|
|
104 |
}
|
1045 |
benjamin |
105 |
}
|
|
|
106 |
});
|
1046 |
benjamin |
107 |
|
437 |
aurelien |
108 |
}
|
1006 |
benjamin |
109 |
|
|
|
110 |
protected ClickHandler creerGestionnaireClicGalerieImages(final int indexImage, final Image imageCourante) {
|
437 |
aurelien |
111 |
ClickHandler gestionnaireClic = new ClickHandler() {
|
436 |
benjamin |
112 |
public void onClick(ClickEvent event) {
|
437 |
aurelien |
113 |
FenetreOverlayDefilantePresenteur presenteurGalerie = new FenetreOverlayDefilantePresenteur(indexImage, new FenetreOverlayDefilanteVue()) {
|
1006 |
benjamin |
114 |
|
437 |
aurelien |
115 |
@Override
|
|
|
116 |
public void surClicBoutonSuivant() {
|
|
|
117 |
int index = getIndexElementAffiche() + 1;
|
1006 |
benjamin |
118 |
if (index >= listeImages.size()) {
|
437 |
aurelien |
119 |
index = 0;
|
|
|
120 |
}
|
|
|
121 |
setContenuFenetreModale(index, new DetailImagePresenteur(listeImages.get(index), new DetailImageVue()));
|
|
|
122 |
}
|
1006 |
benjamin |
123 |
|
437 |
aurelien |
124 |
@Override
|
|
|
125 |
public void surClicBoutonPrecedent() {
|
|
|
126 |
int index = getIndexElementAffiche() - 1;
|
1006 |
benjamin |
127 |
if (index < 0) {
|
437 |
aurelien |
128 |
index = listeImages.size() - 1;
|
|
|
129 |
}
|
|
|
130 |
setContenuFenetreModale(index, new DetailImagePresenteur(listeImages.get(index), new DetailImageVue()));
|
|
|
131 |
}
|
|
|
132 |
};
|
|
|
133 |
presenteurGalerie.ouvrirFenetreModaleDefilante(indexImage, new DetailImagePresenteur(imageCourante, new DetailImageVue()));
|
440 |
aurelien |
134 |
presenteurGalerie.afficherBoutonsSuivantsPrecedents((listeImages.size() > 1));
|
436 |
benjamin |
135 |
}
|
437 |
aurelien |
136 |
};
|
|
|
137 |
return gestionnaireClic;
|
436 |
benjamin |
138 |
}
|
1006 |
benjamin |
139 |
|
|
|
140 |
protected ClickHandler creerGestionnaireClicChangementImagePrincipale(final Image imageCourante) {
|
|
|
141 |
ClickHandler gestionnaireClic = new ClickHandler() {
|
|
|
142 |
public void onClick(ClickEvent event) {
|
|
|
143 |
CacheClient.getInstance().setImageCourante(imageCourante);
|
1045 |
benjamin |
144 |
BusEvenementiel.getInstance().fireEvent(new EvenementChangementImageValidation());
|
1006 |
benjamin |
145 |
}
|
|
|
146 |
};
|
|
|
147 |
return gestionnaireClic;
|
|
|
148 |
}
|
1046 |
benjamin |
149 |
|
436 |
benjamin |
150 |
}
|