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;
|
178 |
benjamin |
6 |
import org.tela_botanica.del.client.modeles.Protocole;
|
148 |
benjamin |
7 |
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
|
311 |
gduche |
8 |
import org.tela_botanica.del.client.navigation.evenement.ajoutdetermination.EvenementAjoutDetermination;
|
178 |
benjamin |
9 |
import org.tela_botanica.del.client.navigation.evenement.changementprotocole.EvenementChangementProtocole;
|
148 |
benjamin |
10 |
import org.tela_botanica.del.client.navigation.evenement.rechercheimage.EvenementRechercheImage;
|
291 |
benjamin |
11 |
import org.tela_botanica.del.client.services.rest.ProtocoleService;
|
9 |
benjamin |
12 |
import org.tela_botanica.del.client.utils.MockDatasource;
|
|
|
13 |
|
178 |
benjamin |
14 |
import com.google.gwt.event.dom.client.ChangeEvent;
|
|
|
15 |
import com.google.gwt.event.dom.client.ChangeHandler;
|
9 |
benjamin |
16 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
17 |
import com.google.gwt.event.dom.client.ClickHandler;
|
277 |
gduche |
18 |
import com.google.gwt.event.dom.client.HasChangeHandlers;
|
|
|
19 |
import com.google.gwt.event.dom.client.HasClickHandlers;
|
|
|
20 |
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
|
204 |
gduche |
21 |
import com.google.gwt.event.dom.client.KeyCodes;
|
|
|
22 |
import com.google.gwt.event.dom.client.KeyPressEvent;
|
|
|
23 |
import com.google.gwt.event.dom.client.KeyPressHandler;
|
9 |
benjamin |
24 |
import com.google.gwt.user.client.ui.HasWidgets;
|
277 |
gduche |
25 |
import com.google.gwt.user.client.ui.IsWidget;
|
9 |
benjamin |
26 |
|
311 |
gduche |
27 |
public class MoteurRechercheImage {
|
9 |
benjamin |
28 |
|
277 |
gduche |
29 |
public interface Vue extends IsWidget {
|
|
|
30 |
|
|
|
31 |
public abstract void ajouterProtocole(String protocole);
|
|
|
32 |
public abstract void selectionnerProtocole(int index);
|
|
|
33 |
public abstract HasClickHandlers getBoutonChercher();
|
|
|
34 |
public abstract HasKeyPressHandlers getChampEspece();
|
|
|
35 |
public abstract HasChangeHandlers getListeProtocoles();
|
278 |
gduche |
36 |
public abstract HasWidgets getZoneResultats();
|
311 |
gduche |
37 |
public abstract String getValeurEspece();
|
277 |
gduche |
38 |
}
|
|
|
39 |
|
|
|
40 |
private Vue vue;
|
|
|
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;
|
|
|
45 |
|
|
|
46 |
//TODO : passer ça en cache
|
178 |
benjamin |
47 |
private String protocoleParDefaut = Protocole.IDENTIFICATION_AUTOMATIQUE;
|
311 |
gduche |
48 |
|
277 |
gduche |
49 |
/**
|
|
|
50 |
* Constructeur
|
|
|
51 |
* */
|
311 |
gduche |
52 |
public MoteurRechercheImage(Vue vue) {
|
277 |
gduche |
53 |
this.vue = vue;
|
|
|
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();
|
|
|
64 |
}
|
148 |
benjamin |
65 |
|
178 |
benjamin |
66 |
private void chargerProtocoles() {
|
291 |
benjamin |
67 |
protocoles = protocoleService.getProtocoles();
|
178 |
benjamin |
68 |
for (Protocole protocole : protocoles) {
|
277 |
gduche |
69 |
vue.ajouterProtocole(protocole.getNom());
|
148 |
benjamin |
70 |
}
|
277 |
gduche |
71 |
vue.selectionnerProtocole(protocoles.indexOf(CacheClient.getInstance().getProtocoleCourant()));
|
9 |
benjamin |
72 |
}
|
|
|
73 |
|
26 |
gduche |
74 |
public void gererEvenements() {
|
9 |
benjamin |
75 |
|
277 |
gduche |
76 |
vue.getBoutonChercher().addClickHandler(new ClickHandler() {
|
26 |
gduche |
77 |
|
9 |
benjamin |
78 |
@Override
|
|
|
79 |
public void onClick(ClickEvent event) {
|
311 |
gduche |
80 |
lancerRechercheImage();
|
9 |
benjamin |
81 |
}
|
|
|
82 |
});
|
|
|
83 |
|
277 |
gduche |
84 |
vue.getChampEspece().addKeyPressHandler(new KeyPressHandler() {
|
9 |
benjamin |
85 |
|
204 |
gduche |
86 |
public void onKeyPress(KeyPressEvent event) {
|
|
|
87 |
if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
|
311 |
gduche |
88 |
lancerRechercheImage();
|
204 |
gduche |
89 |
}
|
9 |
benjamin |
90 |
}
|
|
|
91 |
});
|
|
|
92 |
|
277 |
gduche |
93 |
vue.getListeProtocoles().addChangeHandler(new ChangeHandler() {
|
9 |
benjamin |
94 |
|
124 |
gduche |
95 |
@Override
|
178 |
benjamin |
96 |
public void onChange(ChangeEvent event) {
|
277 |
gduche |
97 |
|
|
|
98 |
Protocole protocoleCourant = (Protocole) event.getSource();
|
178 |
benjamin |
99 |
EvenementChangementProtocole evenement = new EvenementChangementProtocole(protocoleCourant);
|
|
|
100 |
BusEvenementiel.getInstance().fireEvent(evenement);
|
124 |
gduche |
101 |
}
|
178 |
benjamin |
102 |
});
|
9 |
benjamin |
103 |
}
|
311 |
gduche |
104 |
|
|
|
105 |
public void lancerRechercheImage() {
|
|
|
106 |
CacheClient.getInstance().setEspeceRecherche(vue.getValeurEspece());
|
|
|
107 |
BusEvenementiel.getInstance().fireEvent(new EvenementRechercheImage());
|
9 |
benjamin |
108 |
}
|
277 |
gduche |
109 |
|
278 |
gduche |
110 |
public HasWidgets getZoneResultats() {
|
|
|
111 |
return vue.getZoneResultats();
|
9 |
benjamin |
112 |
}
|
|
|
113 |
}
|