Subversion Repositories eFlore/Applications.coel

Rev

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