Subversion Repositories eFlore/Applications.coel

Rev

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