Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
638 jp_milcent 1
package org.tela_botanica.client.vues;
2
 
875 jpm 3
import java.util.ArrayList;
4
 
638 jp_milcent 5
import org.tela_botanica.client.Mediateur;
858 jpm 6
import org.tela_botanica.client.composants.ChampComboBoxListeValeurs;
638 jp_milcent 7
import org.tela_botanica.client.interfaces.Rafraichissable;
8
import org.tela_botanica.client.modeles.Collection;
883 jpm 9
import org.tela_botanica.client.modeles.CollectionAPersonneListe;
10
import org.tela_botanica.client.modeles.CollectionAPublicationListe;
638 jp_milcent 11
import org.tela_botanica.client.modeles.Information;
12
import org.tela_botanica.client.modeles.MenuApplicationId;
883 jpm 13
import org.tela_botanica.client.modeles.Publication;
14
import org.tela_botanica.client.modeles.PublicationAPersonne;
638 jp_milcent 15
import org.tela_botanica.client.modeles.Valeur;
875 jpm 16
import org.tela_botanica.client.util.UtilArray;
638 jp_milcent 17
 
858 jpm 18
import com.extjs.gxt.ui.client.event.BaseEvent;
638 jp_milcent 19
import com.extjs.gxt.ui.client.event.ButtonEvent;
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.event.SelectionListener;
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;
687 jp_milcent 27
import com.extjs.gxt.ui.client.widget.button.Button;
858 jpm 28
import com.extjs.gxt.ui.client.widget.form.FieldSet;
29
import com.extjs.gxt.ui.client.widget.form.TextField;
30
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
31
import com.extjs.gxt.ui.client.widget.layout.FormData;
638 jp_milcent 32
import com.google.gwt.core.client.GWT;
33
 
34
public class CollectionForm extends Formulaire implements Rafraichissable {
35
 
867 jpm 36
	protected Collection collection = null;
37
	protected Collection collectionCollectee = null;
638 jp_milcent 38
 
858 jpm 39
	private ChampComboBoxListeValeurs typesCollectionCombo = null;
638 jp_milcent 40
 
775 jpm 41
	private TabPanel onglets = null;
867 jpm 42
	private CollectionFormGeneral generalOnglet = null;
43
	private CollectionFormPersonne personneOnglet = null;
44
	private CollectionFormPublication publicationOnglet = null;
45
	private CollectionFormDescription descriptionOnglet = null;
46
	private CollectionFormContenu contenuOnglet = null;
47
	private CollectionFormInventaire inventaireOnglet = 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
 
58
		String modeDeCreation = (collection.getId().isEmpty() ? Formulaire.MODE_AJOUTER : Formulaire.MODE_MODIFIER);
648 jp_milcent 59
		initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.COLLECTION);
883 jpm 60
 
858 jpm 61
		creerFieldsetPrincipal();
883 jpm 62
 
63
		if (modeDeCreation.equals(Formulaire.MODE_MODIFIER)) {
64
			mediateurCourrant.selectionnerCollection(this, collectionId);
65
			mediateurCourrant.selectionnerCollectionAPersonne(this, collectionId, null);
66
			mediateurCourrant.selectionnerCollectionAPublication(this, collectionId);
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);
80
		nomChp.getMessages().setBlankText(i18nC.champObligatoire());
81
		principalFieldSet.add(nomChp, new FormData(450, 0));
82
 
83
		typesCollectionCombo = new ChampComboBoxListeValeurs(i18nC.typeCollectionNcd(), "typeCollectionNcd", tabIndex++);
867 jpm 84
		typesCollectionCombo.peupler(Valeur.COLLECTION_NCD_HERBIER);
858 jpm 85
		typesCollectionCombo.addListener(Events.Select, new Listener<BaseEvent>() {
86
			@Override
87
			public void handleEvent(BaseEvent be) {
88
				Valeur valeur = typesCollectionCombo.getValue();
89
				panneauFormulaire.remove(onglets);
90
				mediateur.activerChargement("");
91
				if (valeur != null && valeur.getId().equals(Valeur.COLLECTION_NCD_HERBIER)) {
92
					onglets = creerOngletsHerbier();
93
					panneauFormulaire.add(onglets);
94
				} else {
95
					onglets = creerOngletsDefaut();
96
					panneauFormulaire.add(onglets);
97
				}
98
				mediateur.desactiverChargement();
99
				panneauFormulaire.layout();
100
			}
101
		});
102
		principalFieldSet.add(typesCollectionCombo, new FormData(150, 0));
103
		typesCollectionCombo.fireEvent(Events.Select);
104
 
105
		panneauFormulaire.setTopComponent(principalFieldSet);
106
	}
107
 
108
	protected TabPanel creerOngletsDefaut() {
109
		TabPanel ongletsCollectionDefaut = new TabPanel();
110
 
111
		// Onlget formulaire GENERAL
112
		ongletsCollectionDefaut.add(creerOngletGeneral());
113
 
114
		// Onlget formulaire AUTEUR
860 jpm 115
		ongletsCollectionDefaut.add(creerOngletPersonne());
858 jpm 116
 
117
		return ongletsCollectionDefaut;
118
	}
119
 
120
	protected TabPanel creerOngletsHerbier() {
121
		TabPanel ongletsCollectionHerbier = new TabPanel();
638 jp_milcent 122
		// 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 123
		ongletsCollectionHerbier.setHeight("100%");
638 jp_milcent 124
 
125
		// Onlget formulaire GENERAL
858 jpm 126
		ongletsCollectionHerbier.add(creerOngletGeneral());
638 jp_milcent 127
 
128
		// Onlget formulaire AUTEUR
860 jpm 129
		ongletsCollectionHerbier.add(creerOngletPersonne());
638 jp_milcent 130
 
687 jp_milcent 131
		// Onlget formulaire PUBLICATION
858 jpm 132
		ongletsCollectionHerbier.add(creerOngletPublication());
687 jp_milcent 133
 
638 jp_milcent 134
		// Onlget formulaire DESCRIPTION
858 jpm 135
		ongletsCollectionHerbier.add(creerOngletDescription());
638 jp_milcent 136
 
137
		// Onlget formulaire CONTENU
858 jpm 138
		ongletsCollectionHerbier.add(creerOngletContenu());
638 jp_milcent 139
 
140
		// Onlget formulaire INVENTAIRE
858 jpm 141
		ongletsCollectionHerbier.add(creerOngletInventaire());
638 jp_milcent 142
 
143
		// Sélection de l'onglet par défaut
862 jpm 144
		ongletsCollectionHerbier.setSelection(generalOnglet);
638 jp_milcent 145
 
858 jpm 146
		return ongletsCollectionHerbier;
638 jp_milcent 147
	}
148
 
149
	private TabItem creerOngletGeneral() {
687 jp_milcent 150
		generalOnglet = new CollectionFormGeneral(this);
638 jp_milcent 151
		return generalOnglet;
152
	}
153
 
860 jpm 154
	private TabItem creerOngletPersonne() {
155
		personneOnglet = new CollectionFormPersonne(this);
156
		return personneOnglet;
638 jp_milcent 157
	}
158
 
687 jp_milcent 159
	private TabItem creerOngletPublication() {
720 jp_milcent 160
		publicationOnglet = new CollectionFormPublication(this);
687 jp_milcent 161
		return publicationOnglet;
162
	}
163
 
638 jp_milcent 164
	private TabItem creerOngletDescription() {
807 jpm 165
		descriptionOnglet = new CollectionFormDescription(this);
638 jp_milcent 166
		return descriptionOnglet;
167
	}
168
 
169
	private TabItem creerOngletContenu() {
858 jpm 170
		contenuOnglet = new CollectionFormContenu(this);
638 jp_milcent 171
		return contenuOnglet;
172
	}
173
 
174
	private TabItem creerOngletInventaire() {
862 jpm 175
		inventaireOnglet = new CollectionFormInventaire(this);
638 jp_milcent 176
		return inventaireOnglet;
177
	}
178
 
179
	public void rafraichir(Object nouvellesDonnees) {
858 jpm 180
		if (nouvellesDonnees instanceof Information) {
181
			Information info = (Information) nouvellesDonnees;
182
			rafraichirInformation(info);
183
		} else {
184
			GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
638 jp_milcent 185
		}
858 jpm 186
 
782 jpm 187
		controlerFermetureApresRafraichissement();
638 jp_milcent 188
	}
189
 
687 jp_milcent 190
	private void rafraichirInformation(Information info) {
638 jp_milcent 191
		if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
192
			GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);
193
		}
194
 
875 jpm 195
		if (info.getType().equals("modif_collection")) {
638 jp_milcent 196
			Info.display("Modification d'une collection", info.toString());
197
		} else if (info.getType().equals("selection_collection")) {
198
			Info.display("Modification d'une collection", info.toString());
199
			if (info.getDonnee(0) != null) {
200
				collection = (Collection) info.getDonnee(0);
201
			}
867 jpm 202
			peupler();
638 jp_milcent 203
			actualiserTitrePanneau();
875 jpm 204
		} else if (info.getType().equals("ajout_collection")) {
205
			if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {
206
				String collectionId = (String) info.getDonnee(0);
207
				Info.display("Ajout d'une collection", "La collection '"+collectionId+"' a bien été ajoutée");
208
 
209
				// Suite à la récupération de l'id de l'institution nouvellement ajoutée nous ajoutons les personnes et les publications liées
210
				personneOnglet.rafraichir(info);
211
				publicationOnglet.rafraichir(info);
212
			} else {
213
				Info.display("Ajout d'une Institution", info.toString());
214
			}
883 jpm 215
		} else if (info.getType().equals("liste_collection_a_personne")) {
216
			personneOnglet.rafraichir(info);
217
		} else if (info.getType().equals("liste_collection_a_publication")) {
218
			publicationOnglet.rafraichir(info);
638 jp_milcent 219
		}
220
	}
867 jpm 221
 
222
	private void peupler() {
223
		if (collection != null) {
224
			nomChp.setValue(collection.getNom());
225
			typesCollectionCombo.peupler(collection.getTypeNcd());
226
 
227
			peuplerOnglets();
228
		}
638 jp_milcent 229
	}
230
 
867 jpm 231
	private void peuplerOnglets() {
232
		generalOnglet.peupler();
233
	}
234
 
638 jp_milcent 235
	private void actualiserTitrePanneau() {
236
		String titre = i18nC.titreModifFormCollection();
237
		// Composition du titre
238
		titre += " - ID : "+collection.getId();
239
		panneauFormulaire.setHeading(titre);
240
	}
241
 
242
	@Override
775 jpm 243
	protected SelectionListener<ButtonEvent> creerEcouteurValidation() {
638 jp_milcent 244
		SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {
245
			@Override
246
			public void componentSelected(ButtonEvent ce) {
775 jpm 247
				String code = ((Button) ce.getComponent()).getData("code");
248
				if (code.equals(FormulaireBarreValidation.CODE_BOUTON_VALIDER)) {
782 jpm 249
					soumettreFormulaire();
638 jp_milcent 250
					clicBoutonvalidation = true;
775 jpm 251
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_APPLIQUER)) {
782 jpm 252
					soumettreFormulaire();
775 jpm 253
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_ANNULER)) {
638 jp_milcent 254
					mediateur.clicMenu(menuIdCourant);
775 jpm 255
				} else if (code.equals(FormulaireBarreValidation.CODE_BOUTON_REINITIALISER)) {
256
					reinitialiserFormulaire();
638 jp_milcent 257
				}
258
			}
259
		};
260
 
261
		return ecouteur;
262
	}
263
 
786 jpm 264
	protected boolean soumettreFormulaire() {
638 jp_milcent 265
		// Vérification de la validité des champs du formulaire
786 jpm 266
		boolean fomulaireValide = verifierFormulaire();
267
		if (fomulaireValide) {
638 jp_milcent 268
			// Collecte des données du formulaire
269
			Collection collection = collecterCollection();
270
 
271
			if (mode.equals(MODE_AJOUTER)) {
782 jpm 272
				mediateur.ajouterCollection(this, collection);
638 jp_milcent 273
			} else if (mode.equals(MODE_MODIFIER)) {
274
				if (collection == null) {
275
					Info.display("Modification d'une collection", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
276
				} else {
782 jpm 277
					mediateur.modifierCollection(this, collection);
638 jp_milcent 278
				}
279
			}
875 jpm 280
 
281
			soumettreOnglets();
638 jp_milcent 282
		}
786 jpm 283
		return fomulaireValide;
638 jp_milcent 284
	}
285
 
875 jpm 286
	private void soumettreOnglets() {
287
		personneOnglet.soumettre();
288
	}
289
 
775 jpm 290
	protected void reinitialiserFormulaire() {
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());
300
 
867 jpm 301
		this.collecter();
302
		collecterOnglets();
638 jp_milcent 303
 
304
		Collection collectionARetourner = null;
305
		if (!collectionCollectee.comparer(collection)) {
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();
867 jpm 319
	}
320
 
787 jpm 321
	protected boolean verifierFormulaire() {
875 jpm 322
		ArrayList<String> messages = new ArrayList<String>();
323
 
324
		// Vérification des infos sur le nom de la collection
325
		if (nomChp.getValue() == null || nomChp.getValue().equals("") || collection.getNom().equals("")) {
326
			messages.add("Veuillez donner un nom à la collection.");
327
		}
328
 
329
		// Vérification des infos sur le type de collection
330
		if (typesCollectionCombo.getValue() == null || typesCollectionCombo.getValue().equals("") || collection.getIdProjet().equals("")) {
331
			messages.add("Veuillez sélectionner un type pour la collection.");
332
		}
333
 
334
		messages.addAll(verifierOnglets());
335
 
336
		// Affichage des messages d'alerte
337
		if (messages.size() != 0) {
338
			String[] tableauDesMessages = {};
339
			tableauDesMessages = messages.toArray(tableauDesMessages);
340
			MessageBox.alert("Erreurs de saisies", UtilArray.implode(tableauDesMessages, "<br />"), null);
341
			return false;
342
		}
638 jp_milcent 343
		return true;
344
	}
875 jpm 345
 
346
	private ArrayList<String> verifierOnglets() {
347
		ArrayList<String> messages = new ArrayList<String>();
348
		messages.addAll(generalOnglet.verifier());
349
		messages.addAll(personneOnglet.verifier());
350
		return messages;
351
	}
638 jp_milcent 352
}