Subversion Repositories eFlore/Applications.coel

Rev

Rev 1163 | Rev 1245 | 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
			@Override
102
			public void handleEvent(BaseEvent be) {
103
				Valeur valeur = typesCollectionCombo.getValue();
968 jpm 104
 
105
				// Gestion des onglets en fonction du type de collection
858 jpm 106
				mediateur.activerChargement("");
107
				if (valeur != null && valeur.getId().equals(Valeur.COLLECTION_NCD_HERBIER)) {
1084 jpm 108
					activerOngletsHerbier();
858 jpm 109
				} else {
1084 jpm 110
					activerOngletsDefaut();
858 jpm 111
				}
112
				mediateur.desactiverChargement();
975 jpm 113
			}
1084 jpm 114
		};
115
 
116
		typesCollectionCombo = new ChampComboBoxListeValeurs(i18nC.typeCollectionNcd(), "typeCollectionNcd", tabIndex++);
117
		typesCollectionCombo.peupler(Valeur.COLLECTION_NCD_HERBIER);
118
		typesCollectionCombo.addStyleName(ComposantClass.OBLIGATOIRE);
119
		typesCollectionCombo.addListener(Events.Change, ecouteurTypeCollection);
120
		typesCollectionCombo.addListener(Events.Select, ecouteurTypeCollection);
980 jpm 121
		typesCollectionCombo.addListener(Events.Valid, creerEcouteurChampObligatoire());
858 jpm 122
		principalFieldSet.add(typesCollectionCombo, new FormData(150, 0));
123
		typesCollectionCombo.fireEvent(Events.Select);
124
 
125
		panneauFormulaire.setTopComponent(principalFieldSet);
126
	}
127
 
1084 jpm 128
	private void activerOngletsDefaut() {
129
		if (onglets.findItem(CollectionFormGeneral.ID, false) == null) {
130
			onglets.add(generalOnglet);
131
		}
132
		if (onglets.findItem(CollectionFormPersonne.ID, false) == null) {
133
			onglets.add(personneOnglet);
134
		}
135
		if (onglets.findItem(CollectionFormPublication.ID, false) != null) {
136
			onglets.remove(publicationOnglet);
137
		}
138
		if (onglets.findItem(CollectionFormDescription.ID, false) != null) {
139
			onglets.remove(descriptionOnglet);
140
		}
141
		if (onglets.findItem(CollectionFormContenu.ID, false) != null) {
142
			onglets.remove(contenuOnglet);
143
		}
144
		if (onglets.findItem(CollectionFormInventaire.ID, false) != null) {
145
			onglets.remove(inventaireOnglet);
146
		}
147
		if (onglets.findItem(CollectionFormCommentaire.ID, false) != null) {
148
			onglets.remove(commentaireOnglet);
149
		}
150
		panneauFormulaire.layout();
151
	}
858 jpm 152
 
1084 jpm 153
	private void activerOngletsHerbier() {
154
		if (onglets.findItem(CollectionFormGeneral.ID, false) == null) {
155
			onglets.add(generalOnglet);
156
		}
157
		if (onglets.findItem(CollectionFormPersonne.ID, false) == null) {
158
			onglets.add(personneOnglet);
159
		}
160
		if (onglets.findItem(CollectionFormPublication.ID, false) == null) {
161
			onglets.add(publicationOnglet);
162
		}
163
		if (onglets.findItem(CollectionFormDescription.ID, false) == null) {
164
			onglets.add(descriptionOnglet);
165
		}
166
		if (onglets.findItem(CollectionFormContenu.ID, false) == null) {
167
			onglets.add(contenuOnglet);
168
		}
169
		if (onglets.findItem(CollectionFormInventaire.ID, false) == null) {
170
			onglets.add(inventaireOnglet);
171
		}
172
		if (onglets.findItem(CollectionFormCommentaire.ID, false) == null) {
173
			onglets.add(commentaireOnglet);
174
		}
175
		panneauFormulaire.layout();
858 jpm 176
	}
177
 
1084 jpm 178
	private void creerOnglets() {
179
		onglets = new TabPanel();
638 jp_milcent 180
		// 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 181
		onglets.setHeight("100%");
638 jp_milcent 182
 
183
		// Onlget formulaire GENERAL
1084 jpm 184
		onglets.add(creerOngletGeneral());
638 jp_milcent 185
 
186
		// Onlget formulaire AUTEUR
1084 jpm 187
		onglets.add(creerOngletPersonne());
638 jp_milcent 188
 
687 jp_milcent 189
		// Onlget formulaire PUBLICATION
1084 jpm 190
		onglets.add(creerOngletPublication());
687 jp_milcent 191
 
638 jp_milcent 192
		// Onlget formulaire DESCRIPTION
1084 jpm 193
		onglets.add(creerOngletDescription());
638 jp_milcent 194
 
195
		// Onlget formulaire CONTENU
1084 jpm 196
		onglets.add(creerOngletContenu());
638 jp_milcent 197
 
198
		// Onlget formulaire INVENTAIRE
1084 jpm 199
		onglets.add(creerOngletInventaire());
638 jp_milcent 200
 
997 jpm 201
		// Onlget formulaire COMMENTAIRE
1084 jpm 202
		onglets.add(creerOngletCommentaire());
997 jpm 203
 
638 jp_milcent 204
		// Sélection de l'onglet par défaut
1084 jpm 205
		onglets.setSelection(generalOnglet);
638 jp_milcent 206
 
1084 jpm 207
		panneauFormulaire.add(onglets);
638 jp_milcent 208
	}
209
 
210
	private TabItem creerOngletGeneral() {
687 jp_milcent 211
		generalOnglet = new CollectionFormGeneral(this);
638 jp_milcent 212
		return generalOnglet;
213
	}
214
 
860 jpm 215
	private TabItem creerOngletPersonne() {
216
		personneOnglet = new CollectionFormPersonne(this);
217
		return personneOnglet;
638 jp_milcent 218
	}
219
 
687 jp_milcent 220
	private TabItem creerOngletPublication() {
720 jp_milcent 221
		publicationOnglet = new CollectionFormPublication(this);
687 jp_milcent 222
		return publicationOnglet;
223
	}
224
 
638 jp_milcent 225
	private TabItem creerOngletDescription() {
807 jpm 226
		descriptionOnglet = new CollectionFormDescription(this);
638 jp_milcent 227
		return descriptionOnglet;
228
	}
229
 
230
	private TabItem creerOngletContenu() {
858 jpm 231
		contenuOnglet = new CollectionFormContenu(this);
638 jp_milcent 232
		return contenuOnglet;
233
	}
234
 
235
	private TabItem creerOngletInventaire() {
862 jpm 236
		inventaireOnglet = new CollectionFormInventaire(this);
638 jp_milcent 237
		return inventaireOnglet;
238
	}
239
 
997 jpm 240
	private TabItem creerOngletCommentaire() {
241
		commentaireOnglet = new CollectionFormCommentaire(this);
242
		return commentaireOnglet;
243
	}
244
 
638 jp_milcent 245
	public void rafraichir(Object nouvellesDonnees) {
858 jpm 246
		if (nouvellesDonnees instanceof Information) {
247
			Information info = (Information) nouvellesDonnees;
248
			rafraichirInformation(info);
249
		} else {
1163 jpm 250
			Debug.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()));
638 jp_milcent 251
		}
858 jpm 252
 
1239 cyprien 253
		controlerFermeture();
638 jp_milcent 254
	}
255
 
687 jp_milcent 256
	private void rafraichirInformation(Information info) {
638 jp_milcent 257
		if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
1163 jpm 258
			Debug.log("MESSAGES:\n"+info.getMessages().toString());
638 jp_milcent 259
		}
1163 jpm 260
		String infoType = info.getType();
638 jp_milcent 261
 
1163 jpm 262
		if (infoType.equals("modif_collection")) {
1239 cyprien 263
			InfoLogger.display("Modification d'une collection", info.toString());
1163 jpm 264
		} else if (infoType.equals("selection_collection")) {
1239 cyprien 265
			InfoLogger.display("Modification d'une collection", info.toString());
638 jp_milcent 266
			if (info.getDonnee(0) != null) {
267
				collection = (Collection) info.getDonnee(0);
268
			}
867 jpm 269
			peupler();
1098 jpm 270
			genererTitreFormulaire();
1163 jpm 271
		} else if (infoType.equals("ajout_collection")) {
875 jpm 272
			if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {
273
				String collectionId = (String) info.getDonnee(0);
1239 cyprien 274
				InfoLogger.display("Ajout d'une collection", "La collection '"+collectionId+"' a bien été ajoutée");
875 jpm 275
 
276
				// Suite à la récupération de l'id de l'institution nouvellement ajoutée nous ajoutons les personnes et les publications liées
277
				personneOnglet.rafraichir(info);
278
				publicationOnglet.rafraichir(info);
1098 jpm 279
				commentaireOnglet.rafraichir(info);
875 jpm 280
			} else {
1239 cyprien 281
				InfoLogger.display("Ajout d'une collection", info.toString());
875 jpm 282
			}
1163 jpm 283
		} else if (infoType.equals("liste_collection_a_personne")) {
883 jpm 284
			personneOnglet.rafraichir(info);
1163 jpm 285
		} else if (infoType.equals("liste_collection_a_publication")) {
883 jpm 286
			publicationOnglet.rafraichir(info);
1163 jpm 287
		} else if (infoType.equals("liste_collection_a_commentaire")) {
997 jpm 288
			commentaireOnglet.rafraichir(info);
638 jp_milcent 289
		}
290
	}
867 jpm 291
 
292
	private void peupler() {
293
		if (collection != null) {
294
			nomChp.setValue(collection.getNom());
295
			typesCollectionCombo.peupler(collection.getTypeNcd());
296
 
297
			peuplerOnglets();
298
		}
638 jp_milcent 299
	}
300
 
867 jpm 301
	private void peuplerOnglets() {
302
		generalOnglet.peupler();
948 jpm 303
		descriptionOnglet.peupler();
954 jpm 304
		contenuOnglet.peupler();
305
		inventaireOnglet.peupler();
997 jpm 306
		commentaireOnglet.peupler();
867 jpm 307
	}
308
 
934 jpm 309
	public boolean soumettreFormulaire() {
638 jp_milcent 310
		// Vérification de la validité des champs du formulaire
948 jpm 311
		boolean formulaireValide = verifierFormulaire();
312
		if (formulaireValide) {
638 jp_milcent 313
			// Collecte des données du formulaire
949 jpm 314
			Collection collectionAEnregistrer = collecterCollection();
638 jp_milcent 315
			if (mode.equals(MODE_AJOUTER)) {
949 jpm 316
				mediateur.ajouterCollection(this, collectionAEnregistrer);
638 jp_milcent 317
			} else if (mode.equals(MODE_MODIFIER)) {
949 jpm 318
				if (collectionAEnregistrer == null) {
1239 cyprien 319
					InfoLogger.display("Modification d'une collection", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
638 jp_milcent 320
				} else {
949 jpm 321
					mediateur.modifierCollection(this, collectionAEnregistrer);
638 jp_milcent 322
				}
323
			}
875 jpm 324
 
325
			soumettreOnglets();
638 jp_milcent 326
		}
948 jpm 327
		return formulaireValide;
638 jp_milcent 328
	}
329
 
875 jpm 330
	private void soumettreOnglets() {
331
		personneOnglet.soumettre();
907 jpm 332
		publicationOnglet.soumettre();
997 jpm 333
		commentaireOnglet.soumettre();
875 jpm 334
	}
335
 
934 jpm 336
	public void reinitialiserFormulaire() {
775 jpm 337
		if (mode.equals(StructureForm.MODE_MODIFIER)) {
338
			mediateur.afficherFormCollection(collection.getId());
339
		} else {
340
			mediateur.afficherFormCollection(null);
341
		}
342
	}
343
 
638 jp_milcent 344
	private Collection collecterCollection() {
345
		collectionCollectee = (Collection) collection.cloner(new Collection());
954 jpm 346
 
867 jpm 347
		this.collecter();
348
		collecterOnglets();
954 jpm 349
 
638 jp_milcent 350
		Collection collectionARetourner = null;
949 jpm 351
		if (!collectionCollectee.comparer(collection) || !collectionCollectee.getBotanique().comparer(collection.getBotanique())) {
638 jp_milcent 352
			collectionARetourner = collection = collectionCollectee;
353
		}
354
		return collectionARetourner;
355
	}
356
 
867 jpm 357
	private void collecter() {
358
		collectionCollectee.setNom(nomChp.getValue());
359
		collectionCollectee.setTypeNcd(typesCollectionCombo.getValue().getId());
638 jp_milcent 360
	}
361
 
867 jpm 362
	private void collecterOnglets() {
363
		generalOnglet.collecter();
883 jpm 364
		personneOnglet.collecter();
907 jpm 365
		publicationOnglet.collecter();
948 jpm 366
		descriptionOnglet.collecter();
954 jpm 367
		contenuOnglet.collecter();
368
		inventaireOnglet.collecter();
997 jpm 369
		commentaireOnglet.collecter();
867 jpm 370
	}
371
 
934 jpm 372
	public boolean verifierFormulaire() {
875 jpm 373
		ArrayList<String> messages = new ArrayList<String>();
374
 
375
		// Vérification des infos sur le nom de la collection
968 jpm 376
		if (nomChp.getValue() == null
377
				|| nomChp.getValue().equals("")
378
				|| (mode.equals(MODE_MODIFIER) && collection != null && collection.getNom().equals(""))) {
875 jpm 379
			messages.add("Veuillez donner un nom à la collection.");
380
		}
381
 
382
		// Vérification des infos sur le type de collection
968 jpm 383
		if (typesCollectionCombo.getValue() == null
384
				|| typesCollectionCombo.getValue().equals("")
385
				|| (mode.equals(MODE_MODIFIER) && collection != null && collection.getIdProjet().equals(""))) {
875 jpm 386
			messages.add("Veuillez sélectionner un type pour la collection.");
387
		}
388
 
389
		messages.addAll(verifierOnglets());
390
 
391
		// Affichage des messages d'alerte
392
		if (messages.size() != 0) {
393
			String[] tableauDesMessages = {};
394
			tableauDesMessages = messages.toArray(tableauDesMessages);
395
			MessageBox.alert("Erreurs de saisies", UtilArray.implode(tableauDesMessages, "<br />"), null);
396
			return false;
397
		}
638 jp_milcent 398
		return true;
399
	}
875 jpm 400
 
401
	private ArrayList<String> verifierOnglets() {
402
		ArrayList<String> messages = new ArrayList<String>();
403
		messages.addAll(generalOnglet.verifier());
404
		messages.addAll(personneOnglet.verifier());
405
		return messages;
406
	}
638 jp_milcent 407
}