Subversion Repositories eFlore/Applications.coel

Rev

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

Rev Author Line No. Line
127 gduche 1
package org.tela_botanica.client.vues;
2
 
276 gduche 3
import java.util.HashMap;
4
 
5
import org.tela_botanica.client.ComposantClass;
6
import org.tela_botanica.client.Mediateur;
7
import org.tela_botanica.client.RegistreId;
127 gduche 8
import org.tela_botanica.client.interfaces.Rafraichissable;
280 gduche 9
import org.tela_botanica.client.modeles.InterneValeur;
10
import org.tela_botanica.client.modeles.Personne;
11
import org.tela_botanica.client.modeles.Valeur;
127 gduche 12
 
276 gduche 13
 
14
import com.extjs.gxt.ui.client.Registry;
15
import com.extjs.gxt.ui.client.Style.HorizontalAlignment;
16
import com.extjs.gxt.ui.client.event.ComponentEvent;
17
import com.extjs.gxt.ui.client.event.KeyListener;
280 gduche 18
import com.extjs.gxt.ui.client.event.SelectionChangedEvent;
19
import com.extjs.gxt.ui.client.event.SelectionChangedListener;
276 gduche 20
import com.extjs.gxt.ui.client.event.SelectionListener;
280 gduche 21
import com.extjs.gxt.ui.client.store.ListStore;
22
import com.extjs.gxt.ui.client.store.Store;
276 gduche 23
import com.extjs.gxt.ui.client.widget.Container;
24
import com.extjs.gxt.ui.client.widget.ContentPanel;
280 gduche 25
import com.extjs.gxt.ui.client.widget.DatePicker;
127 gduche 26
import com.extjs.gxt.ui.client.widget.LayoutContainer;
276 gduche 27
import com.extjs.gxt.ui.client.widget.TabItem;
28
import com.extjs.gxt.ui.client.widget.TabPanel;
280 gduche 29
import com.extjs.gxt.ui.client.widget.form.ComboBox;
30
import com.extjs.gxt.ui.client.widget.form.DateField;
276 gduche 31
import com.extjs.gxt.ui.client.widget.form.FieldSet;
32
import com.extjs.gxt.ui.client.widget.form.LabelField;
33
import com.extjs.gxt.ui.client.widget.form.TextField;
280 gduche 34
import com.extjs.gxt.ui.client.widget.form.ComboBox.TriggerAction;
276 gduche 35
import com.extjs.gxt.ui.client.widget.form.FormPanel.LabelAlign;
36
import com.extjs.gxt.ui.client.widget.layout.ColumnData;
37
import com.extjs.gxt.ui.client.widget.layout.ColumnLayout;
38
import com.extjs.gxt.ui.client.widget.layout.FitLayout;
39
import com.extjs.gxt.ui.client.widget.layout.FlowLayout;
40
import com.extjs.gxt.ui.client.widget.layout.FormLayout;
41
import com.extjs.gxt.ui.client.widget.toolbar.TextToolItem;
42
import com.extjs.gxt.ui.client.widget.toolbar.ToolBar;
127 gduche 43
 
276 gduche 44
import com.google.gwt.user.client.ui.Panel;
45
import com.google.gwt.user.client.ui.Widget;
127 gduche 46
 
47
 
276 gduche 48
 
49
public class FormPersonneVue extends ContentPanel implements Rafraichissable {
50
 
51
 
52
	/*--------------------------------------------------------------------------------------
53
	 * 		VARIABLES
54
	 * -------------------------------------------------------------------------------------
55
	 */
56
 
57
	private TabItem tiIdentite, tiAdresses, tiInfosNat;
58
 
59
 
60
	/*--------------------------------------------------------------------------------------
61
	 * 		CONSTRUCTEUR
62
	 * -------------------------------------------------------------------------------------
63
	 */
64
	/**
65
	 * Constructeur du panneau
66
	 *
67
	 * Initialise le panneau et ajoute une barre d'outils à deux boutons (réinitialiser le
68
	 * formulaire et annuler la saisie).
69
	 *
70
	 * */
71
	public FormPersonneVue() {
72
 
73
		initialiserPanneau(this);
74
 
75
		ToolBar barreOutils = new ToolBar();
76
 
77
		ajouterBoutonEnregistrer(barreOutils);
78
		ajouterBoutonReinitialiser(barreOutils);
79
		ajouterBoutonAnnuler(barreOutils);
80
 
81
		setTopComponent(barreOutils);
82
 
83
		initialiserOnglets();
84
 
85
		creerComposantsIdentite();
280 gduche 86
 
276 gduche 87
	}
88
 
89
 
90
	/*---------------------------------------------------------------------------------------
91
	 * 		SOUS-METHODES
92
	 * --------------------------------------------------------------------------------------
93
	 */
94
	/**
95
	 * Inialise le panneau donné
96
	 *
97
	 * @param contentPanel le panneau à initialiser
98
	 * */
99
	public void initialiserPanneau(ContentPanel contentPanel)	{
100
 
101
		contentPanel.setLayout(new FitLayout());
102
		contentPanel.setIconStyle("icone-form-ajouter");
103
		contentPanel.setCollapsible(false);
104
		contentPanel.setHeading("Ajouter une personne");
105
		contentPanel.setButtonAlign(HorizontalAlignment.CENTER);
106
		contentPanel.setLayout(new FormLayout());
107
	}
108
 
109
	/**
110
	 * Crée les onglets identité, adresse et informations naturaliste
111
	 *
112
	 * */
113
	public void initialiserOnglets()	{
114
		//TabPanel
115
		TabPanel formulaireOnglets = new TabPanel();
116
 
117
		//Tab 1 : identite
118
		tiIdentite = new TabItem("Identité");
119
		tiIdentite.setLayout(new FormLayout());
120
		formulaireOnglets.add(tiIdentite);
121
 
122
 
123
		//Tab 2 : Adresse
124
		tiAdresses = new TabItem("Adresse");
125
		tiAdresses.setLayout(new FlowLayout());
126
		formulaireOnglets.add(tiAdresses);
127
 
128
		//Tab 3 : Infos Naturalistes
129
		tiInfosNat = new TabItem("Informations Naturalistes");
130
		tiInfosNat.setLayout(new FormLayout());
131
		formulaireOnglets.add(tiInfosNat);
132
 
133
		add(formulaireOnglets);
134
	}
135
 
136
	/**
137
	 * Crée les widgets pour l'onglet identité
138
	 *
139
	 * */
140
 
141
	//hmIdentite référence par une chaine de caractère tous les composants de l'onglet Identite
142
	private HashMap<String, Widget>hmIdentite = new HashMap<String, Widget>();
143
 
144
	public void creerComposantsIdentite()	{
145
 
146
			// Gestion de l'affichage en colonnes
147
			// On crée 3 Layout container : un principal, un pour la colonne de gauche, un pour la colonne de droite
148
 
149
			// Gauche
150
			LayoutContainer left = new LayoutContainer();
151
			left.setLayout(new FormLayout());
152
 
153
			// Droite
154
			LayoutContainer right = new LayoutContainer();
155
			right.setLayout(new FormLayout());
156
 
157
			// Principal
158
			LayoutContainer main = new LayoutContainer();
159
			main.setLayout(new ColumnLayout());
160
 
161
			// Ajout au principal
162
			main.add(left, new ColumnData(.5));
163
			main.add(right, new ColumnData(.5));
164
 
165
 
166
			// Création des champs
167
 
168
			//FormLayout sera utilisé à plusieurs reprises
169
			FormLayout formLayout = new FormLayout();
170
 
171
			FieldSet fsNoms = new FieldSet();
172
			fsNoms.setHeading("Noms");
173
 
174
			formLayout.setLabelAlign(LabelAlign.LEFT);
175
			fsNoms.setLayout(formLayout);
176
 
177
			// Nom complet
178
			// Affiché que si valeurs saisies
179
			LabelField nomComplet = new LabelField();
180
			nomComplet.setFieldLabel("Nom complet:");
181
			nomComplet.hide();
182
			fsNoms.add(nomComplet);
183
 
184
			hmIdentite.put("nomComplet", nomComplet);
185
 
186
			//Préfixe
280 gduche 187
			ComboBox<Valeur> cbPrefix = new ComboBox<Valeur>();
188
			ListStore<Valeur> storePrefixe = new ListStore<Valeur>();
189
			cbPrefix.setStore(storePrefixe);
190
			cbPrefix.setFieldLabel("Prefix");
191
			fsNoms.add(cbPrefix);
276 gduche 192
 
280 gduche 193
			hmIdentite.put("cbPrefix", cbPrefix);
276 gduche 194
 
195
			//Prénom
196
			TextField<String> tfPrenom = new TextField<String>();
197
			tfPrenom.setFieldLabel("Prénom");
198
			fsNoms.add(tfPrenom);
199
 
200
			hmIdentite.put("tfPrenom", tfPrenom);
201
 
202
			//Nom
203
			TextField<String> tfNom = new TextField<String>();
204
			tfNom.setFieldLabel("Nom");
205
			fsNoms.add(tfNom);
206
 
207
			hmIdentite.put("tfNom", tfNom);
208
 
280 gduche 209
			//Préfixe
210
			ComboBox<Valeur> cbSuffixe = new ComboBox<Valeur>();
211
			ListStore<Valeur> storeSuffixe = new ListStore<Valeur>();
212
			cbSuffixe.setStore(storeSuffixe);
213
			cbSuffixe.setFieldLabel("Suffixe");
214
			fsNoms.add(cbSuffixe);
276 gduche 215
 
280 gduche 216
			hmIdentite.put("cbSuffixe", cbSuffixe);
276 gduche 217
 
218
			// Nom : autre
219
			TextField<String> tfNomAutre = new TextField();
220
			tfNomAutre.setFieldLabel("Autres noms");
221
			fsNoms.add(tfNomAutre);
222
 
223
			hmIdentite.put("tfNomAutre", tfNomAutre);
224
 
225
			//Abréviation
226
			TextField<String> tfAbreviation = new TextField<String>();
227
			tfAbreviation.setFieldLabel("Abréviation");
228
			fsNoms.add(tfAbreviation);
229
 
230
			hmIdentite.put("tfAbreviation", tfAbreviation);
231
 
232
			//Abréviation autres
233
			TextField<String> tfAbreviationAutre = new TextField<String>();
234
			tfAbreviationAutre.setFieldLabel("Autres Abrév.");
235
			fsNoms.add(tfAbreviationAutre);
236
 
237
			hmIdentite.put("tfAbreviation", tfAbreviation);
238
 
239
 
240
			left.add(fsNoms);
241
 
242
			// Naissance & décès
243
			FieldSet fsVie = new FieldSet();
244
			fsVie.setHeading("Vie");
245
 
246
			formLayout = new FormLayout();
280 gduche 247
			formLayout.setLabelAlign(LabelAlign.TOP);
276 gduche 248
			fsVie.setLayout(formLayout);
249
 
250
			// Date naissance
280 gduche 251
			DateField dfDateNaissance = new DateField();
276 gduche 252
 
280 gduche 253
			dfDateNaissance.setFieldLabel("Date de naissance");
254
			fsVie.add(dfDateNaissance);
276 gduche 255
 
280 gduche 256
			hmIdentite.put("dfDateNaissance", dfDateNaissance);
276 gduche 257
 
280 gduche 258
			// Lieu naissance
259
			TextField<String> tfLieuNaissance = new TextField();
260
			tfLieuNaissance.setFieldLabel("Lieu de naissance");
261
			fsVie.add(tfLieuNaissance);
262
 
263
			hmIdentite.put("tfLieuNaissance", tfLieuNaissance);
264
 
265
			// Date décès
266
			DateField dfDateDeces = new DateField();
267
			dfDateDeces.setFieldLabel("Date de décès");
268
			fsVie.add(dfDateDeces);
269
 
270
			hmIdentite.put("dfDateDeces", dfDateDeces);
271
 
272
			// Lieu décès
273
			TextField<String> tfLieuDeces = new TextField();
274
			tfLieuDeces.setFieldLabel("Lieu de décès");
275
			fsVie.add(tfLieuDeces);
276
 
277
			hmIdentite.put("tfLieuDeces", tfLieuDeces);
278
 
279
			//Date picker
280
			DatePicker datePick = new DatePicker();
281
 
282
 
283
			left.add(fsVie);
284
 
276 gduche 285
			tiIdentite.add(main);
286
 
287
 
288
			// Ajout des évènements saisi
289
			KeyListener klNoms = new KeyListener()	{
290
				public void componentKeyUp(ComponentEvent ev)	{
291
						/*
292
						 * Met à jour le nom Complet du formulaire
293
						 * */
294
						String valeurRetour = "";
295
						// Prefixe
280 gduche 296
						String prefixe = (String) ((ComboBox) hmIdentite.get("cbPrefix")).getSelectedText();
276 gduche 297
 
298
						// Prénom
299
						String prenom = (String) ((TextField) hmIdentite.get("tfPrenom")).getValue();
300
 
301
						// Nom
302
						String nom = (String) ((TextField) hmIdentite.get("tfNom")).getValue();
303
 
304
						// Suffixe
280 gduche 305
						String suffixe = (String) ((ComboBox) hmIdentite.get("cbSuffixe")).getSelectedText();
276 gduche 306
 
307
						// Mettre à jour la valeur
308
						valeurRetour = prefixe + " " + prenom + " " + nom + " " + suffixe;
309
						valeurRetour = valeurRetour.replaceAll("null", "");
310
 
311
						((LabelField) hmIdentite.get("nomComplet")).setValue(valeurRetour);
312
 
313
						if (!valeurRetour.trim().equals(""))	{
314
							((LabelField) hmIdentite.get("nomComplet")).show();
315
						} else {
316
							((LabelField) hmIdentite.get("nomComplet")).hide();
317
						}
318
 
280 gduche 319
				}
276 gduche 320
			};
321
 
280 gduche 322
			cbPrefix.addKeyListener(klNoms);
276 gduche 323
			tfPrenom.addKeyListener(klNoms);
324
			tfNom.addKeyListener(klNoms);
280 gduche 325
			cbSuffixe.addKeyListener(klNoms);
276 gduche 326
 
327
 
328
			//Prénom
329
 
280 gduche 330
 
331
			this.recalculate();
332
			fsNoms.recalculate();
333
			fsNoms.layout();
334
			this.layout();
335
			this.hide();
336
 
337
			rafraichir(null);
338
 
339
 
276 gduche 340
	}
341
 
342
	/**
343
	 * Ajouter le bouton réinitialiser à la barre d'outils donnée
344
	 *
345
	 * @param barreOutils la barre d'outils à modifier
346
	 * */
347
	public static void ajouterBoutonReinitialiser(ToolBar barreOutils)	{
348
 
349
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
350
		TextToolItem reinitialiser = new TextToolItem("Réinitialiser");
351
		reinitialiser.setIconStyle(ComposantClass.ICONE_RAFRAICHIR);
352
		reinitialiser.addSelectionListener(new SelectionListener<ComponentEvent>() {
353
			public void componentSelected(ComponentEvent ce) {
354
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicAjouterPersonne();
355
			}
356
		});
357
		barreOutils.add(reinitialiser);
358
	}
359
 
360
	/**
361
	 * Ajouter le bouton Sauvegarder à la barre d'outils donnée
362
	 *
363
	 * @param barreOutils la barre d'outils à modifier
364
	 * */
365
	public static void ajouterBoutonEnregistrer(ToolBar barreOutils)	{
366
 
367
		//Le bouton réintialiser recharge la page sans sauvegarder les informations
368
		TextToolItem reinitialiser = new TextToolItem("Enregistrer");
369
		reinitialiser.setIconStyle(ComposantClass.ICONE_PREFERENCE);
370
		reinitialiser.addSelectionListener(new SelectionListener<ComponentEvent>() {
371
			public void componentSelected(ComponentEvent ce) {
372
				// TODO : Enregistrer le formulaire
373
			}
374
		});
375
		barreOutils.add(reinitialiser);
376
	}
377
 
378
	/**
379
	 * Ajouter le bouton annuler à la barre d'outils donnée
380
	 *
381
	 * @param barreOutils la barre d'outils à modifier
382
	 * */
383
	public static void ajouterBoutonAnnuler(ToolBar barreOutils)	{
384
 
385
		// Le bouton annuler ne sauvegarde pas les informations et renvoie vers la page précédente
386
		TextToolItem annuler = new TextToolItem("Annuler");
387
		annuler.addSelectionListener(new SelectionListener<ComponentEvent>() {
388
			public void componentSelected(ComponentEvent ce) {
389
				((Mediateur) Registry.get(RegistreId.MEDIATEUR)).clicMenu("Personnes");
390
			}
391
		});
392
		annuler.setIconStyle(ComposantClass.ICONE_SUPPRIMER);
393
		barreOutils.add(annuler);
394
	}
395
 
396
 
397
 
398
	/*---------------------------------------------------------------------------------------
399
	 * 		RAFRAICHISSEMENT DU PANNEAU
400
	 * --------------------------------------------------------------------------------------
401
	 */
127 gduche 402
	public void rafraichir(Object nouvelleDonnees) {
403
		// TODO Auto-generated method stub
280 gduche 404
		this.show();
405
		this.layout();
406
		this.recalculate();
127 gduche 407
	}
408
 
130 gduche 409
 
410
 
411
 
127 gduche 412
}