Subversion Repositories eFlore/Applications.coel

Rev

Rev 1262 | Rev 1367 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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