934 |
jpm |
1 |
package org.tela_botanica.client.vues.collection;
|
638 |
jp_milcent |
2 |
|
875 |
jpm |
3 |
import java.util.ArrayList;
|
|
|
4 |
|
638 |
jp_milcent |
5 |
import org.tela_botanica.client.Mediateur;
|
858 |
jpm |
6 |
import org.tela_botanica.client.composants.ChampComboBoxListeValeurs;
|
638 |
jp_milcent |
7 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
|
|
8 |
import org.tela_botanica.client.modeles.Information;
|
|
|
9 |
import org.tela_botanica.client.modeles.MenuApplicationId;
|
|
|
10 |
import org.tela_botanica.client.modeles.Valeur;
|
935 |
jpm |
11 |
import org.tela_botanica.client.modeles.collection.Collection;
|
948 |
jpm |
12 |
import org.tela_botanica.client.modeles.collection.CollectionBotanique;
|
875 |
jpm |
13 |
import org.tela_botanica.client.util.UtilArray;
|
884 |
jpm |
14 |
import org.tela_botanica.client.util.UtilString;
|
934 |
jpm |
15 |
import org.tela_botanica.client.vues.Formulaire;
|
935 |
jpm |
16 |
import org.tela_botanica.client.vues.structure.StructureForm;
|
638 |
jp_milcent |
17 |
|
858 |
jpm |
18 |
import com.extjs.gxt.ui.client.event.BaseEvent;
|
638 |
jp_milcent |
19 |
import com.extjs.gxt.ui.client.event.Events;
|
|
|
20 |
import com.extjs.gxt.ui.client.event.Listener;
|
|
|
21 |
import com.extjs.gxt.ui.client.widget.Info;
|
875 |
jpm |
22 |
import com.extjs.gxt.ui.client.widget.MessageBox;
|
638 |
jp_milcent |
23 |
import com.extjs.gxt.ui.client.widget.TabItem;
|
|
|
24 |
import com.extjs.gxt.ui.client.widget.TabPanel;
|
858 |
jpm |
25 |
import com.extjs.gxt.ui.client.widget.form.FieldSet;
|
|
|
26 |
import com.extjs.gxt.ui.client.widget.form.TextField;
|
|
|
27 |
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
|
|
|
28 |
import com.extjs.gxt.ui.client.widget.layout.FormData;
|
638 |
jp_milcent |
29 |
import com.google.gwt.core.client.GWT;
|
|
|
30 |
|
|
|
31 |
public class CollectionForm extends Formulaire implements Rafraichissable {
|
|
|
32 |
|
867 |
jpm |
33 |
protected Collection collection = null;
|
|
|
34 |
protected Collection collectionCollectee = null;
|
638 |
jp_milcent |
35 |
|
858 |
jpm |
36 |
private ChampComboBoxListeValeurs typesCollectionCombo = null;
|
638 |
jp_milcent |
37 |
|
775 |
jpm |
38 |
private TabPanel onglets = null;
|
867 |
jpm |
39 |
private CollectionFormGeneral generalOnglet = null;
|
|
|
40 |
private CollectionFormPersonne personneOnglet = null;
|
|
|
41 |
private CollectionFormPublication publicationOnglet = null;
|
|
|
42 |
private CollectionFormDescription descriptionOnglet = null;
|
|
|
43 |
private CollectionFormContenu contenuOnglet = null;
|
|
|
44 |
private CollectionFormInventaire inventaireOnglet = null;
|
858 |
jpm |
45 |
private TextField<String> nomChp = null;
|
687 |
jp_milcent |
46 |
|
883 |
jpm |
47 |
public CollectionForm(Mediateur mediateurCourrant, String collectionId) {
|
|
|
48 |
initialiserCollectionForm(mediateurCourrant, collectionId);
|
|
|
49 |
}
|
|
|
50 |
|
|
|
51 |
private void initialiserCollectionForm(Mediateur mediateurCourrant, String collectionId) {
|
|
|
52 |
collection = new Collection();
|
|
|
53 |
collection.setId(collectionId);
|
|
|
54 |
|
884 |
jpm |
55 |
String modeDeCreation = (UtilString.isEmpty(collection.getId()) ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER);
|
648 |
jp_milcent |
56 |
initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.COLLECTION);
|
883 |
jpm |
57 |
|
858 |
jpm |
58 |
creerFieldsetPrincipal();
|
883 |
jpm |
59 |
|
|
|
60 |
if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) {
|
|
|
61 |
mediateurCourrant.selectionnerCollection(this, collectionId);
|
|
|
62 |
mediateurCourrant.selectionnerCollectionAPersonne(this, collectionId, null);
|
|
|
63 |
mediateurCourrant.selectionnerCollectionAPublication(this, collectionId);
|
|
|
64 |
}
|
638 |
jp_milcent |
65 |
}
|
|
|
66 |
|
858 |
jpm |
67 |
private void creerFieldsetPrincipal() {
|
|
|
68 |
FieldSet principalFieldSet = new FieldSet();
|
|
|
69 |
principalFieldSet.setHeading("Info");
|
|
|
70 |
principalFieldSet.setCollapsible(true);
|
|
|
71 |
principalFieldSet.setLayout(Formulaire.creerFormLayout(150, LabelAlign.LEFT));
|
|
|
72 |
|
|
|
73 |
nomChp = new TextField<String>();
|
|
|
74 |
nomChp.setTabIndex(tabIndex++);
|
|
|
75 |
nomChp.setFieldLabel(i18nC.nomCollection());
|
|
|
76 |
nomChp.setAllowBlank(false);
|
|
|
77 |
nomChp.getMessages().setBlankText(i18nC.champObligatoire());
|
|
|
78 |
principalFieldSet.add(nomChp, new FormData(450, 0));
|
|
|
79 |
|
|
|
80 |
typesCollectionCombo = new ChampComboBoxListeValeurs(i18nC.typeCollectionNcd(), "typeCollectionNcd", tabIndex++);
|
867 |
jpm |
81 |
typesCollectionCombo.peupler(Valeur.COLLECTION_NCD_HERBIER);
|
858 |
jpm |
82 |
typesCollectionCombo.addListener(Events.Select, new Listener<BaseEvent>() {
|
|
|
83 |
@Override
|
|
|
84 |
public void handleEvent(BaseEvent be) {
|
|
|
85 |
Valeur valeur = typesCollectionCombo.getValue();
|
|
|
86 |
panneauFormulaire.remove(onglets);
|
|
|
87 |
mediateur.activerChargement("");
|
|
|
88 |
if (valeur != null && valeur.getId().equals(Valeur.COLLECTION_NCD_HERBIER)) {
|
|
|
89 |
onglets = creerOngletsHerbier();
|
|
|
90 |
panneauFormulaire.add(onglets);
|
|
|
91 |
} else {
|
|
|
92 |
onglets = creerOngletsDefaut();
|
|
|
93 |
panneauFormulaire.add(onglets);
|
|
|
94 |
}
|
|
|
95 |
mediateur.desactiverChargement();
|
|
|
96 |
panneauFormulaire.layout();
|
|
|
97 |
}
|
|
|
98 |
});
|
|
|
99 |
principalFieldSet.add(typesCollectionCombo, new FormData(150, 0));
|
|
|
100 |
typesCollectionCombo.fireEvent(Events.Select);
|
|
|
101 |
|
|
|
102 |
panneauFormulaire.setTopComponent(principalFieldSet);
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
protected TabPanel creerOngletsDefaut() {
|
|
|
106 |
TabPanel ongletsCollectionDefaut = new TabPanel();
|
|
|
107 |
|
|
|
108 |
// Onlget formulaire GENERAL
|
|
|
109 |
ongletsCollectionDefaut.add(creerOngletGeneral());
|
|
|
110 |
|
|
|
111 |
// Onlget formulaire AUTEUR
|
860 |
jpm |
112 |
ongletsCollectionDefaut.add(creerOngletPersonne());
|
858 |
jpm |
113 |
|
|
|
114 |
return ongletsCollectionDefaut;
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
protected TabPanel creerOngletsHerbier() {
|
|
|
118 |
TabPanel ongletsCollectionHerbier = new TabPanel();
|
638 |
jp_milcent |
119 |
// NOTE : pour faire apparaître les scrollBar il faut définir la hauteur du panneau d'onglets à 100% (autoHeight ne semble pas fonctionner)
|
858 |
jpm |
120 |
ongletsCollectionHerbier.setHeight("100%");
|
638 |
jp_milcent |
121 |
|
|
|
122 |
// Onlget formulaire GENERAL
|
858 |
jpm |
123 |
ongletsCollectionHerbier.add(creerOngletGeneral());
|
638 |
jp_milcent |
124 |
|
|
|
125 |
// Onlget formulaire AUTEUR
|
860 |
jpm |
126 |
ongletsCollectionHerbier.add(creerOngletPersonne());
|
638 |
jp_milcent |
127 |
|
687 |
jp_milcent |
128 |
// Onlget formulaire PUBLICATION
|
858 |
jpm |
129 |
ongletsCollectionHerbier.add(creerOngletPublication());
|
687 |
jp_milcent |
130 |
|
638 |
jp_milcent |
131 |
// Onlget formulaire DESCRIPTION
|
858 |
jpm |
132 |
ongletsCollectionHerbier.add(creerOngletDescription());
|
638 |
jp_milcent |
133 |
|
|
|
134 |
// Onlget formulaire CONTENU
|
858 |
jpm |
135 |
ongletsCollectionHerbier.add(creerOngletContenu());
|
638 |
jp_milcent |
136 |
|
|
|
137 |
// Onlget formulaire INVENTAIRE
|
858 |
jpm |
138 |
ongletsCollectionHerbier.add(creerOngletInventaire());
|
638 |
jp_milcent |
139 |
|
|
|
140 |
// Sélection de l'onglet par défaut
|
862 |
jpm |
141 |
ongletsCollectionHerbier.setSelection(generalOnglet);
|
638 |
jp_milcent |
142 |
|
858 |
jpm |
143 |
return ongletsCollectionHerbier;
|
638 |
jp_milcent |
144 |
}
|
|
|
145 |
|
|
|
146 |
private TabItem creerOngletGeneral() {
|
687 |
jp_milcent |
147 |
generalOnglet = new CollectionFormGeneral(this);
|
638 |
jp_milcent |
148 |
return generalOnglet;
|
|
|
149 |
}
|
|
|
150 |
|
860 |
jpm |
151 |
private TabItem creerOngletPersonne() {
|
|
|
152 |
personneOnglet = new CollectionFormPersonne(this);
|
|
|
153 |
return personneOnglet;
|
638 |
jp_milcent |
154 |
}
|
|
|
155 |
|
687 |
jp_milcent |
156 |
private TabItem creerOngletPublication() {
|
720 |
jp_milcent |
157 |
publicationOnglet = new CollectionFormPublication(this);
|
687 |
jp_milcent |
158 |
return publicationOnglet;
|
|
|
159 |
}
|
|
|
160 |
|
638 |
jp_milcent |
161 |
private TabItem creerOngletDescription() {
|
807 |
jpm |
162 |
descriptionOnglet = new CollectionFormDescription(this);
|
638 |
jp_milcent |
163 |
return descriptionOnglet;
|
|
|
164 |
}
|
|
|
165 |
|
|
|
166 |
private TabItem creerOngletContenu() {
|
858 |
jpm |
167 |
contenuOnglet = new CollectionFormContenu(this);
|
638 |
jp_milcent |
168 |
return contenuOnglet;
|
|
|
169 |
}
|
|
|
170 |
|
|
|
171 |
private TabItem creerOngletInventaire() {
|
862 |
jpm |
172 |
inventaireOnglet = new CollectionFormInventaire(this);
|
638 |
jp_milcent |
173 |
return inventaireOnglet;
|
|
|
174 |
}
|
|
|
175 |
|
|
|
176 |
public void rafraichir(Object nouvellesDonnees) {
|
858 |
jpm |
177 |
if (nouvellesDonnees instanceof Information) {
|
|
|
178 |
Information info = (Information) nouvellesDonnees;
|
|
|
179 |
rafraichirInformation(info);
|
|
|
180 |
} else {
|
|
|
181 |
GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
|
638 |
jp_milcent |
182 |
}
|
858 |
jpm |
183 |
|
782 |
jpm |
184 |
controlerFermetureApresRafraichissement();
|
638 |
jp_milcent |
185 |
}
|
|
|
186 |
|
687 |
jp_milcent |
187 |
private void rafraichirInformation(Information info) {
|
638 |
jp_milcent |
188 |
if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
|
|
|
189 |
GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);
|
|
|
190 |
}
|
|
|
191 |
|
875 |
jpm |
192 |
if (info.getType().equals("modif_collection")) {
|
638 |
jp_milcent |
193 |
Info.display("Modification d'une collection", info.toString());
|
|
|
194 |
} else if (info.getType().equals("selection_collection")) {
|
|
|
195 |
Info.display("Modification d'une collection", info.toString());
|
|
|
196 |
if (info.getDonnee(0) != null) {
|
|
|
197 |
collection = (Collection) info.getDonnee(0);
|
|
|
198 |
}
|
867 |
jpm |
199 |
peupler();
|
638 |
jp_milcent |
200 |
actualiserTitrePanneau();
|
875 |
jpm |
201 |
} else if (info.getType().equals("ajout_collection")) {
|
|
|
202 |
if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {
|
|
|
203 |
String collectionId = (String) info.getDonnee(0);
|
|
|
204 |
Info.display("Ajout d'une collection", "La collection '"+collectionId+"' a bien été ajoutée");
|
|
|
205 |
|
|
|
206 |
// Suite à la récupération de l'id de l'institution nouvellement ajoutée nous ajoutons les personnes et les publications liées
|
|
|
207 |
personneOnglet.rafraichir(info);
|
|
|
208 |
publicationOnglet.rafraichir(info);
|
|
|
209 |
} else {
|
|
|
210 |
Info.display("Ajout d'une Institution", info.toString());
|
|
|
211 |
}
|
883 |
jpm |
212 |
} else if (info.getType().equals("liste_collection_a_personne")) {
|
|
|
213 |
personneOnglet.rafraichir(info);
|
|
|
214 |
} else if (info.getType().equals("liste_collection_a_publication")) {
|
|
|
215 |
publicationOnglet.rafraichir(info);
|
638 |
jp_milcent |
216 |
}
|
|
|
217 |
}
|
867 |
jpm |
218 |
|
|
|
219 |
private void peupler() {
|
|
|
220 |
if (collection != null) {
|
|
|
221 |
nomChp.setValue(collection.getNom());
|
|
|
222 |
typesCollectionCombo.peupler(collection.getTypeNcd());
|
|
|
223 |
|
|
|
224 |
peuplerOnglets();
|
|
|
225 |
}
|
638 |
jp_milcent |
226 |
}
|
|
|
227 |
|
867 |
jpm |
228 |
private void peuplerOnglets() {
|
|
|
229 |
generalOnglet.peupler();
|
948 |
jpm |
230 |
descriptionOnglet.peupler();
|
867 |
jpm |
231 |
}
|
|
|
232 |
|
638 |
jp_milcent |
233 |
private void actualiserTitrePanneau() {
|
|
|
234 |
String titre = i18nC.titreModifFormCollection();
|
|
|
235 |
// Composition du titre
|
|
|
236 |
titre += " - ID : "+collection.getId();
|
|
|
237 |
panneauFormulaire.setHeading(titre);
|
|
|
238 |
}
|
|
|
239 |
|
934 |
jpm |
240 |
public boolean soumettreFormulaire() {
|
638 |
jp_milcent |
241 |
// Vérification de la validité des champs du formulaire
|
948 |
jpm |
242 |
boolean formulaireValide = verifierFormulaire();
|
|
|
243 |
if (formulaireValide) {
|
638 |
jp_milcent |
244 |
// Collecte des données du formulaire
|
948 |
jpm |
245 |
Collection collectionCollectee = collecterCollection();
|
|
|
246 |
|
638 |
jp_milcent |
247 |
if (mode.equals(MODE_AJOUTER)) {
|
948 |
jpm |
248 |
mediateur.ajouterCollection(this, collectionCollectee);
|
638 |
jp_milcent |
249 |
} else if (mode.equals(MODE_MODIFIER)) {
|
948 |
jpm |
250 |
if (collectionCollectee == null) {
|
638 |
jp_milcent |
251 |
Info.display("Modification d'une collection", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
|
|
|
252 |
} else {
|
948 |
jpm |
253 |
mediateur.modifierCollection(this, collectionCollectee);
|
638 |
jp_milcent |
254 |
}
|
|
|
255 |
}
|
875 |
jpm |
256 |
|
|
|
257 |
soumettreOnglets();
|
638 |
jp_milcent |
258 |
}
|
948 |
jpm |
259 |
return formulaireValide;
|
638 |
jp_milcent |
260 |
}
|
|
|
261 |
|
875 |
jpm |
262 |
private void soumettreOnglets() {
|
|
|
263 |
personneOnglet.soumettre();
|
907 |
jpm |
264 |
publicationOnglet.soumettre();
|
875 |
jpm |
265 |
}
|
|
|
266 |
|
934 |
jpm |
267 |
public void reinitialiserFormulaire() {
|
775 |
jpm |
268 |
if (mode.equals(StructureForm.MODE_MODIFIER)) {
|
|
|
269 |
mediateur.afficherFormCollection(collection.getId());
|
|
|
270 |
} else {
|
|
|
271 |
mediateur.afficherFormCollection(null);
|
|
|
272 |
}
|
|
|
273 |
}
|
|
|
274 |
|
638 |
jp_milcent |
275 |
private Collection collecterCollection() {
|
|
|
276 |
collectionCollectee = (Collection) collection.cloner(new Collection());
|
|
|
277 |
|
867 |
jpm |
278 |
this.collecter();
|
|
|
279 |
collecterOnglets();
|
638 |
jp_milcent |
280 |
|
|
|
281 |
Collection collectionARetourner = null;
|
|
|
282 |
if (!collectionCollectee.comparer(collection)) {
|
|
|
283 |
collectionARetourner = collection = collectionCollectee;
|
|
|
284 |
}
|
|
|
285 |
return collectionARetourner;
|
|
|
286 |
}
|
|
|
287 |
|
867 |
jpm |
288 |
private void collecter() {
|
|
|
289 |
collectionCollectee.setNom(nomChp.getValue());
|
|
|
290 |
collectionCollectee.setTypeNcd(typesCollectionCombo.getValue().getId());
|
638 |
jp_milcent |
291 |
}
|
|
|
292 |
|
867 |
jpm |
293 |
private void collecterOnglets() {
|
|
|
294 |
generalOnglet.collecter();
|
883 |
jpm |
295 |
personneOnglet.collecter();
|
907 |
jpm |
296 |
publicationOnglet.collecter();
|
948 |
jpm |
297 |
descriptionOnglet.collecter();
|
867 |
jpm |
298 |
}
|
|
|
299 |
|
934 |
jpm |
300 |
public boolean verifierFormulaire() {
|
875 |
jpm |
301 |
ArrayList<String> messages = new ArrayList<String>();
|
|
|
302 |
|
|
|
303 |
// Vérification des infos sur le nom de la collection
|
|
|
304 |
if (nomChp.getValue() == null || nomChp.getValue().equals("") || collection.getNom().equals("")) {
|
|
|
305 |
messages.add("Veuillez donner un nom à la collection.");
|
|
|
306 |
}
|
|
|
307 |
|
|
|
308 |
// Vérification des infos sur le type de collection
|
|
|
309 |
if (typesCollectionCombo.getValue() == null || typesCollectionCombo.getValue().equals("") || collection.getIdProjet().equals("")) {
|
|
|
310 |
messages.add("Veuillez sélectionner un type pour la collection.");
|
|
|
311 |
}
|
|
|
312 |
|
|
|
313 |
messages.addAll(verifierOnglets());
|
|
|
314 |
|
|
|
315 |
// Affichage des messages d'alerte
|
|
|
316 |
if (messages.size() != 0) {
|
|
|
317 |
String[] tableauDesMessages = {};
|
|
|
318 |
tableauDesMessages = messages.toArray(tableauDesMessages);
|
|
|
319 |
MessageBox.alert("Erreurs de saisies", UtilArray.implode(tableauDesMessages, "<br />"), null);
|
|
|
320 |
return false;
|
|
|
321 |
}
|
638 |
jp_milcent |
322 |
return true;
|
|
|
323 |
}
|
875 |
jpm |
324 |
|
|
|
325 |
private ArrayList<String> verifierOnglets() {
|
|
|
326 |
ArrayList<String> messages = new ArrayList<String>();
|
|
|
327 |
messages.addAll(generalOnglet.verifier());
|
|
|
328 |
messages.addAll(personneOnglet.verifier());
|
|
|
329 |
return messages;
|
|
|
330 |
}
|
638 |
jp_milcent |
331 |
}
|