Subversion Repositories eFlore/Applications.coel

Rev

Rev 948 | Rev 954 | 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;
948 jpm 12
import org.tela_botanica.client.modeles.collection.CollectionBotanique;
949 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);
78
		nomChp.getMessages().setBlankText(i18nC.champObligatoire());
79
		principalFieldSet.add(nomChp, new FormData(450, 0));
80
 
81
		typesCollectionCombo = new ChampComboBoxListeValeurs(i18nC.typeCollectionNcd(), "typeCollectionNcd", tabIndex++);
867 jpm 82
		typesCollectionCombo.peupler(Valeur.COLLECTION_NCD_HERBIER);
858 jpm 83
		typesCollectionCombo.addListener(Events.Select, new Listener<BaseEvent>() {
84
			@Override
85
			public void handleEvent(BaseEvent be) {
86
				Valeur valeur = typesCollectionCombo.getValue();
87
				panneauFormulaire.remove(onglets);
88
				mediateur.activerChargement("");
89
				if (valeur != null && valeur.getId().equals(Valeur.COLLECTION_NCD_HERBIER)) {
90
					onglets = creerOngletsHerbier();
91
					panneauFormulaire.add(onglets);
92
				} else {
93
					onglets = creerOngletsDefaut();
94
					panneauFormulaire.add(onglets);
95
				}
96
				mediateur.desactiverChargement();
97
				panneauFormulaire.layout();
98
			}
99
		});
100
		principalFieldSet.add(typesCollectionCombo, new FormData(150, 0));
101
		typesCollectionCombo.fireEvent(Events.Select);
102
 
103
		panneauFormulaire.setTopComponent(principalFieldSet);
104
	}
105
 
106
	protected TabPanel creerOngletsDefaut() {
107
		TabPanel ongletsCollectionDefaut = new TabPanel();
108
 
109
		// Onlget formulaire GENERAL
110
		ongletsCollectionDefaut.add(creerOngletGeneral());
111
 
112
		// Onlget formulaire AUTEUR
860 jpm 113
		ongletsCollectionDefaut.add(creerOngletPersonne());
858 jpm 114
 
115
		return ongletsCollectionDefaut;
116
	}
117
 
118
	protected TabPanel creerOngletsHerbier() {
119
		TabPanel ongletsCollectionHerbier = new TabPanel();
638 jp_milcent 120
		// 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 121
		ongletsCollectionHerbier.setHeight("100%");
638 jp_milcent 122
 
123
		// Onlget formulaire GENERAL
858 jpm 124
		ongletsCollectionHerbier.add(creerOngletGeneral());
638 jp_milcent 125
 
126
		// Onlget formulaire AUTEUR
860 jpm 127
		ongletsCollectionHerbier.add(creerOngletPersonne());
638 jp_milcent 128
 
687 jp_milcent 129
		// Onlget formulaire PUBLICATION
858 jpm 130
		ongletsCollectionHerbier.add(creerOngletPublication());
687 jp_milcent 131
 
638 jp_milcent 132
		// Onlget formulaire DESCRIPTION
858 jpm 133
		ongletsCollectionHerbier.add(creerOngletDescription());
638 jp_milcent 134
 
135
		// Onlget formulaire CONTENU
858 jpm 136
		ongletsCollectionHerbier.add(creerOngletContenu());
638 jp_milcent 137
 
138
		// Onlget formulaire INVENTAIRE
858 jpm 139
		ongletsCollectionHerbier.add(creerOngletInventaire());
638 jp_milcent 140
 
141
		// Sélection de l'onglet par défaut
862 jpm 142
		ongletsCollectionHerbier.setSelection(generalOnglet);
638 jp_milcent 143
 
858 jpm 144
		return ongletsCollectionHerbier;
638 jp_milcent 145
	}
146
 
147
	private TabItem creerOngletGeneral() {
687 jp_milcent 148
		generalOnglet = new CollectionFormGeneral(this);
638 jp_milcent 149
		return generalOnglet;
150
	}
151
 
860 jpm 152
	private TabItem creerOngletPersonne() {
153
		personneOnglet = new CollectionFormPersonne(this);
154
		return personneOnglet;
638 jp_milcent 155
	}
156
 
687 jp_milcent 157
	private TabItem creerOngletPublication() {
720 jp_milcent 158
		publicationOnglet = new CollectionFormPublication(this);
687 jp_milcent 159
		return publicationOnglet;
160
	}
161
 
638 jp_milcent 162
	private TabItem creerOngletDescription() {
807 jpm 163
		descriptionOnglet = new CollectionFormDescription(this);
638 jp_milcent 164
		return descriptionOnglet;
165
	}
166
 
167
	private TabItem creerOngletContenu() {
858 jpm 168
		contenuOnglet = new CollectionFormContenu(this);
638 jp_milcent 169
		return contenuOnglet;
170
	}
171
 
172
	private TabItem creerOngletInventaire() {
862 jpm 173
		inventaireOnglet = new CollectionFormInventaire(this);
638 jp_milcent 174
		return inventaireOnglet;
175
	}
176
 
177
	public void rafraichir(Object nouvellesDonnees) {
858 jpm 178
		if (nouvellesDonnees instanceof Information) {
179
			Information info = (Information) nouvellesDonnees;
180
			rafraichirInformation(info);
181
		} else {
182
			GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
638 jp_milcent 183
		}
858 jpm 184
 
782 jpm 185
		controlerFermetureApresRafraichissement();
638 jp_milcent 186
	}
187
 
687 jp_milcent 188
	private void rafraichirInformation(Information info) {
638 jp_milcent 189
		if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
190
			GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);
191
		}
192
 
875 jpm 193
		if (info.getType().equals("modif_collection")) {
638 jp_milcent 194
			Info.display("Modification d'une collection", info.toString());
195
		} else if (info.getType().equals("selection_collection")) {
196
			Info.display("Modification d'une collection", info.toString());
197
			if (info.getDonnee(0) != null) {
198
				collection = (Collection) info.getDonnee(0);
199
			}
867 jpm 200
			peupler();
638 jp_milcent 201
			actualiserTitrePanneau();
875 jpm 202
		} else if (info.getType().equals("ajout_collection")) {
203
			if (info.getDonnee(0) != null && info.getDonnee(0) instanceof String) {
204
				String collectionId = (String) info.getDonnee(0);
205
				Info.display("Ajout d'une collection", "La collection '"+collectionId+"' a bien été ajoutée");
206
 
207
				// Suite à la récupération de l'id de l'institution nouvellement ajoutée nous ajoutons les personnes et les publications liées
208
				personneOnglet.rafraichir(info);
209
				publicationOnglet.rafraichir(info);
210
			} else {
211
				Info.display("Ajout d'une Institution", info.toString());
212
			}
883 jpm 213
		} else if (info.getType().equals("liste_collection_a_personne")) {
214
			personneOnglet.rafraichir(info);
215
		} else if (info.getType().equals("liste_collection_a_publication")) {
216
			publicationOnglet.rafraichir(info);
638 jp_milcent 217
		}
218
	}
867 jpm 219
 
220
	private void peupler() {
221
		if (collection != null) {
222
			nomChp.setValue(collection.getNom());
223
			typesCollectionCombo.peupler(collection.getTypeNcd());
224
 
225
			peuplerOnglets();
226
		}
638 jp_milcent 227
	}
228
 
867 jpm 229
	private void peuplerOnglets() {
230
		generalOnglet.peupler();
948 jpm 231
		descriptionOnglet.peupler();
867 jpm 232
	}
233
 
638 jp_milcent 234
	private void actualiserTitrePanneau() {
235
		String titre = i18nC.titreModifFormCollection();
236
		// Composition du titre
237
		titre += " - ID : "+collection.getId();
238
		panneauFormulaire.setHeading(titre);
239
	}
240
 
934 jpm 241
	public boolean soumettreFormulaire() {
638 jp_milcent 242
		// Vérification de la validité des champs du formulaire
948 jpm 243
		boolean formulaireValide = verifierFormulaire();
244
		if (formulaireValide) {
638 jp_milcent 245
			// Collecte des données du formulaire
949 jpm 246
			Collection collectionAEnregistrer = collecterCollection();
247
 
638 jp_milcent 248
			if (mode.equals(MODE_AJOUTER)) {
949 jpm 249
				mediateur.ajouterCollection(this, collectionAEnregistrer);
638 jp_milcent 250
			} else if (mode.equals(MODE_MODIFIER)) {
949 jpm 251
				if (collectionAEnregistrer == null) {
638 jp_milcent 252
					Info.display("Modification d'une collection", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
253
				} else {
949 jpm 254
					mediateur.modifierCollection(this, collectionAEnregistrer);
638 jp_milcent 255
				}
256
			}
875 jpm 257
 
258
			soumettreOnglets();
638 jp_milcent 259
		}
948 jpm 260
		return formulaireValide;
638 jp_milcent 261
	}
262
 
875 jpm 263
	private void soumettreOnglets() {
264
		personneOnglet.soumettre();
907 jpm 265
		publicationOnglet.soumettre();
875 jpm 266
	}
267
 
934 jpm 268
	public void reinitialiserFormulaire() {
775 jpm 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());
949 jpm 278
		//Debug.log(collectionCollectee.toString());
867 jpm 279
		this.collecter();
280
		collecterOnglets();
949 jpm 281
		//Debug.log(collectionCollectee.toString());
638 jp_milcent 282
		Collection collectionARetourner = null;
949 jpm 283
		if (!collectionCollectee.comparer(collection) || !collectionCollectee.getBotanique().comparer(collection.getBotanique())) {
638 jp_milcent 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();
883 jpm 296
		personneOnglet.collecter();
907 jpm 297
		publicationOnglet.collecter();
948 jpm 298
		descriptionOnglet.collecter();
867 jpm 299
	}
300
 
934 jpm 301
	public boolean verifierFormulaire() {
875 jpm 302
		ArrayList<String> messages = new ArrayList<String>();
303
 
304
		// Vérification des infos sur le nom de la collection
305
		if (nomChp.getValue() == null || nomChp.getValue().equals("") || collection.getNom().equals("")) {
306
			messages.add("Veuillez donner un nom à la collection.");
307
		}
308
 
309
		// Vérification des infos sur le type de collection
310
		if (typesCollectionCombo.getValue() == null || typesCollectionCombo.getValue().equals("") || collection.getIdProjet().equals("")) {
311
			messages.add("Veuillez sélectionner un type pour la collection.");
312
		}
313
 
314
		messages.addAll(verifierOnglets());
315
 
316
		// Affichage des messages d'alerte
317
		if (messages.size() != 0) {
318
			String[] tableauDesMessages = {};
319
			tableauDesMessages = messages.toArray(tableauDesMessages);
320
			MessageBox.alert("Erreurs de saisies", UtilArray.implode(tableauDesMessages, "<br />"), null);
321
			return false;
322
		}
638 jp_milcent 323
		return true;
324
	}
875 jpm 325
 
326
	private ArrayList<String> verifierOnglets() {
327
		ArrayList<String> messages = new ArrayList<String>();
328
		messages.addAll(generalOnglet.verifier());
329
		messages.addAll(personneOnglet.verifier());
330
		return messages;
331
	}
638 jp_milcent 332
}