46 |
aurelien |
1 |
package org.tela_botanica.del.client.vues.plateformedetermination.formulaireproposition;
|
|
|
2 |
|
95 |
aurelien |
3 |
import java.util.Date;
|
46 |
aurelien |
4 |
|
85 |
benjamin |
5 |
import org.tela_botanica.del.client.cache.CacheClient;
|
262 |
aurelien |
6 |
import org.tela_botanica.del.client.composants.formulaires.AutoCompletionComboBoxPresenteur;
|
453 |
aurelien |
7 |
import org.tela_botanica.del.client.composants.formulaires.AutoCompletionComboBoxVue;
|
321 |
aurelien |
8 |
|
262 |
aurelien |
9 |
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
|
228 |
aurelien |
10 |
import org.tela_botanica.del.client.composants.validation.ValidateurChampTexteNonNul;
|
553 |
jpm |
11 |
import org.tela_botanica.del.client.config.Config;
|
140 |
aurelien |
12 |
import org.tela_botanica.del.client.modeles.Commentaire;
|
|
|
13 |
import org.tela_botanica.del.client.modeles.PropositionDetermination;
|
159 |
benjamin |
14 |
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
|
|
|
15 |
import org.tela_botanica.del.client.navigation.evenement.ajoutdetermination.EvenementAjoutDetermination;
|
500 |
aurelien |
16 |
import org.tela_botanica.del.client.utils.UtilitairesAutoCompletionService;
|
46 |
aurelien |
17 |
|
77 |
aurelien |
18 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
19 |
import com.google.gwt.event.dom.client.ClickHandler;
|
303 |
aurelien |
20 |
import com.google.gwt.event.dom.client.HasClickHandlers;
|
268 |
aurelien |
21 |
import com.google.gwt.http.client.Response;
|
303 |
aurelien |
22 |
import com.google.gwt.user.client.ui.HasText;
|
46 |
aurelien |
23 |
import com.google.gwt.user.client.ui.HasWidgets;
|
303 |
aurelien |
24 |
import com.google.gwt.user.client.ui.IsWidget;
|
46 |
aurelien |
25 |
|
262 |
aurelien |
26 |
public class FormulairePropositionPresenteur extends Presenteur {
|
|
|
27 |
|
303 |
aurelien |
28 |
public interface Vue extends IsWidget {
|
553 |
jpm |
29 |
public HasText getNomPrenom();
|
|
|
30 |
public HasWidgets getPropositionTaxon();
|
|
|
31 |
public HasText getCommentaires();
|
|
|
32 |
public HasClickHandlers getBoutonValidationProposition();
|
|
|
33 |
public void afficherStyleErreur(String styleErreur);
|
|
|
34 |
public void supprimerStyleErreur(String styleErreur);
|
303 |
aurelien |
35 |
}
|
553 |
jpm |
36 |
|
303 |
aurelien |
37 |
private Vue vue;
|
553 |
jpm |
38 |
private Config config;
|
268 |
aurelien |
39 |
private AutoCompletionComboBoxPresenteur autoCompletionNomTaxonsPresenteur;
|
388 |
aurelien |
40 |
|
303 |
aurelien |
41 |
public FormulairePropositionPresenteur(Vue vue) {
|
|
|
42 |
this.vue = vue;
|
553 |
jpm |
43 |
config = new Config();
|
|
|
44 |
creerCompletionTaxons();
|
|
|
45 |
}
|
|
|
46 |
|
|
|
47 |
private void creerCompletionTaxons() {
|
|
|
48 |
String url = this.config.getUrl("nomSciCompletionService");
|
|
|
49 |
autoCompletionNomTaxonsPresenteur = new AutoCompletionComboBoxPresenteur(new AutoCompletionComboBoxVue(), url) {
|
321 |
aurelien |
50 |
protected String effectuerPreTraitementChaineRequete(String requete) {
|
388 |
aurelien |
51 |
return UtilitairesAutoCompletionService.effectuerPreTraitementChaineRequeteGenreEspeceSlash(requete);
|
321 |
aurelien |
52 |
}
|
|
|
53 |
|
|
|
54 |
@Override
|
268 |
aurelien |
55 |
protected String[] parserResultatRequete(Response response) {
|
388 |
aurelien |
56 |
return UtilitairesAutoCompletionService.parserRetourSimple(response);
|
268 |
aurelien |
57 |
}
|
553 |
jpm |
58 |
};
|
262 |
aurelien |
59 |
}
|
85 |
benjamin |
60 |
|
46 |
aurelien |
61 |
public void go(HasWidgets composite) {
|
303 |
aurelien |
62 |
autoCompletionNomTaxonsPresenteur.go(vue.getPropositionTaxon());
|
|
|
63 |
composite.add(vue.asWidget());
|
95 |
aurelien |
64 |
gererEvenements();
|
46 |
aurelien |
65 |
}
|
85 |
benjamin |
66 |
|
262 |
aurelien |
67 |
protected void gererEvenements() {
|
303 |
aurelien |
68 |
vue.getBoutonValidationProposition().addClickHandler(new ClickHandler() {
|
77 |
aurelien |
69 |
@Override
|
|
|
70 |
public void onClick(ClickEvent event) {
|
234 |
gduche |
71 |
|
|
|
72 |
if (!validerSaisieProposition()) {
|
105 |
aurelien |
73 |
return;
|
77 |
aurelien |
74 |
} else {
|
140 |
aurelien |
75 |
PropositionDetermination propositionAjoutee = collecterValeursSaisieProposition();
|
234 |
gduche |
76 |
CacheClient.getInstance().getObservationCourante().addImageCelValidationData(propositionAjoutee);
|
|
|
77 |
|
|
|
78 |
EvenementAjoutDetermination evenementAjoutDetermination = new EvenementAjoutDetermination(propositionAjoutee);
|
159 |
benjamin |
79 |
BusEvenementiel.getInstance().fireEvent(evenementAjoutDetermination);
|
77 |
aurelien |
80 |
}
|
85 |
benjamin |
81 |
}
|
77 |
aurelien |
82 |
});
|
|
|
83 |
}
|
234 |
gduche |
84 |
|
105 |
aurelien |
85 |
private boolean validerSaisieProposition() {
|
234 |
gduche |
86 |
|
303 |
aurelien |
87 |
ValidateurChampTexteNonNul validateurTaxon = new ValidateurChampTexteNonNul(vue.getNomPrenom()) {
|
|
|
88 |
@Override
|
|
|
89 |
public void afficherStyleErreur(String styleErreur) {
|
|
|
90 |
vue.afficherStyleErreur(styleErreur);
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
@Override
|
|
|
94 |
public void supprimerStyleErreur(String styleErreur) {
|
|
|
95 |
vue.supprimerStyleErreur(styleErreur);
|
|
|
96 |
}
|
|
|
97 |
};
|
228 |
aurelien |
98 |
boolean taxonSaisi = validateurTaxon.valider();
|
234 |
gduche |
99 |
|
140 |
aurelien |
100 |
return taxonSaisi;
|
105 |
aurelien |
101 |
}
|
234 |
gduche |
102 |
|
140 |
aurelien |
103 |
private PropositionDetermination collecterValeursSaisieProposition() {
|
|
|
104 |
PropositionDetermination propositionAjoutee = new PropositionDetermination();
|
148 |
benjamin |
105 |
propositionAjoutee.setId(CacheClient.getInstance().getImageCourante().getIdImage());
|
234 |
gduche |
106 |
|
303 |
aurelien |
107 |
String auteur = vue.getNomPrenom().getText();
|
|
|
108 |
if (vue.getCommentaires().getText() != "") {
|
|
|
109 |
String contenuCommentaire = vue.getCommentaires().getText();
|
234 |
gduche |
110 |
Commentaire comm = new Commentaire(auteur, new Date(), contenuCommentaire);
|
140 |
aurelien |
111 |
propositionAjoutee.ajouterCommentaire(comm);
|
|
|
112 |
}
|
|
|
113 |
propositionAjoutee.setContributeur(auteur);
|
105 |
aurelien |
114 |
propositionAjoutee.setDate(new Date());
|
234 |
gduche |
115 |
|
268 |
aurelien |
116 |
propositionAjoutee.setEspece(autoCompletionNomTaxonsPresenteur.getValeur());
|
234 |
gduche |
117 |
|
105 |
aurelien |
118 |
return propositionAjoutee;
|
|
|
119 |
}
|
46 |
aurelien |
120 |
}
|