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