Subversion Repositories eFlore/Applications.coel

Rev

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