Subversion Repositories eFlore/Applications.coel

Rev

Rev 949 | Rev 968 | 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();
948 jpm 229
		descriptionOnglet.peupler();
954 jpm 230
		contenuOnglet.peupler();
231
		inventaireOnglet.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());
954 jpm 278
 
867 jpm 279
		this.collecter();
280
		collecterOnglets();
954 jpm 281
 
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();
954 jpm 299
		contenuOnglet.collecter();
300
		inventaireOnglet.collecter();
867 jpm 301
	}
302
 
934 jpm 303
	public boolean verifierFormulaire() {
875 jpm 304
		ArrayList<String> messages = new ArrayList<String>();
305
 
306
		// Vérification des infos sur le nom de la collection
307
		if (nomChp.getValue() == null || nomChp.getValue().equals("") || collection.getNom().equals("")) {
308
			messages.add("Veuillez donner un nom à la collection.");
309
		}
310
 
311
		// Vérification des infos sur le type de collection
312
		if (typesCollectionCombo.getValue() == null || typesCollectionCombo.getValue().equals("") || collection.getIdProjet().equals("")) {
313
			messages.add("Veuillez sélectionner un type pour la collection.");
314
		}
315
 
316
		messages.addAll(verifierOnglets());
317
 
318
		// Affichage des messages d'alerte
319
		if (messages.size() != 0) {
320
			String[] tableauDesMessages = {};
321
			tableauDesMessages = messages.toArray(tableauDesMessages);
322
			MessageBox.alert("Erreurs de saisies", UtilArray.implode(tableauDesMessages, "<br />"), null);
323
			return false;
324
		}
638 jp_milcent 325
		return true;
326
	}
875 jpm 327
 
328
	private ArrayList<String> verifierOnglets() {
329
		ArrayList<String> messages = new ArrayList<String>();
330
		messages.addAll(generalOnglet.verifier());
331
		messages.addAll(personneOnglet.verifier());
332
		return messages;
333
	}
638 jp_milcent 334
}