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;
|
9 |
benjamin |
11 |
import org.tela_botanica.del.client.utils.MockDatasource;
|
|
|
12 |
|
178 |
benjamin |
13 |
import com.google.gwt.event.dom.client.ChangeEvent;
|
|
|
14 |
import com.google.gwt.event.dom.client.ChangeHandler;
|
9 |
benjamin |
15 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
16 |
import com.google.gwt.event.dom.client.ClickHandler;
|
204 |
gduche |
17 |
import com.google.gwt.event.dom.client.KeyCodes;
|
|
|
18 |
import com.google.gwt.event.dom.client.KeyPressEvent;
|
|
|
19 |
import com.google.gwt.event.dom.client.KeyPressHandler;
|
9 |
benjamin |
20 |
import com.google.gwt.user.client.ui.HasWidgets;
|
|
|
21 |
|
178 |
benjamin |
22 |
public class RechercheImagePresenteur {
|
9 |
benjamin |
23 |
|
178 |
benjamin |
24 |
private final MockDatasource dataSource = MockDatasource.getInstance();
|
|
|
25 |
private final RechercheImageVue vue = new RechercheImageVue();
|
|
|
26 |
private String protocoleParDefaut = Protocole.IDENTIFICATION_AUTOMATIQUE;
|
|
|
27 |
private List<Protocole> protocoles;
|
9 |
benjamin |
28 |
|
178 |
benjamin |
29 |
public RechercheImagePresenteur() {
|
|
|
30 |
|
|
|
31 |
if (CacheClient.getInstance().getProtocoleCourant() == null) {
|
|
|
32 |
CacheClient.getInstance().setProtocoleCourant(dataSource.getProtocole(protocoleParDefaut));
|
|
|
33 |
}
|
9 |
benjamin |
34 |
}
|
|
|
35 |
|
|
|
36 |
public void go(HasWidgets composite) {
|
26 |
gduche |
37 |
composite.add(vue);
|
|
|
38 |
gererEvenements();
|
178 |
benjamin |
39 |
chargerProtocoles();
|
|
|
40 |
}
|
148 |
benjamin |
41 |
|
178 |
benjamin |
42 |
private void chargerProtocoles() {
|
|
|
43 |
protocoles = dataSource.getProtocoles();
|
|
|
44 |
for (Protocole protocole : protocoles) {
|
|
|
45 |
vue.getListeProtocoles().addItem(protocole.getNom());
|
148 |
benjamin |
46 |
}
|
178 |
benjamin |
47 |
vue.getListeProtocoles().setSelectedIndex(protocoles.indexOf(CacheClient.getInstance().getProtocoleCourant()));
|
9 |
benjamin |
48 |
}
|
|
|
49 |
|
26 |
gduche |
50 |
public void gererEvenements() {
|
9 |
benjamin |
51 |
|
124 |
gduche |
52 |
vue.getBoutonChercher().addClickHandler(new ClickHandler() {
|
26 |
gduche |
53 |
|
9 |
benjamin |
54 |
@Override
|
|
|
55 |
public void onClick(ClickEvent event) {
|
178 |
benjamin |
56 |
chargerImages();
|
9 |
benjamin |
57 |
}
|
|
|
58 |
});
|
|
|
59 |
|
204 |
gduche |
60 |
vue.getTextBox().addKeyPressHandler(new KeyPressHandler() {
|
9 |
benjamin |
61 |
|
204 |
gduche |
62 |
public void onKeyPress(KeyPressEvent event) {
|
|
|
63 |
if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
|
|
|
64 |
chargerImages();
|
|
|
65 |
}
|
9 |
benjamin |
66 |
}
|
|
|
67 |
});
|
|
|
68 |
|
178 |
benjamin |
69 |
vue.getListeProtocoles().addChangeHandler(new ChangeHandler() {
|
9 |
benjamin |
70 |
|
124 |
gduche |
71 |
@Override
|
178 |
benjamin |
72 |
public void onChange(ChangeEvent event) {
|
|
|
73 |
Protocole protocoleCourant = protocoles.get(vue.getListeProtocoles().getSelectedIndex());
|
|
|
74 |
EvenementChangementProtocole evenement = new EvenementChangementProtocole(protocoleCourant);
|
|
|
75 |
BusEvenementiel.getInstance().fireEvent(evenement);
|
124 |
gduche |
76 |
}
|
178 |
benjamin |
77 |
});
|
9 |
benjamin |
78 |
}
|
|
|
79 |
|
178 |
benjamin |
80 |
private void chargerImages() {
|
|
|
81 |
List<Image> imagesFromDatabase = dataSource.getImages();
|
|
|
82 |
EvenementRechercheImage evenementRechercheImage = new EvenementRechercheImage(imagesFromDatabase);
|
|
|
83 |
BusEvenementiel.getInstance().fireEvent(evenementRechercheImage);
|
9 |
benjamin |
84 |
}
|
|
|
85 |
|
178 |
benjamin |
86 |
public RechercheImageVue getVue() {
|
26 |
gduche |
87 |
return vue;
|
9 |
benjamin |
88 |
}
|
|
|
89 |
|
|
|
90 |
}
|