Subversion Repositories eFlore/Applications.coel

Rev

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