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);
|
558 |
aurelien |
35 |
public void afficherNomPrenomEtDesactiver(String nomPrenomFormate);
|
303 |
aurelien |
36 |
}
|
553 |
jpm |
37 |
|
303 |
aurelien |
38 |
private Vue vue;
|
553 |
jpm |
39 |
private Config config;
|
268 |
aurelien |
40 |
private AutoCompletionComboBoxPresenteur autoCompletionNomTaxonsPresenteur;
|
388 |
aurelien |
41 |
|
303 |
aurelien |
42 |
public FormulairePropositionPresenteur(Vue vue) {
|
|
|
43 |
this.vue = vue;
|
553 |
jpm |
44 |
config = new Config();
|
|
|
45 |
creerCompletionTaxons();
|
558 |
aurelien |
46 |
remplirAvecInfosUtilisateur();
|
553 |
jpm |
47 |
}
|
|
|
48 |
|
558 |
aurelien |
49 |
private void remplirAvecInfosUtilisateur() {
|
597 |
aurelien |
50 |
if(CacheClient.getInstance().getUtilisateur().estIdentifie()) {
|
558 |
aurelien |
51 |
vue.afficherNomPrenomEtDesactiver(CacheClient.getInstance().getUtilisateur().getNomPrenomFormate());
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
|
553 |
jpm |
55 |
private void creerCompletionTaxons() {
|
|
|
56 |
String url = this.config.getUrl("nomSciCompletionService");
|
|
|
57 |
autoCompletionNomTaxonsPresenteur = new AutoCompletionComboBoxPresenteur(new AutoCompletionComboBoxVue(), url) {
|
321 |
aurelien |
58 |
protected String effectuerPreTraitementChaineRequete(String requete) {
|
388 |
aurelien |
59 |
return UtilitairesAutoCompletionService.effectuerPreTraitementChaineRequeteGenreEspeceSlash(requete);
|
321 |
aurelien |
60 |
}
|
|
|
61 |
|
|
|
62 |
@Override
|
268 |
aurelien |
63 |
protected String[] parserResultatRequete(Response response) {
|
388 |
aurelien |
64 |
return UtilitairesAutoCompletionService.parserRetourSimple(response);
|
268 |
aurelien |
65 |
}
|
553 |
jpm |
66 |
};
|
262 |
aurelien |
67 |
}
|
85 |
benjamin |
68 |
|
46 |
aurelien |
69 |
public void go(HasWidgets composite) {
|
303 |
aurelien |
70 |
autoCompletionNomTaxonsPresenteur.go(vue.getPropositionTaxon());
|
|
|
71 |
composite.add(vue.asWidget());
|
95 |
aurelien |
72 |
gererEvenements();
|
46 |
aurelien |
73 |
}
|
85 |
benjamin |
74 |
|
262 |
aurelien |
75 |
protected void gererEvenements() {
|
303 |
aurelien |
76 |
vue.getBoutonValidationProposition().addClickHandler(new ClickHandler() {
|
77 |
aurelien |
77 |
@Override
|
|
|
78 |
public void onClick(ClickEvent event) {
|
234 |
gduche |
79 |
|
|
|
80 |
if (!validerSaisieProposition()) {
|
105 |
aurelien |
81 |
return;
|
77 |
aurelien |
82 |
} else {
|
140 |
aurelien |
83 |
PropositionDetermination propositionAjoutee = collecterValeursSaisieProposition();
|
234 |
gduche |
84 |
CacheClient.getInstance().getObservationCourante().addImageCelValidationData(propositionAjoutee);
|
|
|
85 |
|
|
|
86 |
EvenementAjoutDetermination evenementAjoutDetermination = new EvenementAjoutDetermination(propositionAjoutee);
|
159 |
benjamin |
87 |
BusEvenementiel.getInstance().fireEvent(evenementAjoutDetermination);
|
77 |
aurelien |
88 |
}
|
85 |
benjamin |
89 |
}
|
77 |
aurelien |
90 |
});
|
|
|
91 |
}
|
234 |
gduche |
92 |
|
105 |
aurelien |
93 |
private boolean validerSaisieProposition() {
|
234 |
gduche |
94 |
|
303 |
aurelien |
95 |
ValidateurChampTexteNonNul validateurTaxon = new ValidateurChampTexteNonNul(vue.getNomPrenom()) {
|
|
|
96 |
@Override
|
|
|
97 |
public void afficherStyleErreur(String styleErreur) {
|
|
|
98 |
vue.afficherStyleErreur(styleErreur);
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
@Override
|
|
|
102 |
public void supprimerStyleErreur(String styleErreur) {
|
|
|
103 |
vue.supprimerStyleErreur(styleErreur);
|
|
|
104 |
}
|
|
|
105 |
};
|
228 |
aurelien |
106 |
boolean taxonSaisi = validateurTaxon.valider();
|
234 |
gduche |
107 |
|
140 |
aurelien |
108 |
return taxonSaisi;
|
105 |
aurelien |
109 |
}
|
234 |
gduche |
110 |
|
140 |
aurelien |
111 |
private PropositionDetermination collecterValeursSaisieProposition() {
|
|
|
112 |
PropositionDetermination propositionAjoutee = new PropositionDetermination();
|
148 |
benjamin |
113 |
propositionAjoutee.setId(CacheClient.getInstance().getImageCourante().getIdImage());
|
234 |
gduche |
114 |
|
303 |
aurelien |
115 |
String auteur = vue.getNomPrenom().getText();
|
|
|
116 |
if (vue.getCommentaires().getText() != "") {
|
|
|
117 |
String contenuCommentaire = vue.getCommentaires().getText();
|
234 |
gduche |
118 |
Commentaire comm = new Commentaire(auteur, new Date(), contenuCommentaire);
|
140 |
aurelien |
119 |
propositionAjoutee.ajouterCommentaire(comm);
|
|
|
120 |
}
|
|
|
121 |
propositionAjoutee.setContributeur(auteur);
|
105 |
aurelien |
122 |
propositionAjoutee.setDate(new Date());
|
234 |
gduche |
123 |
|
268 |
aurelien |
124 |
propositionAjoutee.setEspece(autoCompletionNomTaxonsPresenteur.getValeur());
|
234 |
gduche |
125 |
|
105 |
aurelien |
126 |
return propositionAjoutee;
|
|
|
127 |
}
|
46 |
aurelien |
128 |
}
|