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;
|
|
|
6 |
import org.tela_botanica.del.client.modeles.Image;
|
178 |
benjamin |
7 |
import org.tela_botanica.del.client.modeles.Protocole;
|
148 |
benjamin |
8 |
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
|
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;
|
289 |
benjamin |
11 |
import org.tela_botanica.del.client.services.rest.ImageService;
|
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;
|
279 |
gduche |
24 |
import com.google.gwt.user.client.Window;
|
9 |
benjamin |
25 |
import com.google.gwt.user.client.ui.HasWidgets;
|
277 |
gduche |
26 |
import com.google.gwt.user.client.ui.IsWidget;
|
9 |
benjamin |
27 |
|
178 |
benjamin |
28 |
public class RechercheImagePresenteur {
|
9 |
benjamin |
29 |
|
277 |
gduche |
30 |
public interface Vue extends IsWidget {
|
|
|
31 |
|
|
|
32 |
public abstract void ajouterProtocole(String protocole);
|
|
|
33 |
public abstract void selectionnerProtocole(int index);
|
|
|
34 |
public abstract HasClickHandlers getBoutonChercher();
|
|
|
35 |
public abstract HasKeyPressHandlers getChampEspece();
|
|
|
36 |
public abstract HasChangeHandlers getListeProtocoles();
|
278 |
gduche |
37 |
public abstract HasWidgets getZoneResultats();
|
277 |
gduche |
38 |
}
|
|
|
39 |
|
|
|
40 |
private Vue vue;
|
|
|
41 |
|
289 |
benjamin |
42 |
private final ImageService dataSource = MockDatasource.getInstance();
|
178 |
benjamin |
43 |
private String protocoleParDefaut = Protocole.IDENTIFICATION_AUTOMATIQUE;
|
|
|
44 |
private List<Protocole> protocoles;
|
9 |
benjamin |
45 |
|
277 |
gduche |
46 |
/**
|
|
|
47 |
* Constructeur
|
|
|
48 |
* */
|
|
|
49 |
public RechercheImagePresenteur(Vue vue) {
|
|
|
50 |
this.vue = vue;
|
|
|
51 |
|
178 |
benjamin |
52 |
if (CacheClient.getInstance().getProtocoleCourant() == null) {
|
|
|
53 |
CacheClient.getInstance().setProtocoleCourant(dataSource.getProtocole(protocoleParDefaut));
|
|
|
54 |
}
|
9 |
benjamin |
55 |
}
|
|
|
56 |
|
|
|
57 |
public void go(HasWidgets composite) {
|
277 |
gduche |
58 |
composite.add(vue.asWidget());
|
26 |
gduche |
59 |
gererEvenements();
|
178 |
benjamin |
60 |
chargerProtocoles();
|
|
|
61 |
}
|
148 |
benjamin |
62 |
|
178 |
benjamin |
63 |
private void chargerProtocoles() {
|
|
|
64 |
protocoles = dataSource.getProtocoles();
|
|
|
65 |
for (Protocole protocole : protocoles) {
|
277 |
gduche |
66 |
vue.ajouterProtocole(protocole.getNom());
|
148 |
benjamin |
67 |
}
|
277 |
gduche |
68 |
vue.selectionnerProtocole(protocoles.indexOf(CacheClient.getInstance().getProtocoleCourant()));
|
9 |
benjamin |
69 |
}
|
|
|
70 |
|
26 |
gduche |
71 |
public void gererEvenements() {
|
9 |
benjamin |
72 |
|
277 |
gduche |
73 |
vue.getBoutonChercher().addClickHandler(new ClickHandler() {
|
26 |
gduche |
74 |
|
9 |
benjamin |
75 |
@Override
|
|
|
76 |
public void onClick(ClickEvent event) {
|
279 |
gduche |
77 |
chargerImages(0, CacheClient.getInstance().getPaginationPasRechercheImage());
|
9 |
benjamin |
78 |
}
|
|
|
79 |
});
|
|
|
80 |
|
277 |
gduche |
81 |
vue.getChampEspece().addKeyPressHandler(new KeyPressHandler() {
|
9 |
benjamin |
82 |
|
204 |
gduche |
83 |
public void onKeyPress(KeyPressEvent event) {
|
|
|
84 |
if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
|
279 |
gduche |
85 |
chargerImages(0, CacheClient.getInstance().getPaginationPasRechercheImage());
|
204 |
gduche |
86 |
}
|
9 |
benjamin |
87 |
}
|
|
|
88 |
});
|
|
|
89 |
|
277 |
gduche |
90 |
vue.getListeProtocoles().addChangeHandler(new ChangeHandler() {
|
9 |
benjamin |
91 |
|
124 |
gduche |
92 |
@Override
|
178 |
benjamin |
93 |
public void onChange(ChangeEvent event) {
|
277 |
gduche |
94 |
|
|
|
95 |
Protocole protocoleCourant = (Protocole) event.getSource();
|
178 |
benjamin |
96 |
EvenementChangementProtocole evenement = new EvenementChangementProtocole(protocoleCourant);
|
|
|
97 |
BusEvenementiel.getInstance().fireEvent(evenement);
|
124 |
gduche |
98 |
}
|
178 |
benjamin |
99 |
});
|
9 |
benjamin |
100 |
}
|
|
|
101 |
|
279 |
gduche |
102 |
private void chargerImages(int debut, int fin) {
|
|
|
103 |
List<Image> imagesFromDatabase = dataSource.getImages(debut, fin);
|
178 |
benjamin |
104 |
EvenementRechercheImage evenementRechercheImage = new EvenementRechercheImage(imagesFromDatabase);
|
|
|
105 |
BusEvenementiel.getInstance().fireEvent(evenementRechercheImage);
|
9 |
benjamin |
106 |
}
|
277 |
gduche |
107 |
|
278 |
gduche |
108 |
public HasWidgets getZoneResultats() {
|
|
|
109 |
return vue.getZoneResultats();
|
9 |
benjamin |
110 |
}
|
|
|
111 |
}
|