Subversion Repositories eFlore/Applications.coel

Rev

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