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