50 |
benjamin |
1 |
package org.tela_botanica.del.client.vues.comparaisoneflore;
|
|
|
2 |
|
1062 |
benjamin |
3 |
import java.util.ArrayList;
|
50 |
benjamin |
4 |
import java.util.List;
|
|
|
5 |
|
73 |
benjamin |
6 |
import org.tela_botanica.del.client.cache.CacheClient;
|
148 |
benjamin |
7 |
import org.tela_botanica.del.client.modeles.Image;
|
352 |
aurelien |
8 |
import org.tela_botanica.del.client.modeles.ImageServiceResultat;
|
1037 |
benjamin |
9 |
import org.tela_botanica.del.client.modeles.InformationsRecherche;
|
1062 |
benjamin |
10 |
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
|
|
|
11 |
import org.tela_botanica.del.client.navigation.evenement.comparaisoneflore.EvenementComparaisonEflore;
|
|
|
12 |
import org.tela_botanica.del.client.navigation.evenement.comparaisoneflore.GestionnaireEvenementComparaisonEflore;
|
284 |
benjamin |
13 |
import org.tela_botanica.del.client.services.rest.ImageService;
|
352 |
aurelien |
14 |
import org.tela_botanica.del.client.services.rest.async.ImagesParTaxonCallback;
|
1062 |
benjamin |
15 |
import org.tela_botanica.del.client.vues.plateformedetermination.formulairerechercheeflore.FormulaireRechercheEflorePresenteur;
|
50 |
benjamin |
16 |
|
|
|
17 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
18 |
import com.google.gwt.event.dom.client.ClickHandler;
|
284 |
benjamin |
19 |
import com.google.gwt.event.dom.client.HasClickHandlers;
|
939 |
benjamin |
20 |
import com.google.gwt.user.client.Window;
|
1062 |
benjamin |
21 |
import com.google.gwt.user.client.ui.HTMLPanel;
|
50 |
benjamin |
22 |
import com.google.gwt.user.client.ui.HasWidgets;
|
284 |
benjamin |
23 |
import com.google.gwt.user.client.ui.IsWidget;
|
50 |
benjamin |
24 |
|
|
|
25 |
public class ComparaisonEflorePresenteur {
|
|
|
26 |
|
284 |
benjamin |
27 |
public interface Vue extends IsWidget {
|
|
|
28 |
public void chargerImagePrincipale(org.tela_botanica.del.client.modeles.Image image);
|
|
|
29 |
|
|
|
30 |
public void chargerImagesEflore(List<org.tela_botanica.del.client.modeles.Image> observationsEflore, int indexImage);
|
|
|
31 |
|
|
|
32 |
public HasClickHandlers getScrollLeftImage();
|
|
|
33 |
|
|
|
34 |
public HasClickHandlers getScrollRightImage();
|
|
|
35 |
|
|
|
36 |
public int getCurrentIndexImages();
|
361 |
benjamin |
37 |
|
939 |
benjamin |
38 |
public void startChargement();
|
|
|
39 |
|
361 |
benjamin |
40 |
public void stopChargement();
|
1062 |
benjamin |
41 |
|
|
|
42 |
public void afficherAucuneImageTrouvee();
|
|
|
43 |
|
|
|
44 |
public HTMLPanel getFormulaireRecherche();
|
|
|
45 |
|
|
|
46 |
public void setCurrentIndexImages(int index);
|
284 |
benjamin |
47 |
}
|
|
|
48 |
|
|
|
49 |
private Vue vue;
|
359 |
benjamin |
50 |
private final ImageService imageService;
|
284 |
benjamin |
51 |
|
148 |
benjamin |
52 |
private Image imagePrincipale;
|
50 |
benjamin |
53 |
private String nomTaxonComparaison;
|
1062 |
benjamin |
54 |
private List<org.tela_botanica.del.client.modeles.Image> imagesEflore = new ArrayList<Image>();
|
|
|
55 |
private int page = 0;
|
|
|
56 |
private int nbImagesPreFetch = 10;
|
62 |
benjamin |
57 |
|
882 |
aurelien |
58 |
public ComparaisonEflorePresenteur(Vue vue, ImageService imageService) {
|
284 |
benjamin |
59 |
this.vue = vue;
|
148 |
benjamin |
60 |
this.imagePrincipale = CacheClient.getInstance().getImageCourante();
|
73 |
benjamin |
61 |
this.nomTaxonComparaison = CacheClient.getInstance().getTaxonPourRechercheEflore();
|
360 |
benjamin |
62 |
this.imageService = imageService;
|
50 |
benjamin |
63 |
}
|
|
|
64 |
|
|
|
65 |
public void go(HasWidgets composite) {
|
284 |
benjamin |
66 |
composite.add(vue.asWidget());
|
148 |
benjamin |
67 |
vue.chargerImagePrincipale(imagePrincipale);
|
50 |
benjamin |
68 |
chargerObservationsEflore();
|
|
|
69 |
gererEvenements();
|
1062 |
benjamin |
70 |
new FormulaireRechercheEflorePresenteur().go(vue.getFormulaireRecherche());
|
50 |
benjamin |
71 |
}
|
|
|
72 |
|
284 |
benjamin |
73 |
public void chargerObservationsEflore() {
|
939 |
benjamin |
74 |
|
1062 |
benjamin |
75 |
int debut = (page * nbImagesPreFetch) + 1;
|
|
|
76 |
int fin = (page + 1) * nbImagesPreFetch;
|
|
|
77 |
|
361 |
benjamin |
78 |
vue.startChargement();
|
360 |
benjamin |
79 |
|
1037 |
benjamin |
80 |
InformationsRecherche informationsRecherche = new InformationsRecherche();
|
|
|
81 |
informationsRecherche.setTaxon(nomTaxonComparaison);
|
|
|
82 |
|
352 |
aurelien |
83 |
ImagesParTaxonCallback callback = new ImagesParTaxonCallback() {
|
360 |
benjamin |
84 |
|
352 |
aurelien |
85 |
@Override
|
939 |
benjamin |
86 |
public void surRetour(ImageServiceResultat imagesRecues) {
|
1062 |
benjamin |
87 |
if (imagesRecues == null || imagesRecues.getImages() == null || imagesRecues.getImages().size() == 0) {
|
|
|
88 |
vue.afficherAucuneImageTrouvee();
|
1037 |
benjamin |
89 |
} else {
|
1062 |
benjamin |
90 |
addImagesEflore(imagesRecues.getImages());
|
1037 |
benjamin |
91 |
vue.stopChargement();
|
1062 |
benjamin |
92 |
vue.chargerImagesEflore(imagesEflore, vue.getCurrentIndexImages());
|
1037 |
benjamin |
93 |
}
|
352 |
aurelien |
94 |
}
|
939 |
benjamin |
95 |
|
|
|
96 |
@Override
|
|
|
97 |
public void surErreur(String messageErreur) {
|
1062 |
benjamin |
98 |
vue.afficherAucuneImageTrouvee();
|
939 |
benjamin |
99 |
Window.alert(messageErreur);
|
|
|
100 |
}
|
|
|
101 |
|
352 |
aurelien |
102 |
};
|
360 |
benjamin |
103 |
|
1062 |
benjamin |
104 |
imageService.getImagesParTaxon(informationsRecherche, debut, fin, callback);
|
360 |
benjamin |
105 |
|
50 |
benjamin |
106 |
}
|
|
|
107 |
|
|
|
108 |
private void gererEvenements() {
|
284 |
benjamin |
109 |
vue.getScrollLeftImage().addClickHandler(new ClickHandler() {
|
50 |
benjamin |
110 |
|
|
|
111 |
@Override
|
|
|
112 |
public void onClick(ClickEvent event) {
|
148 |
benjamin |
113 |
vue.chargerImagesEflore(imagesEflore, vue.getCurrentIndexImages() - 1);
|
50 |
benjamin |
114 |
}
|
|
|
115 |
});
|
62 |
benjamin |
116 |
|
284 |
benjamin |
117 |
vue.getScrollRightImage().addClickHandler(new ClickHandler() {
|
50 |
benjamin |
118 |
|
|
|
119 |
@Override
|
|
|
120 |
public void onClick(ClickEvent event) {
|
1062 |
benjamin |
121 |
|
|
|
122 |
if (vue.getCurrentIndexImages() == imagesEflore.size() - 1) {
|
|
|
123 |
page += 1;
|
|
|
124 |
vue.setCurrentIndexImages(vue.getCurrentIndexImages()+1);
|
|
|
125 |
chargerObservationsEflore();
|
|
|
126 |
} else {
|
|
|
127 |
vue.chargerImagesEflore(imagesEflore, vue.getCurrentIndexImages() + 1);
|
|
|
128 |
}
|
50 |
benjamin |
129 |
}
|
|
|
130 |
});
|
1062 |
benjamin |
131 |
|
|
|
132 |
BusEvenementiel.getInstance().addHandler(EvenementComparaisonEflore.TYPE, new GestionnaireEvenementComparaisonEflore() {
|
|
|
133 |
|
|
|
134 |
@Override
|
|
|
135 |
public void onComparaisonEflore(EvenementComparaisonEflore event) {
|
|
|
136 |
nomTaxonComparaison = event.getTaxonDemande();
|
1064 |
benjamin |
137 |
page=0;
|
|
|
138 |
vue.setCurrentIndexImages(0);
|
|
|
139 |
getImagesEflore().clear();
|
1062 |
benjamin |
140 |
chargerObservationsEflore();
|
|
|
141 |
}
|
|
|
142 |
});
|
50 |
benjamin |
143 |
}
|
|
|
144 |
|
284 |
benjamin |
145 |
public List<org.tela_botanica.del.client.modeles.Image> getImagesEflore() {
|
|
|
146 |
return imagesEflore;
|
|
|
147 |
}
|
|
|
148 |
|
1062 |
benjamin |
149 |
public void addImagesEflore(List<org.tela_botanica.del.client.modeles.Image> imagesEflore) {
|
|
|
150 |
this.imagesEflore.addAll(imagesEflore);
|
360 |
benjamin |
151 |
}
|
|
|
152 |
|
50 |
benjamin |
153 |
}
|