Subversion Repositories eFlore/Applications.coel

Rev

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