| 148 |
benjamin |
1 |
package org.tela_botanica.del.client.vues.rechercheimages;
|
| 9 |
benjamin |
2 |
|
|
|
3 |
import java.util.List;
|
|
|
4 |
|
| 148 |
benjamin |
5 |
import org.tela_botanica.del.client.cache.CacheClient;
|
| 323 |
gduche |
6 |
import org.tela_botanica.del.client.composants.moteurrecherche.MoteurRecherchePresenteur;
|
|
|
7 |
import org.tela_botanica.del.client.composants.moteurrecherche.MoteurRechercheVue;
|
|
|
8 |
import org.tela_botanica.del.client.i18n.I18n;
|
| 178 |
benjamin |
9 |
import org.tela_botanica.del.client.modeles.Protocole;
|
| 148 |
benjamin |
10 |
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
|
| 178 |
benjamin |
11 |
import org.tela_botanica.del.client.navigation.evenement.changementprotocole.EvenementChangementProtocole;
|
| 344 |
aurelien |
12 |
import org.tela_botanica.del.client.services.rest.ImageServiceConcret;
|
| 291 |
benjamin |
13 |
import org.tela_botanica.del.client.services.rest.ProtocoleService;
|
| 9 |
benjamin |
14 |
import org.tela_botanica.del.client.utils.MockDatasource;
|
| 335 |
benjamin |
15 |
import org.tela_botanica.del.client.vues.rechercheimages.resultats.ResultatRechercheImagePresenteur;
|
| 9 |
benjamin |
16 |
|
| 178 |
benjamin |
17 |
import com.google.gwt.event.dom.client.ChangeEvent;
|
|
|
18 |
import com.google.gwt.event.dom.client.ChangeHandler;
|
| 277 |
gduche |
19 |
import com.google.gwt.event.dom.client.HasChangeHandlers;
|
| 9 |
benjamin |
20 |
import com.google.gwt.user.client.ui.HasWidgets;
|
| 277 |
gduche |
21 |
import com.google.gwt.user.client.ui.IsWidget;
|
| 9 |
benjamin |
22 |
|
| 323 |
gduche |
23 |
public class MoteurRechercheImagePresenteur {
|
| 9 |
benjamin |
24 |
|
| 277 |
gduche |
25 |
public interface Vue extends IsWidget {
|
| 335 |
benjamin |
26 |
|
| 277 |
gduche |
27 |
public abstract void ajouterProtocole(String protocole);
|
| 335 |
benjamin |
28 |
|
| 277 |
gduche |
29 |
public abstract void selectionnerProtocole(int index);
|
| 335 |
benjamin |
30 |
|
| 277 |
gduche |
31 |
public abstract HasChangeHandlers getListeProtocoles();
|
| 335 |
benjamin |
32 |
|
| 278 |
gduche |
33 |
public abstract HasWidgets getZoneResultats();
|
| 335 |
benjamin |
34 |
|
| 323 |
gduche |
35 |
public abstract HasWidgets getZoneRecherche();
|
| 360 |
benjamin |
36 |
|
|
|
37 |
public abstract String getNomProtocolSelectionne();
|
| 277 |
gduche |
38 |
}
|
| 335 |
benjamin |
39 |
|
| 277 |
gduche |
40 |
private Vue vue;
|
| 335 |
benjamin |
41 |
|
| 311 |
gduche |
42 |
// private final ImageService imageService = MockDatasource.getInstance();
|
| 291 |
benjamin |
43 |
private final ProtocoleService protocoleService = MockDatasource.getInstance();
|
| 311 |
gduche |
44 |
private List<Protocole> protocoles;
|
| 335 |
benjamin |
45 |
|
|
|
46 |
// TODO : passer ça en cache
|
| 178 |
benjamin |
47 |
private String protocoleParDefaut = Protocole.IDENTIFICATION_AUTOMATIQUE;
|
| 335 |
benjamin |
48 |
|
| 277 |
gduche |
49 |
/**
|
|
|
50 |
* Constructeur
|
|
|
51 |
* */
|
| 323 |
gduche |
52 |
public MoteurRechercheImagePresenteur(Vue vue) {
|
| 277 |
gduche |
53 |
this.vue = vue;
|
| 335 |
benjamin |
54 |
|
| 178 |
benjamin |
55 |
if (CacheClient.getInstance().getProtocoleCourant() == null) {
|
| 291 |
benjamin |
56 |
CacheClient.getInstance().setProtocoleCourant(protocoleService.getProtocole(protocoleParDefaut));
|
| 178 |
benjamin |
57 |
}
|
| 9 |
benjamin |
58 |
}
|
|
|
59 |
|
|
|
60 |
public void go(HasWidgets composite) {
|
| 277 |
gduche |
61 |
composite.add(vue.asWidget());
|
| 26 |
gduche |
62 |
gererEvenements();
|
| 178 |
benjamin |
63 |
chargerProtocoles();
|
| 323 |
gduche |
64 |
chargerMoteurRechercheAvancee();
|
| 178 |
benjamin |
65 |
}
|
| 148 |
benjamin |
66 |
|
| 178 |
benjamin |
67 |
private void chargerProtocoles() {
|
| 291 |
benjamin |
68 |
protocoles = protocoleService.getProtocoles();
|
| 178 |
benjamin |
69 |
for (Protocole protocole : protocoles) {
|
| 277 |
gduche |
70 |
vue.ajouterProtocole(protocole.getNom());
|
| 148 |
benjamin |
71 |
}
|
| 277 |
gduche |
72 |
vue.selectionnerProtocole(protocoles.indexOf(CacheClient.getInstance().getProtocoleCourant()));
|
| 9 |
benjamin |
73 |
}
|
|
|
74 |
|
| 26 |
gduche |
75 |
public void gererEvenements() {
|
| 9 |
benjamin |
76 |
|
| 277 |
gduche |
77 |
vue.getListeProtocoles().addChangeHandler(new ChangeHandler() {
|
| 9 |
benjamin |
78 |
|
| 124 |
gduche |
79 |
@Override
|
| 178 |
benjamin |
80 |
public void onChange(ChangeEvent event) {
|
| 360 |
benjamin |
81 |
Protocole protocoleCourant = null;
|
|
|
82 |
for (Protocole protocole : protocoles) {
|
|
|
83 |
if (protocole.getNom().equals(vue.getNomProtocolSelectionne())) {
|
|
|
84 |
protocoleCourant = protocole;
|
|
|
85 |
}
|
|
|
86 |
}
|
| 335 |
benjamin |
87 |
|
| 360 |
benjamin |
88 |
CacheClient.getInstance().setProtocoleCourant(protocoleCourant);
|
| 178 |
benjamin |
89 |
EvenementChangementProtocole evenement = new EvenementChangementProtocole(protocoleCourant);
|
|
|
90 |
BusEvenementiel.getInstance().fireEvent(evenement);
|
| 124 |
gduche |
91 |
}
|
| 178 |
benjamin |
92 |
});
|
| 9 |
benjamin |
93 |
}
|
| 335 |
benjamin |
94 |
|
| 323 |
gduche |
95 |
public void chargerMoteurRechercheAvancee() {
|
| 335 |
benjamin |
96 |
MoteurRecherchePresenteur presenteurRecherche = new MoteurRecherchePresenteur(new MoteurRechercheVue(I18n.getVocabulary().rechercherImage()), true, false) {
|
|
|
97 |
public void lancerRecherche() {
|
|
|
98 |
chercherImages();
|
| 323 |
gduche |
99 |
}
|
|
|
100 |
};
|
|
|
101 |
presenteurRecherche.go(vue.getZoneRecherche());
|
| 9 |
benjamin |
102 |
}
|
| 335 |
benjamin |
103 |
|
|
|
104 |
public void chercherImages() {
|
| 359 |
benjamin |
105 |
vue.getZoneResultats().clear();
|
| 344 |
aurelien |
106 |
new ResultatRechercheImagePresenteur(new ImageServiceConcret()).go(vue.getZoneResultats());
|
| 335 |
benjamin |
107 |
}
|
|
|
108 |
|
| 278 |
gduche |
109 |
public HasWidgets getZoneResultats() {
|
|
|
110 |
return vue.getZoneResultats();
|
| 9 |
benjamin |
111 |
}
|
|
|
112 |
}
|