Subversion Repositories eFlore/Applications.coel

Rev

Rev 1098 | Rev 1239 | 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;
638 jp_milcent 8
import org.tela_botanica.client.interfaces.Rafraichissable;
9
import org.tela_botanica.client.modeles.Information;
10
import org.tela_botanica.client.modeles.MenuApplicationId;
11
import org.tela_botanica.client.modeles.Valeur;
935 jpm 12
import org.tela_botanica.client.modeles.collection.Collection;
968 jpm 13
import org.tela_botanica.client.util.Debug;
875 jpm 14
import org.tela_botanica.client.util.UtilArray;
884 jpm 15
import org.tela_botanica.client.util.UtilString;
934 jpm 16
import org.tela_botanica.client.vues.Formulaire;
935 jpm 17
import org.tela_botanica.client.vues.structure.StructureForm;
638 jp_milcent 18
 
858 jpm 19
import com.extjs.gxt.ui.client.event.BaseEvent;
638 jp_milcent 20
import com.extjs.gxt.ui.client.event.Events;
21
import com.extjs.gxt.ui.client.event.Listener;
22
import com.extjs.gxt.ui.client.widget.Info;
875 jpm 23
import com.extjs.gxt.ui.client.widget.MessageBox;
638 jp_milcent 24
import com.extjs.gxt.ui.client.widget.TabItem;
25
import com.extjs.gxt.ui.client.widget.TabPanel;
858 jpm 26
import com.extjs.gxt.ui.client.widget.form.FieldSet;
27
import com.extjs.gxt.ui.client.widget.form.TextField;
28
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
29
import com.extjs.gxt.ui.client.widget.layout.FormData;
638 jp_milcent 30
import com.google.gwt.core.client.GWT;
31
 
32
public class CollectionForm extends Formulaire implements Rafraichissable {
33
 
867 jpm 34
	protected Collection collection = null;
35
	protected Collection collectionCollectee = null;
638 jp_milcent 36
 
858 jpm 37
	private ChampComboBoxListeValeurs typesCollectionCombo = null;
638 jp_milcent 38
 
775 jpm 39
	private TabPanel onglets = null;
867 jpm 40
	private CollectionFormGeneral generalOnglet = null;
41
	private CollectionFormPersonne personneOnglet = null;
42
	private CollectionFormPublication publicationOnglet = null;
43
	private CollectionFormDescription descriptionOnglet = null;
44
	private CollectionFormContenu contenuOnglet = null;
45
	private CollectionFormInventaire inventaireOnglet = null;
997 jpm 46
	private CollectionFormCommentaire commentaireOnglet = null;
858 jpm 47
	private TextField<String> nomChp = null;
687 jp_milcent 48
 
883 jpm 49
	public CollectionForm(Mediateur mediateurCourrant, String collectionId) {
50
		initialiserCollectionForm(mediateurCourrant, collectionId);
51
	}
52
 
53
	private void initialiserCollectionForm(Mediateur mediateurCourrant, String collectionId) {
54
		collection = new Collection();
55
		collection.setId(collectionId);
56
 
884 jpm 57
		String modeDeCreation = (UtilString.isEmpty(collection.getId()) ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER);
648 jp_milcent 58
		initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.COLLECTION);
883 jpm 59
 
1098 jpm 60
		genererTitreFormulaire();
1084 jpm 61
 
62
		creerOnglets();
858 jpm 63
		creerFieldsetPrincipal();
883 jpm 64
 
65
		if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) {
1041 gduche 66
			mediateurCourrant.selectionnerCollection(this, collectionId, null);
883 jpm 67
			mediateurCourrant.selectionnerCollectionAPersonne(this, collectionId, null);
68
			mediateurCourrant.selectionnerCollectionAPublication(this, collectionId);
997 jpm 69
			mediateurCourrant.selectionnerCollectionACommentaire(this, collectionId);
883 jpm 70
		}
638 jp_milcent 71
	}
72
 
1098 jpm 73
	private void genererTitreFormulaire() {
1084 jpm 74
		String titre = i18nC.collectionTitreFormAjout();
75
		if (mode.equals(Formulaire.MODE_MODIFIER)) {
1098 jpm 76
			 titre = i18nC.collectionTitreFormModif();
77
			 if (collection != null) {
78
				 titre += " - "+i18nC.id()+": "+collection.getId();
79
			 }
1084 jpm 80
		}
1098 jpm 81
		panneauFormulaire.setHeading(titre);
1084 jpm 82
	}
83
 
858 jpm 84
	private void creerFieldsetPrincipal() {
85
		FieldSet principalFieldSet = new FieldSet();
86
		principalFieldSet.setHeading("Info");
87
		principalFieldSet.setCollapsible(true);
88
		principalFieldSet.setLayout(Formulaire.creerFormLayout(150, LabelAlign.LEFT));
89
 
90
		nomChp  = new TextField<String>();
91
		nomChp.setTabIndex(tabIndex++);
92
		nomChp.setFieldLabel(i18nC.nomCollection());
93
		nomChp.setAllowBlank(false);
975 jpm 94
		nomChp.addStyleName(ComposantClass.OBLIGATOIRE);
980 jpm 95
		nomChp.addListener(Events.Valid, creerEcouteurChampObligatoire());
858 jpm 96
		nomChp.getMessages().setBlankText(i18nC.champObligatoire());
97
		principalFieldSet.add(nomChp, new FormData(450, 0));
98
 
1084 jpm 99
		Listener<BaseEvent> ecouteurTypeCollection = new Listener<BaseEvent>() {
858 jpm 100
			@Override
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
		}
858 jpm 251
 
782 jpm 252
		controlerFermetureApresRafraichissement();
638 jp_milcent 253
	}
254
 
687 jp_milcent 255
	private void rafraichirInformation(Information info) {
638 jp_milcent 256
		if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
1163 jpm 257
			Debug.log("MESSAGES:\n"+info.getMessages().toString());
638 jp_milcent 258
		}
1163 jpm 259
		String infoType = info.getType();
638 jp_milcent 260
 
1163 jpm 261
		if (infoType.equals("modif_collection")) {
638 jp_milcent 262
			Info.display("Modification d'une collection", info.toString());
1163 jpm 263
		} else if (infoType.equals("selection_collection")) {
638 jp_milcent 264
			Info.display("Modification d'une collection", info.toString());
265
			if (info.getDonnee(0) != null) {
266
				collection = (Collection) info.getDonnee(0);
267
			}
867 jpm 268
			peupler();
1098 jpm 269
			genererTitreFormulaire();
1163 jpm 270
		} else if (infoType.equals("ajout_collection")) {
875 jpm 271
			if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {
272
				String collectionId = (String) info.getDonnee(0);
273
				Info.display("Ajout d'une collection", "La collection '"+collectionId+"' a bien été ajoutée");
274
 
275
				// Suite à la récupération de l'id de l'institution nouvellement ajoutée nous ajoutons les personnes et les publications liées
276
				personneOnglet.rafraichir(info);
277
				publicationOnglet.rafraichir(info);
1098 jpm 278
				commentaireOnglet.rafraichir(info);
875 jpm 279
			} else {
968 jpm 280
				Info.display("Ajout d'une collection", info.toString());
875 jpm 281
			}
1163 jpm 282
		} else if (infoType.equals("liste_collection_a_personne")) {
883 jpm 283
			personneOnglet.rafraichir(info);
1163 jpm 284
		} else if (infoType.equals("liste_collection_a_publication")) {
883 jpm 285
			publicationOnglet.rafraichir(info);
1163 jpm 286
		} else if (infoType.equals("liste_collection_a_commentaire")) {
997 jpm 287
			commentaireOnglet.rafraichir(info);
638 jp_milcent 288
		}
289
	}
867 jpm 290
 
291
	private void peupler() {
292
		if (collection != null) {
293
			nomChp.setValue(collection.getNom());
294
			typesCollectionCombo.peupler(collection.getTypeNcd());
295
 
296
			peuplerOnglets();
297
		}
638 jp_milcent 298
	}
299
 
867 jpm 300
	private void peuplerOnglets() {
301
		generalOnglet.peupler();
948 jpm 302
		descriptionOnglet.peupler();
954 jpm 303
		contenuOnglet.peupler();
304
		inventaireOnglet.peupler();
997 jpm 305
		commentaireOnglet.peupler();
867 jpm 306
	}
307
 
934 jpm 308
	public boolean soumettreFormulaire() {
638 jp_milcent 309
		// Vérification de la validité des champs du formulaire
948 jpm 310
		boolean formulaireValide = verifierFormulaire();
311
		if (formulaireValide) {
638 jp_milcent 312
			// Collecte des données du formulaire
949 jpm 313
			Collection collectionAEnregistrer = collecterCollection();
638 jp_milcent 314
			if (mode.equals(MODE_AJOUTER)) {
949 jpm 315
				mediateur.ajouterCollection(this, collectionAEnregistrer);
638 jp_milcent 316
			} else if (mode.equals(MODE_MODIFIER)) {
949 jpm 317
				if (collectionAEnregistrer == null) {
638 jp_milcent 318
					Info.display("Modification d'une collection", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
319
				} else {
949 jpm 320
					mediateur.modifierCollection(this, collectionAEnregistrer);
638 jp_milcent 321
				}
322
			}
875 jpm 323
 
324
			soumettreOnglets();
638 jp_milcent 325
		}
948 jpm 326
		return formulaireValide;
638 jp_milcent 327
	}
328
 
875 jpm 329
	private void soumettreOnglets() {
330
		personneOnglet.soumettre();
907 jpm 331
		publicationOnglet.soumettre();
997 jpm 332
		commentaireOnglet.soumettre();
875 jpm 333
	}
334
 
934 jpm 335
	public void reinitialiserFormulaire() {
775 jpm 336
		if (mode.equals(StructureForm.MODE_MODIFIER)) {
337
			mediateur.afficherFormCollection(collection.getId());
338
		} else {
339
			mediateur.afficherFormCollection(null);
340
		}
341
	}
342
 
638 jp_milcent 343
	private Collection collecterCollection() {
344
		collectionCollectee = (Collection) collection.cloner(new Collection());
954 jpm 345
 
867 jpm 346
		this.collecter();
347
		collecterOnglets();
954 jpm 348
 
638 jp_milcent 349
		Collection collectionARetourner = null;
949 jpm 350
		if (!collectionCollectee.comparer(collection) || !collectionCollectee.getBotanique().comparer(collection.getBotanique())) {
638 jp_milcent 351
			collectionARetourner = collection = collectionCollectee;
352
		}
353
		return collectionARetourner;
354
	}
355
 
867 jpm 356
	private void collecter() {
357
		collectionCollectee.setNom(nomChp.getValue());
358
		collectionCollectee.setTypeNcd(typesCollectionCombo.getValue().getId());
638 jp_milcent 359
	}
360
 
867 jpm 361
	private void collecterOnglets() {
362
		generalOnglet.collecter();
883 jpm 363
		personneOnglet.collecter();
907 jpm 364
		publicationOnglet.collecter();
948 jpm 365
		descriptionOnglet.collecter();
954 jpm 366
		contenuOnglet.collecter();
367
		inventaireOnglet.collecter();
997 jpm 368
		commentaireOnglet.collecter();
867 jpm 369
	}
370
 
934 jpm 371
	public boolean verifierFormulaire() {
875 jpm 372
		ArrayList<String> messages = new ArrayList<String>();
373
 
374
		// Vérification des infos sur le nom de la collection
968 jpm 375
		if (nomChp.getValue() == null
376
				|| nomChp.getValue().equals("")
377
				|| (mode.equals(MODE_MODIFIER) && collection != null && collection.getNom().equals(""))) {
875 jpm 378
			messages.add("Veuillez donner un nom à la collection.");
379
		}
380
 
381
		// Vérification des infos sur le type de collection
968 jpm 382
		if (typesCollectionCombo.getValue() == null
383
				|| typesCollectionCombo.getValue().equals("")
384
				|| (mode.equals(MODE_MODIFIER) && collection != null && collection.getIdProjet().equals(""))) {
875 jpm 385
			messages.add("Veuillez sélectionner un type pour la collection.");
386
		}
387
 
388
		messages.addAll(verifierOnglets());
389
 
390
		// Affichage des messages d'alerte
391
		if (messages.size() != 0) {
392
			String[] tableauDesMessages = {};
393
			tableauDesMessages = messages.toArray(tableauDesMessages);
394
			MessageBox.alert("Erreurs de saisies", UtilArray.implode(tableauDesMessages, "<br />"), null);
395
			return false;
396
		}
638 jp_milcent 397
		return true;
398
	}
875 jpm 399
 
400
	private ArrayList<String> verifierOnglets() {
401
		ArrayList<String> messages = new ArrayList<String>();
402
		messages.addAll(generalOnglet.verifier());
403
		messages.addAll(personneOnglet.verifier());
404
		return messages;
405
	}
638 jp_milcent 406
}