Subversion Repositories eFlore/Applications.coel

Rev

Rev 638 | Rev 687 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
638 jp_milcent 1
package org.tela_botanica.client.vues;
2
 
3
import java.util.HashMap;
4
import java.util.List;
5
 
6
import org.tela_botanica.client.Mediateur;
7
import org.tela_botanica.client.interfaces.Rafraichissable;
8
import org.tela_botanica.client.modeles.Collection;
9
import org.tela_botanica.client.modeles.Information;
10
import org.tela_botanica.client.modeles.MenuApplicationId;
11
import org.tela_botanica.client.modeles.Structure;
12
import org.tela_botanica.client.modeles.StructureConservation;
13
import org.tela_botanica.client.modeles.StructureValorisation;
14
import org.tela_botanica.client.modeles.Valeur;
15
import org.tela_botanica.client.modeles.ValeurListe;
16
 
17
import com.extjs.gxt.ui.client.event.ButtonEvent;
18
import com.extjs.gxt.ui.client.event.ComponentEvent;
19
import com.extjs.gxt.ui.client.event.Events;
20
import com.extjs.gxt.ui.client.event.Listener;
21
import com.extjs.gxt.ui.client.event.SelectionListener;
22
import com.extjs.gxt.ui.client.widget.Info;
23
import com.extjs.gxt.ui.client.widget.TabItem;
24
import com.extjs.gxt.ui.client.widget.TabPanel;
25
import com.extjs.gxt.ui.client.widget.form.FieldSet;
26
import com.extjs.gxt.ui.client.widget.form.HiddenField;
27
import com.extjs.gxt.ui.client.widget.form.Radio;
648 jp_milcent 28
import com.extjs.gxt.ui.client.widget.form.TextField;
638 jp_milcent 29
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
648 jp_milcent 30
import com.extjs.gxt.ui.client.widget.layout.FormData;
638 jp_milcent 31
import com.google.gwt.core.client.GWT;
32
import com.google.gwt.user.client.ui.Widget;
33
 
34
public class CollectionForm extends Formulaire implements Rafraichissable {
35
 
36
	private Collection collection = null;
37
	private Collection collectionCollectee = null;
38
 
39
	private HashMap<String, Widget>champs = new HashMap<String, Widget>();
40
 
41
	private TabItem generalOnglet = null;
42
	private TabItem auteurOnglet = null;
43
	private TabItem descriptionOnglet = null;
44
	private TabItem contenuOnglet = null;
45
	private TabItem documentOnglet = null;
46
	private TabItem inventaireOnglet = null;
47
 
48
	public CollectionForm(Mediateur mediateurCourrant, String modeDeCreation) {
648 jp_milcent 49
		initialiserFormulaire(mediateurCourrant, modeDeCreation, MenuApplicationId.COLLECTION);
638 jp_milcent 50
	}
51
 
52
	protected void creerOnglets() {
53
		onglets = new TabPanel();
54
		// NOTE : pour faire apparaître les scrollBar il faut définir la hauteur du panneau d'onglets à 100% (autoHeight ne semble pas fonctionner)
55
		onglets.setHeight("100%");
56
 
57
		// Onlget formulaire GENERAL
58
		onglets.add(creerOngletGeneral());
59
 
60
		// Onlget formulaire AUTEUR
61
		onglets.add(creerOngletAuteur());
62
 
63
		// Onlget formulaire DESCRIPTION
64
		onglets.add(creerOngletDescription());
65
 
66
		// Onlget formulaire CONTENU
67
		onglets.add(creerOngletContenu());
68
 
69
		// Onlget formulaire DOCUMENT
70
		onglets.add(creerOngletDocument());
71
 
72
		// Onlget formulaire INVENTAIRE
73
		onglets.add(creerOngletInventaire());
74
 
75
		// Sélection de l'onglet par défaut
76
		//onglets.setSelection(personnelOnglet);
77
 
78
		// Ajout des onglets au formulaire général
79
		panneauFormulaire.add(onglets);
80
	}
81
 
82
	private TabItem creerOngletGeneral() {
83
		generalOnglet = creerOnglet(i18nC.collectionGeneral(), "general");
84
		generalOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
85
			public void handleEvent(ComponentEvent be) {
86
				//peuplerOngletGeneral();
87
				generalOnglet.layout();
88
			}
89
		});
90
 
91
		//+-----------------------------------------------------------------------------------------------------------+
92
		// Champs cachés
93
		HiddenField<String> idCollectionChp = new HiddenField<String>();
94
		champs.put("idCollectionChp", idCollectionChp);
648 jp_milcent 95
 
638 jp_milcent 96
		//+-----------------------------------------------------------------------------------------------------------+
97
		// Fieldset ADMINISTRATIF
648 jp_milcent 98
		FieldSet administratifFieldSet = new FieldSet();
99
		administratifFieldSet.setHeading(i18nC.collectionGeneralTitre());
100
		administratifFieldSet.setCollapsible(true);
101
		administratifFieldSet.setLayout(creerFormLayout(120, LabelAlign.LEFT));
638 jp_milcent 102
 
648 jp_milcent 103
		TextField<String> nomChp = new TextField<String>();
104
		nomChp.setTabIndex(tabIndex++);
105
		nomChp.setFieldLabel(i18nC.nomCollection());
106
		nomChp.setAllowBlank(false);
107
		nomChp.getMessages().setBlankText(i18nC.champObligatoire());
108
		administratifFieldSet.add(nomChp, new FormData(450, 0));
638 jp_milcent 109
 
648 jp_milcent 110
		generalOnglet.add(administratifFieldSet);
111
 
112
		//+-----------------------------------------------------------------------------------------------------------+
113
		// Fieldset DESCRIPTION
114
		FieldSet descriptionFieldSet = new FieldSet();
115
		descriptionFieldSet.setHeading(i18nC.collectionDescriptionTitre());
116
		descriptionFieldSet.setCollapsible(true);
117
		descriptionFieldSet.setLayout(creerFormLayout(120, LabelAlign.LEFT));
118
 
119
		generalOnglet.add(descriptionFieldSet);
120
 
121
		//+-----------------------------------------------------------------------------------------------------------+
122
		// Retour
638 jp_milcent 123
		return generalOnglet;
124
	}
125
 
126
	private TabItem creerOngletAuteur() {
127
		auteurOnglet = creerOnglet(i18nC.collectionAuteur(), "auteur");
128
		auteurOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
129
			public void handleEvent(ComponentEvent be) {
130
				//peuplerOngletAuteur();
131
				auteurOnglet.layout();
132
			}
133
		});
134
 
135
		return auteurOnglet;
136
	}
137
 
138
	private TabItem creerOngletDescription() {
139
		descriptionOnglet = creerOnglet(i18nC.collectionDescription(), "description");
140
		descriptionOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
141
			public void handleEvent(ComponentEvent be) {
142
				//peuplerOngletDescription();
143
				descriptionOnglet.layout();
144
			}
145
		});
146
 
147
		return descriptionOnglet;
148
	}
149
 
150
	private TabItem creerOngletContenu() {
151
		contenuOnglet = creerOnglet(i18nC.collectionDescription(), "contenu");
152
		contenuOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
153
			public void handleEvent(ComponentEvent be) {
154
				//peuplerOngletContenu();
155
				contenuOnglet.layout();
156
			}
157
		});
158
 
159
		return contenuOnglet;
160
	}
161
 
162
	private TabItem creerOngletDocument() {
163
		documentOnglet = creerOnglet(i18nC.collectionDescription(), "document");
164
		documentOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
165
			public void handleEvent(ComponentEvent be) {
166
				//peuplerOngletDocument();
167
				documentOnglet.layout();
168
			}
169
		});
170
 
171
		return documentOnglet;
172
	}
173
 
174
	private TabItem creerOngletInventaire() {
175
		inventaireOnglet = creerOnglet(i18nC.collectionDescription(), "inventaire");
176
		inventaireOnglet.addListener(Events.Select, new Listener<ComponentEvent>() {
177
			public void handleEvent(ComponentEvent be) {
178
				//peuplerOngletInventaire();
179
				inventaireOnglet.layout();
180
			}
181
		});
182
 
183
		return inventaireOnglet;
184
	}
185
 
186
	public void rafraichir(Object nouvellesDonnees) {
187
		try {
188
			if (nouvellesDonnees instanceof Information) {
189
				Information info = (Information) nouvellesDonnees;
190
				rafraichirInformation(info);
191
			} else if (nouvellesDonnees instanceof ValeurListe) {
192
				ValeurListe listeValeurs = (ValeurListe) nouvellesDonnees;
193
				rafraichirValeurListe(listeValeurs);
194
			} else {
195
				GWT.log(Mediateur.i18nM.erreurRafraichir(nouvellesDonnees.getClass(), this.getClass()), null);
196
			}
197
		} catch (Exception e) {
198
			GWT.log("rafraichir()", e);
199
		}
200
		verifierApresRafraichissement();
201
	}
202
 
203
	public void rafraichirInformation(Information info) {
204
		if (info.getMessages() != null && !info.getMessages().toString().equals("[]")) {
205
			GWT.log("MESSAGES:\n"+info.getMessages().toString(), null);
206
		}
207
 
208
		if (info.getType().equals("modif_structure")) {
209
			Info.display("Modification d'une collection", info.toString());
210
		} else if (info.getType().equals("selection_collection")) {
211
			Info.display("Modification d'une collection", info.toString());
212
			if (info.getDonnee(0) != null) {
213
				collection = (Collection) info.getDonnee(0);
214
			}
215
			actualiserPeuplementOnglet();
216
			actualiserTitrePanneau();
217
		}
218
	}
219
 
220
	public void rafraichirValeurListe(ValeurListe listeValeurs) {
221
		List<Valeur> liste = listeValeurs.toList();
222
 
223
		// Test pour savoir si la liste contient des éléments
224
		if (liste.size() > 0) {
225
 
226
		}
227
	}
228
 
229
	private void actualiserPeuplementOnglet() {
230
		onglets.setSelection(onglets.getSelectedItem());
231
	}
232
 
233
	private void actualiserTitrePanneau() {
234
		String titre = i18nC.titreModifFormCollection();
235
		// Composition du titre
236
		titre += " - ID : "+collection.getId();
237
		panneauFormulaire.setHeading(titre);
238
	}
239
 
240
	@Override
241
	protected SelectionListener<ButtonEvent> creerEcouteurBoutonFormulaire(final String code) {
242
		SelectionListener<ButtonEvent> ecouteur = new SelectionListener<ButtonEvent>() {
243
			@Override
244
			public void componentSelected(ButtonEvent ce) {
245
				if (code.equals(Formulaire.CODE_BOUTON_VALIDER)) {
246
					soumettreFormulaire();
247
					clicBoutonvalidation = true;
248
				} else if (code.equals(Formulaire.CODE_BOUTON_APPLIQUER)) {
249
					soumettreFormulaire();
250
				} else if (code.equals(Formulaire.CODE_BOUTON_ANNULER)) {
251
					mediateur.clicMenu(menuIdCourant);
252
				} else if (code.equals(Formulaire.CODE_BOUTON_REINITIALISER)) {
253
					if (mode.equals(StructureForm.MODE_MODIFIER)) {
254
						mediateur.afficherFormCollection(collection.getId());
255
					} else {
256
						mediateur.afficherFormCollection(null);
257
					}
258
				}
259
			}
260
		};
261
 
262
		return ecouteur;
263
	}
264
 
265
	protected void soumettreFormulaire() {
266
		// Vérification de la validité des champs du formulaire
267
		if (verifierFormulaire()) {
268
			// Collecte des données du formulaire
269
			Collection collection = collecterCollection();
270
 
271
			if (mode.equals(MODE_AJOUTER)) {
272
				mediateur.ajouterCollection(this, collection);
273
			} else if (mode.equals(MODE_MODIFIER)) {
274
				if (collection == null) {
275
					Info.display("Modification d'une collection", "Rien n'a été enregistré car le formulaire n'a pas été modifié.");
276
				} else {
277
					mediateur.modifierCollection(this, collection);
278
				}
279
			}
280
		}
281
	}
282
 
283
	private Collection collecterCollection() {
284
		collectionCollectee = (Collection) collection.cloner(new Collection());
285
 
286
		collecterOngletGeneral();
287
 
288
		Collection collectionARetourner = null;
289
		if (!collectionCollectee.comparer(collection)) {
290
			collectionARetourner = collection = collectionCollectee;
291
		}
292
		return collectionARetourner;
293
	}
294
 
295
	private void collecterOngletGeneral() {
296
		if (generalOnglet.getData("acces").equals(true)) {
297
 
298
		}
299
	}
300
 
301
	private Boolean verifierFormulaire() {
302
		return true;
303
	}
304
 
305
	@Override
306
	protected void afficherChampSupplementaire(Radio radioBtn) {
307
		// TODO Auto-generated method stub
308
 
309
	}
310
}