1151 |
aurelien |
1 |
package org.tela_botanica.del.client.composants.motsclesimages.formulairesaisiemotclesimages;
|
|
|
2 |
|
|
|
3 |
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
|
|
|
4 |
import org.tela_botanica.del.client.navigation.evenement.ajoutmotcleimage.EvenementAjoutMotCleImage;
|
|
|
5 |
import org.tela_botanica.del.client.services.rest.MotsClesService;
|
1162 |
aurelien |
6 |
import org.tela_botanica.del.client.services.rest.async.AjoutMotsClesImageCallback;
|
1151 |
aurelien |
7 |
|
|
|
8 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
9 |
import com.google.gwt.event.dom.client.ClickHandler;
|
|
|
10 |
import com.google.gwt.event.dom.client.HasClickHandlers;
|
|
|
11 |
import com.google.gwt.event.dom.client.HasKeyPressHandlers;
|
|
|
12 |
import com.google.gwt.event.dom.client.KeyCodes;
|
|
|
13 |
import com.google.gwt.event.dom.client.KeyPressEvent;
|
|
|
14 |
import com.google.gwt.event.dom.client.KeyPressHandler;
|
|
|
15 |
import com.google.gwt.user.client.ui.HasText;
|
|
|
16 |
import com.google.gwt.user.client.ui.HasWidgets;
|
|
|
17 |
import com.google.gwt.user.client.ui.IsWidget;
|
|
|
18 |
|
|
|
19 |
public class FormulaireSaisieMotsClesImagePresenteur {
|
|
|
20 |
|
|
|
21 |
private MotsClesService motsClesService;
|
|
|
22 |
private String idImage;
|
|
|
23 |
|
|
|
24 |
public interface Vue extends IsWidget {
|
|
|
25 |
public HasClickHandlers getBoutonValider();
|
|
|
26 |
public HasText getSaisieMotsCles();
|
1152 |
aurelien |
27 |
public HasKeyPressHandlers getSaisieMotsClesHasKeyPressHandlers();
|
|
|
28 |
public void focuserChampSaisie();
|
1151 |
aurelien |
29 |
}
|
|
|
30 |
|
|
|
31 |
private Vue vue;
|
|
|
32 |
|
|
|
33 |
public FormulaireSaisieMotsClesImagePresenteur(String idImage, MotsClesService motsClesService, Vue vue) {
|
|
|
34 |
this.vue = vue;
|
|
|
35 |
this.motsClesService = motsClesService;
|
|
|
36 |
this.idImage = idImage;
|
|
|
37 |
gererEvenements();
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
public void go(HasWidgets composite) {
|
|
|
41 |
composite.add(vue.asWidget());
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
private void gererEvenements() {
|
|
|
45 |
vue.getBoutonValider().addClickHandler(new ClickHandler() {
|
|
|
46 |
@Override
|
|
|
47 |
public void onClick(ClickEvent event) {
|
|
|
48 |
validerSaisie();
|
|
|
49 |
}
|
|
|
50 |
});
|
|
|
51 |
|
|
|
52 |
vue.getSaisieMotsClesHasKeyPressHandlers().addKeyPressHandler(new KeyPressHandler() {
|
|
|
53 |
public void onKeyPress(KeyPressEvent event) {
|
|
|
54 |
if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_ENTER) {
|
|
|
55 |
validerSaisie();
|
|
|
56 |
}
|
|
|
57 |
}
|
|
|
58 |
});
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
private void validerSaisie() {
|
1152 |
aurelien |
62 |
String texte = vue.getSaisieMotsCles().getText();
|
|
|
63 |
if(texte != null && !texte.isEmpty()) {
|
1162 |
aurelien |
64 |
motsClesService.ajouterMotCleImage(idImage, vue.getSaisieMotsCles().getText(), new AjoutMotsClesImageCallback() {
|
1151 |
aurelien |
65 |
@Override
|
|
|
66 |
public void surRetour(Void objetRetour) {
|
1162 |
aurelien |
67 |
EvenementAjoutMotCleImage event = new EvenementAjoutMotCleImage(idImage);
|
1151 |
aurelien |
68 |
BusEvenementiel.getInstance().fireEvent(event);
|
|
|
69 |
}
|
|
|
70 |
});
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
public void viderChampSaisie() {
|
|
|
75 |
vue.getSaisieMotsCles().setText("");
|
|
|
76 |
}
|
1152 |
aurelien |
77 |
|
|
|
78 |
public void focuserChampSaisie() {
|
|
|
79 |
vue.focuserChampSaisie();
|
|
|
80 |
}
|
1151 |
aurelien |
81 |
}
|