Subversion Repositories eFlore/Applications.coel

Rev

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