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;
|
321 |
aurelien |
7 |
|
262 |
aurelien |
8 |
import org.tela_botanica.del.client.composants.presenteur.Presenteur;
|
228 |
aurelien |
9 |
import org.tela_botanica.del.client.composants.validation.ValidateurChampTexteNonNul;
|
140 |
aurelien |
10 |
import org.tela_botanica.del.client.modeles.Commentaire;
|
|
|
11 |
import org.tela_botanica.del.client.modeles.PropositionDetermination;
|
159 |
benjamin |
12 |
import org.tela_botanica.del.client.navigation.evenement.BusEvenementiel;
|
|
|
13 |
import org.tela_botanica.del.client.navigation.evenement.ajoutdetermination.EvenementAjoutDetermination;
|
46 |
aurelien |
14 |
|
77 |
aurelien |
15 |
import com.google.gwt.event.dom.client.ClickEvent;
|
|
|
16 |
import com.google.gwt.event.dom.client.ClickHandler;
|
303 |
aurelien |
17 |
import com.google.gwt.event.dom.client.HasClickHandlers;
|
268 |
aurelien |
18 |
import com.google.gwt.http.client.Response;
|
|
|
19 |
import com.google.gwt.json.client.JSONArray;
|
|
|
20 |
import com.google.gwt.json.client.JSONParser;
|
|
|
21 |
import com.google.gwt.json.client.JSONValue;
|
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 {
|
|
|
29 |
public abstract HasText getNomPrenom();
|
|
|
30 |
public abstract HasWidgets getPropositionTaxon();
|
|
|
31 |
public abstract HasText getCommentaires();
|
|
|
32 |
public abstract HasClickHandlers getBoutonValidationProposition();
|
|
|
33 |
public abstract void afficherStyleErreur(String styleErreur);
|
|
|
34 |
public abstract void supprimerStyleErreur(String styleErreur);
|
|
|
35 |
}
|
|
|
36 |
private Vue vue;
|
|
|
37 |
|
268 |
aurelien |
38 |
private AutoCompletionComboBoxPresenteur autoCompletionNomTaxonsPresenteur;
|
|
|
39 |
private String urlServiceCompletionNom = "http://www.tela-botanica.org/eflore/cel2/jrest/NameSearch/";
|
262 |
aurelien |
40 |
|
303 |
aurelien |
41 |
public FormulairePropositionPresenteur(Vue vue) {
|
|
|
42 |
this.vue = vue;
|
268 |
aurelien |
43 |
|
321 |
aurelien |
44 |
autoCompletionNomTaxonsPresenteur = new AutoCompletionComboBoxPresenteur(urlServiceCompletionNom) {
|
|
|
45 |
|
268 |
aurelien |
46 |
@Override
|
321 |
aurelien |
47 |
protected String effectuerPreTraitementChaineRequete(String requete) {
|
|
|
48 |
String[] parties = requete.split(" ", 2);
|
|
|
49 |
|
|
|
50 |
if(parties.length == 2) {
|
|
|
51 |
if(parties[1].trim().isEmpty()) {
|
|
|
52 |
parties[1] = "*";
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
return parties[0]+"/"+parties[1];
|
|
|
57 |
}
|
|
|
58 |
|
|
|
59 |
@Override
|
268 |
aurelien |
60 |
protected String[] parserResultatRequete(Response response) {
|
|
|
61 |
return convertirReponseVersListeNom(response);
|
|
|
62 |
}
|
|
|
63 |
};
|
262 |
aurelien |
64 |
}
|
85 |
benjamin |
65 |
|
46 |
aurelien |
66 |
public void go(HasWidgets composite) {
|
85 |
benjamin |
67 |
|
303 |
aurelien |
68 |
autoCompletionNomTaxonsPresenteur.go(vue.getPropositionTaxon());
|
|
|
69 |
composite.add(vue.asWidget());
|
95 |
aurelien |
70 |
gererEvenements();
|
46 |
aurelien |
71 |
}
|
85 |
benjamin |
72 |
|
262 |
aurelien |
73 |
protected void gererEvenements() {
|
303 |
aurelien |
74 |
vue.getBoutonValidationProposition().addClickHandler(new ClickHandler() {
|
77 |
aurelien |
75 |
|
|
|
76 |
@Override
|
|
|
77 |
public void onClick(ClickEvent event) {
|
234 |
gduche |
78 |
|
|
|
79 |
if (!validerSaisieProposition()) {
|
105 |
aurelien |
80 |
return;
|
77 |
aurelien |
81 |
} else {
|
140 |
aurelien |
82 |
PropositionDetermination propositionAjoutee = collecterValeursSaisieProposition();
|
234 |
gduche |
83 |
CacheClient.getInstance().getObservationCourante().addImageCelValidationData(propositionAjoutee);
|
|
|
84 |
|
|
|
85 |
EvenementAjoutDetermination evenementAjoutDetermination = new EvenementAjoutDetermination(propositionAjoutee);
|
159 |
benjamin |
86 |
BusEvenementiel.getInstance().fireEvent(evenementAjoutDetermination);
|
77 |
aurelien |
87 |
}
|
85 |
benjamin |
88 |
}
|
77 |
aurelien |
89 |
});
|
|
|
90 |
}
|
234 |
gduche |
91 |
|
105 |
aurelien |
92 |
private boolean validerSaisieProposition() {
|
234 |
gduche |
93 |
|
303 |
aurelien |
94 |
ValidateurChampTexteNonNul validateurTaxon = new ValidateurChampTexteNonNul(vue.getNomPrenom()) {
|
|
|
95 |
@Override
|
|
|
96 |
public void afficherStyleErreur(String styleErreur) {
|
|
|
97 |
vue.afficherStyleErreur(styleErreur);
|
|
|
98 |
}
|
|
|
99 |
|
|
|
100 |
@Override
|
|
|
101 |
public void supprimerStyleErreur(String styleErreur) {
|
|
|
102 |
vue.supprimerStyleErreur(styleErreur);
|
|
|
103 |
}
|
|
|
104 |
};
|
228 |
aurelien |
105 |
boolean taxonSaisi = validateurTaxon.valider();
|
234 |
gduche |
106 |
|
140 |
aurelien |
107 |
return taxonSaisi;
|
105 |
aurelien |
108 |
}
|
234 |
gduche |
109 |
|
140 |
aurelien |
110 |
private PropositionDetermination collecterValeursSaisieProposition() {
|
234 |
gduche |
111 |
|
140 |
aurelien |
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 |
}
|
268 |
aurelien |
128 |
|
|
|
129 |
private String[] convertirReponseVersListeNom(Response response) {
|
|
|
130 |
final JSONValue responseValue = JSONParser.parseStrict(response.getText());
|
|
|
131 |
JSONArray noms;
|
|
|
132 |
String[] valeurs = new String[0];
|
|
|
133 |
|
|
|
134 |
if ((noms=responseValue.isArray()) != null) {
|
|
|
135 |
|
|
|
136 |
final int taillemax = noms.size();
|
|
|
137 |
valeurs = new String[taillemax];
|
|
|
138 |
for (int i = 0; i < taillemax; i++) {
|
|
|
139 |
valeurs[i] = (noms.get(i).isArray().get(0).isString().stringValue());
|
|
|
140 |
}
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
return valeurs;
|
|
|
144 |
}
|
46 |
aurelien |
145 |
}
|