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;
|
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;
|
436 |
benjamin |
18 |
|
1704 |
jpm |
19 |
import com.google.gwt.core.client.GWT;
|
436 |
benjamin |
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;
|
1704 |
jpm |
23 |
import com.google.gwt.event.shared.HandlerRegistration;
|
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();
|
1704 |
jpm |
43 |
|
|
|
44 |
public HandlerRegistration setImgPrincipaleClicGestionnaire(ClickHandler gestionnaireClic);
|
436 |
benjamin |
45 |
}
|
|
|
46 |
|
|
|
47 |
private Vue vue;
|
|
|
48 |
|
|
|
49 |
private Observation observation;
|
|
|
50 |
|
|
|
51 |
private Image imagePrincipale;
|
1006 |
benjamin |
52 |
|
437 |
aurelien |
53 |
private List<Image> listeImages;
|
1704 |
jpm |
54 |
|
1553 |
jpm |
55 |
public ObservationImagesPresenteur(Vue vue, Observation observation, Image imagePrincipale) {
|
436 |
benjamin |
56 |
this.observation = observation;
|
|
|
57 |
this.vue = vue;
|
1039 |
benjamin |
58 |
this.imagePrincipale = imagePrincipale;
|
436 |
benjamin |
59 |
}
|
|
|
60 |
|
|
|
61 |
public void chargerImagesObservation() {
|
437 |
aurelien |
62 |
listeImages = observation.getImages();
|
1039 |
benjamin |
63 |
if (imagePrincipale != null) {
|
444 |
aurelien |
64 |
vue.chargerImagePrincipale(imagePrincipale);
|
1704 |
jpm |
65 |
vue.setImgPrincipaleClicGestionnaire(creerGestionnaireClicGalerieImages(0, imagePrincipale));
|
444 |
aurelien |
66 |
}
|
436 |
benjamin |
67 |
|
1553 |
jpm |
68 |
String urlCourante = Window.Location.getHref();
|
|
|
69 |
Config config = new Config();
|
|
|
70 |
String urlAppliObs = config.getUrl("identiplante");
|
1704 |
jpm |
71 |
int indexImage = 0;
|
953 |
gduche |
72 |
for (Image imageCourante : listeImages) {
|
1704 |
jpm |
73 |
vue.ajouterPhoto(imageCourante, creerGestionnaireClicChangementImagePrincipale(indexImage, imageCourante));
|
|
|
74 |
indexImage++;
|
1046 |
benjamin |
75 |
|
1704 |
jpm |
76 |
if (urlCourante.contains(urlAppliObs) && indexImage >= 5) {
|
1041 |
benjamin |
77 |
vue.afficherLienPlateformeValidation();
|
|
|
78 |
break;
|
|
|
79 |
}
|
436 |
benjamin |
80 |
}
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
public void go(HasWidgets composite) {
|
|
|
84 |
composite.add(vue.asWidget());
|
|
|
85 |
chargerImagesObservation();
|
1041 |
benjamin |
86 |
gererEvenements();
|
436 |
benjamin |
87 |
}
|
|
|
88 |
|
|
|
89 |
protected void gererEvenements() {
|
1485 |
mathias |
90 |
vue.getLienPlateforme().addClickHandler(new ClickHandler() {
|
|
|
91 |
@Override
|
|
|
92 |
public void onClick(ClickEvent arg0) {
|
|
|
93 |
BusEvenementiel.getInstance().fireEvent(new EvenementValidation(observation));
|
|
|
94 |
}
|
|
|
95 |
});
|
|
|
96 |
|
1045 |
benjamin |
97 |
BusEvenementiel.getInstance().addHandler(EvenementChangementImageValidation.TYPE, new GestionnaireEvenementChangementImageValidation() {
|
|
|
98 |
@Override
|
|
|
99 |
public void onChangementImage(EvenementChangementImageValidation event) {
|
1046 |
benjamin |
100 |
if (CacheClient.getInstance().getImageCourante().getObservation().getId().equals(observation.getId())) {
|
1704 |
jpm |
101 |
GWT.log("Reception event Chgmt img index :"+event.indexImage);
|
1046 |
benjamin |
102 |
vue.chargerImagePrincipale(CacheClient.getInstance().getImageCourante());
|
1704 |
jpm |
103 |
vue.setImgPrincipaleClicGestionnaire(creerGestionnaireClicGalerieImages(event.indexImage, imagePrincipale));
|
1046 |
benjamin |
104 |
}
|
1045 |
benjamin |
105 |
}
|
|
|
106 |
});
|
437 |
aurelien |
107 |
}
|
1006 |
benjamin |
108 |
|
|
|
109 |
protected ClickHandler creerGestionnaireClicGalerieImages(final int indexImage, final Image imageCourante) {
|
437 |
aurelien |
110 |
ClickHandler gestionnaireClic = new ClickHandler() {
|
436 |
benjamin |
111 |
public void onClick(ClickEvent event) {
|
437 |
aurelien |
112 |
FenetreOverlayDefilantePresenteur presenteurGalerie = new FenetreOverlayDefilantePresenteur(indexImage, new FenetreOverlayDefilanteVue()) {
|
1006 |
benjamin |
113 |
|
437 |
aurelien |
114 |
@Override
|
|
|
115 |
public void surClicBoutonSuivant() {
|
|
|
116 |
int index = getIndexElementAffiche() + 1;
|
1006 |
benjamin |
117 |
if (index >= listeImages.size()) {
|
437 |
aurelien |
118 |
index = 0;
|
|
|
119 |
}
|
|
|
120 |
setContenuFenetreModale(index, new DetailImagePresenteur(listeImages.get(index), new DetailImageVue()));
|
|
|
121 |
}
|
1006 |
benjamin |
122 |
|
437 |
aurelien |
123 |
@Override
|
|
|
124 |
public void surClicBoutonPrecedent() {
|
|
|
125 |
int index = getIndexElementAffiche() - 1;
|
1006 |
benjamin |
126 |
if (index < 0) {
|
437 |
aurelien |
127 |
index = listeImages.size() - 1;
|
|
|
128 |
}
|
|
|
129 |
setContenuFenetreModale(index, new DetailImagePresenteur(listeImages.get(index), new DetailImageVue()));
|
|
|
130 |
}
|
|
|
131 |
};
|
1704 |
jpm |
132 |
presenteurGalerie.ouvrirFenetreModaleDefilante(indexImage, new DetailImagePresenteur(listeImages.get(indexImage), new DetailImageVue()));
|
440 |
aurelien |
133 |
presenteurGalerie.afficherBoutonsSuivantsPrecedents((listeImages.size() > 1));
|
436 |
benjamin |
134 |
}
|
437 |
aurelien |
135 |
};
|
|
|
136 |
return gestionnaireClic;
|
436 |
benjamin |
137 |
}
|
1006 |
benjamin |
138 |
|
1704 |
jpm |
139 |
protected ClickHandler creerGestionnaireClicChangementImagePrincipale(final int indexImage, final Image imageCourante) {
|
1006 |
benjamin |
140 |
ClickHandler gestionnaireClic = new ClickHandler() {
|
|
|
141 |
public void onClick(ClickEvent event) {
|
|
|
142 |
CacheClient.getInstance().setImageCourante(imageCourante);
|
1704 |
jpm |
143 |
EvenementChangementImageValidation chgmtImgEvent = new EvenementChangementImageValidation();
|
|
|
144 |
chgmtImgEvent.indexImage = indexImage;
|
|
|
145 |
BusEvenementiel.getInstance().fireEvent(chgmtImgEvent);
|
1006 |
benjamin |
146 |
}
|
|
|
147 |
};
|
|
|
148 |
return gestionnaireClic;
|
|
|
149 |
}
|
1046 |
benjamin |
150 |
|
436 |
benjamin |
151 |
}
|