| 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;
|
| 453 |
aurelien |
8 |
import org.tela_botanica.del.client.modeles.ModeRecherche;
|
| 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;
|
| 379 |
gduche |
16 |
import org.tela_botanica.del.client.vues.rechercheimages.resultats.ResultatRechercheImageVue;
|
| 9 |
benjamin |
17 |
|
| 178 |
benjamin |
18 |
import com.google.gwt.event.dom.client.ChangeEvent;
|
|
|
19 |
import com.google.gwt.event.dom.client.ChangeHandler;
|
| 277 |
gduche |
20 |
import com.google.gwt.event.dom.client.HasChangeHandlers;
|
| 9 |
benjamin |
21 |
import com.google.gwt.user.client.ui.HasWidgets;
|
| 277 |
gduche |
22 |
import com.google.gwt.user.client.ui.IsWidget;
|
| 9 |
benjamin |
23 |
|
| 323 |
gduche |
24 |
public class MoteurRechercheImagePresenteur {
|
| 9 |
benjamin |
25 |
|
| 277 |
gduche |
26 |
public interface Vue extends IsWidget {
|
| 335 |
benjamin |
27 |
|
| 387 |
aurelien |
28 |
public void ajouterProtocole(String protocole);
|
| 455 |
benjamin |
29 |
|
| 387 |
aurelien |
30 |
public void selectionnerProtocole(int index);
|
| 455 |
benjamin |
31 |
|
| 387 |
aurelien |
32 |
public HasChangeHandlers getListeProtocoles();
|
| 455 |
benjamin |
33 |
|
| 387 |
aurelien |
34 |
public HasWidgets getZoneResultats();
|
| 455 |
benjamin |
35 |
|
| 387 |
aurelien |
36 |
public HasWidgets getZoneRecherche();
|
| 455 |
benjamin |
37 |
|
| 387 |
aurelien |
38 |
public String getNomProtocolSelectionne();
|
| 455 |
benjamin |
39 |
|
| 454 |
aurelien |
40 |
public int getIdProtocoleSelectionne();
|
| 455 |
benjamin |
41 |
|
| 454 |
aurelien |
42 |
public void ajouterVue(HasWidgets composite);
|
| 455 |
benjamin |
43 |
|
| 277 |
gduche |
44 |
}
|
| 335 |
benjamin |
45 |
|
| 277 |
gduche |
46 |
private Vue vue;
|
| 335 |
benjamin |
47 |
|
| 291 |
benjamin |
48 |
private final ProtocoleService protocoleService = MockDatasource.getInstance();
|
| 311 |
gduche |
49 |
private List<Protocole> protocoles;
|
| 335 |
benjamin |
50 |
|
|
|
51 |
// TODO : passer ça en cache
|
| 405 |
gduche |
52 |
private String protocoleParDefaut = Protocole.ESTHETISME;
|
| 335 |
benjamin |
53 |
|
| 277 |
gduche |
54 |
/**
|
|
|
55 |
* Constructeur
|
|
|
56 |
* */
|
| 323 |
gduche |
57 |
public MoteurRechercheImagePresenteur(Vue vue) {
|
| 277 |
gduche |
58 |
this.vue = vue;
|
| 178 |
benjamin |
59 |
if (CacheClient.getInstance().getProtocoleCourant() == null) {
|
| 291 |
benjamin |
60 |
CacheClient.getInstance().setProtocoleCourant(protocoleService.getProtocole(protocoleParDefaut));
|
| 178 |
benjamin |
61 |
}
|
| 454 |
aurelien |
62 |
gererEvenements();
|
|
|
63 |
chargerProtocoles();
|
| 9 |
benjamin |
64 |
}
|
|
|
65 |
|
|
|
66 |
public void go(HasWidgets composite) {
|
| 454 |
aurelien |
67 |
vue.ajouterVue(composite);
|
| 323 |
gduche |
68 |
chargerMoteurRechercheAvancee();
|
| 178 |
benjamin |
69 |
}
|
| 148 |
benjamin |
70 |
|
| 178 |
benjamin |
71 |
private void chargerProtocoles() {
|
| 291 |
benjamin |
72 |
protocoles = protocoleService.getProtocoles();
|
| 178 |
benjamin |
73 |
for (Protocole protocole : protocoles) {
|
| 277 |
gduche |
74 |
vue.ajouterProtocole(protocole.getNom());
|
| 148 |
benjamin |
75 |
}
|
| 277 |
gduche |
76 |
vue.selectionnerProtocole(protocoles.indexOf(CacheClient.getInstance().getProtocoleCourant()));
|
| 9 |
benjamin |
77 |
}
|
|
|
78 |
|
| 26 |
gduche |
79 |
public void gererEvenements() {
|
| 9 |
benjamin |
80 |
|
| 277 |
gduche |
81 |
vue.getListeProtocoles().addChangeHandler(new ChangeHandler() {
|
| 9 |
benjamin |
82 |
|
| 124 |
gduche |
83 |
@Override
|
| 178 |
benjamin |
84 |
public void onChange(ChangeEvent event) {
|
| 454 |
aurelien |
85 |
surChangementProtocole();
|
| 124 |
gduche |
86 |
}
|
| 178 |
benjamin |
87 |
});
|
| 455 |
benjamin |
88 |
|
| 9 |
benjamin |
89 |
}
|
| 455 |
benjamin |
90 |
|
| 454 |
aurelien |
91 |
public void surChangementProtocole() {
|
|
|
92 |
Protocole protocoleCourant = null;
|
|
|
93 |
for (Protocole protocole : protocoles) {
|
|
|
94 |
if (protocole.getId() == vue.getIdProtocoleSelectionne()) {
|
|
|
95 |
protocoleCourant = protocole;
|
|
|
96 |
}
|
|
|
97 |
}
|
| 335 |
benjamin |
98 |
|
| 454 |
aurelien |
99 |
CacheClient.getInstance().setProtocoleCourant(protocoleCourant);
|
|
|
100 |
EvenementChangementProtocole evenement = new EvenementChangementProtocole(protocoleCourant);
|
|
|
101 |
BusEvenementiel.getInstance().fireEvent(evenement);
|
|
|
102 |
}
|
|
|
103 |
|
| 323 |
gduche |
104 |
public void chargerMoteurRechercheAvancee() {
|
| 453 |
aurelien |
105 |
MoteurRecherchePresenteur presenteurRecherche = new MoteurRecherchePresenteur(new MoteurRechercheVue(""), ModeRecherche.MODE_IMAGE) {
|
| 335 |
benjamin |
106 |
public void lancerRecherche() {
|
|
|
107 |
chercherImages();
|
| 323 |
gduche |
108 |
}
|
|
|
109 |
};
|
|
|
110 |
presenteurRecherche.go(vue.getZoneRecherche());
|
| 9 |
benjamin |
111 |
}
|
| 335 |
benjamin |
112 |
|
|
|
113 |
public void chercherImages() {
|
| 359 |
benjamin |
114 |
vue.getZoneResultats().clear();
|
| 379 |
gduche |
115 |
new ResultatRechercheImagePresenteur(new ImageServiceConcret(), new ResultatRechercheImageVue()).go(vue.getZoneResultats());
|
| 335 |
benjamin |
116 |
}
|
|
|
117 |
|
| 278 |
gduche |
118 |
public HasWidgets getZoneResultats() {
|
|
|
119 |
return vue.getZoneResultats();
|
| 9 |
benjamin |
120 |
}
|
|
|
121 |
}
|