Subversion Repositories eFlore/Applications.coel

Rev

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