Subversion Repositories eFlore/Applications.coel

Rev

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