Subversion Repositories eFlore/Applications.cel

Rev

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

Rev Author Line No. Line
12 david 1
package org.tela_botanica.client.vues;
2
 
3
 
4
 
13 david 5
import java.util.Iterator;
6
 
7
import org.tela_botanica.client.interfaces.Rafraichissable;
8
import org.tela_botanica.client.modeles.ListeReferentielCommune;
20 david 9
import org.tela_botanica.client.modeles.ListeReferentielNom;
39 david 10
import org.tela_botanica.client.modeles.Observation;
13 david 11
import org.tela_botanica.client.modeles.ReferentielCommune;
20 david 12
import org.tela_botanica.client.modeles.ReferentielNom;
12 david 13
import org.tela_botanica.client.observation.ObservationMediateur;
14
 
15
 
39 david 16
import com.google.gwt.user.client.Window;
13 david 17
import com.gwtext.client.core.EventCallback;
18
import com.gwtext.client.core.EventObject;
19
import com.gwtext.client.core.ListenerConfig;
12 david 20
import com.gwtext.client.core.Position;
13 david 21
import com.gwtext.client.data.ArrayReader;
22
import com.gwtext.client.data.FieldDef;
23
import com.gwtext.client.data.MemoryProxy;
24
import com.gwtext.client.data.RecordDef;
25
import com.gwtext.client.data.Store;
26
import com.gwtext.client.data.StringFieldDef;
12 david 27
import com.gwtext.client.widgets.Button;
28
import com.gwtext.client.widgets.Panel;
20 david 29
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
13 david 30
import com.gwtext.client.widgets.form.ComboBox;
12 david 31
import com.gwtext.client.widgets.form.DateField;
32
import com.gwtext.client.widgets.form.FormPanel;
33
import com.gwtext.client.widgets.form.TextField;
13 david 34
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
12 david 35
import com.gwtext.client.widgets.layout.ColumnLayout;
36
import com.gwtext.client.widgets.layout.ColumnLayoutData;
37
import com.gwtext.client.widgets.layout.FormLayout;
13 david 38
import com.gwtext.client.data.Record;
12 david 39
 
40
/**
41
 * Panneau contenant les infos, les métadonnées et l'arbre des mots clés, il implémente l'interface rafraichissable
42
 * @author aurelien
43
 *
44
 */
13 david 45
public class FormulaireSaisieObservationVue extends Panel implements Rafraichissable  {
12 david 46
 
47
 
48
	/**
49
	 * Le médiateur associé à la vue
50
	 */
51
	private ObservationMediateur	observationMediateur		= null;
52
 
53
 
20 david 54
 
13 david 55
	private DateField date = null;
12 david 56
	private TextField lieudit = null;
57
	private TextField station = null;
58
	private TextField milieu = null;
59
	private TextField comment = null;
13 david 60
	private ComboBox  commune = null;
39 david 61
	private String departement = null;
20 david 62
	private ComboBox  espece = null;
39 david 63
	private String numeroNom = null;
20 david 64
 
65
	private Button boutonOK = new Button("Ok");
66
	private Button boutonAnnuler = new Button("Annuler");
67
 
13 david 68
	private boolean selectionCommune=false;
20 david 69
	private boolean selectionEspece=false;
12 david 70
 
13 david 71
 
20 david 72
	private final int KEY_ALT = 18;
73
	private final int KEY_BACKSPACE = 8;
74
	private final int KEY_CTRL = 17;
75
	private final int KEY_DELETE = 46;
76
	private final int KEY_DOWN = 40;
77
	private final int KEY_END = 35;
78
	private final int KEY_ENTER = 13;
79
	private final int KEY_ESCAPE = 27;
80
	private final int KEY_HOME = 36;
81
	private final int KEY_LEFT = 37;
82
	private final int KEY_PAGEDOWN = 34;
83
	private final int KEY_PAGEUP = 33;
84
	private final int KEY_RIGHT = 39;
85
	private final int KEY_SHIFT = 16;
86
	private final int KEY_TAB = 9;
87
	private final int KEY_UP = 38;
13 david 88
 
89
 
20 david 90
 
13 david 91
 
12 david 92
	/**
93
	 * Booleen d'instanciation
94
	 */
95
	boolean estInstancie = false ;
96
 
97
	/**
98
	 * Constructeur sans argument (privé car ne doit pas être utilisé)
99
	 */
100
	private FormulaireSaisieObservationVue()
101
	{
102
		super() ;
103
	}
104
 
105
	/**
106
	 * Constructeur avec argument
107
	 * @param im
108
	 */
109
	public FormulaireSaisieObservationVue(ObservationMediateur obs)
110
	{
111
 
112
 
113
		// on associe le médiateur
114
		observationMediateur = obs ;
115
 
116
		this.setHeader(true);
117
		this.setTitle("Saisie");
118
 
119
 
120
		this.setCollapsible(true) ;
121
 
122
		FormPanel panneauFormulaire = new FormPanel(Position.RIGHT);
123
		panneauFormulaire.setBorder(false);
124
 
125
		// Panneau intermediaire qui contient deux colonnes de formulaire
126
 
127
		Panel panneauIntermediaire = new Panel();
128
		panneauIntermediaire.setLayout(new ColumnLayout());
129
		panneauIntermediaire.setBorder(false);
130
 
131
		//create first panel and add fields to it
132
		Panel panneauPremierColonne = new Panel();
133
		panneauPremierColonne.setLayout(new FormLayout());
134
		panneauPremierColonne.setBorder(false);
135
 
136
		//create second panel and add fields to it
137
	    Panel panneauSecondeColonne = new Panel();
138
		panneauSecondeColonne.setLayout(new FormLayout());
139
		panneauSecondeColonne.setBorder(false);
140
 
13 david 141
	/*
142
	    //	  creation du store
143
		FieldDef defCommune = new StringFieldDef("commune");
144
		FieldDef defDepartement = new StringFieldDef("departement");
12 david 145
 
13 david 146
 
147
		FieldDef[] defTab = { defCommune, defDepartement};
148
 
149
		RecordDef rd = new RecordDef(defTab);
150
 
151
 
152
		store = new Store(rd);
153
 
154
		//store.load();*/
155
 
20 david 156
 
13 david 157
		commune=new ComboBox("Commune","commune",275 );
158
 
159
 
20 david 160
		final String resultTplCommune = "<div class=\"search-item-commune\">{commune}</div>";
13 david 161
 
162
 
20 david 163
		commune.setTpl(resultTplCommune);
13 david 164
		commune.setMode(ComboBox.REMOTE);
165
		// commune.setPageSize(10); // Ne fonctionne pas
20 david 166
		commune.setItemSelector("div.search-item-commune");
13 david 167
		commune.setTypeAhead(true);
168
		commune.setLoadingText("Recherche...");
169
 
170
		commune.setHideTrigger(true);
171
 
172
 
20 david 173
 
13 david 174
 
175
 
176
	    panneauPremierColonne.add(commune);
177
 
178
 
179
 
12 david 180
	    station = new TextField("Station", "station", 275);
181
	    station.setAllowBlank(true);
182
	    panneauPremierColonne.add(station);
183
 
184
	    date = new DateField("Date", "date", 100);
185
	    date.setAllowBlank(true);
20 david 186
	    date.setFormat("d/m/Y") ;
12 david 187
	    panneauPremierColonne.add(date);
20 david 188
 
189
 
190
		espece=new ComboBox("Espèce","nom",275 );
12 david 191
 
20 david 192
 
193
		final String resultTplEspece = "<div class=\"search-item-espece\">{nom}</div>";
194
 
195
 
196
		espece.setTpl(resultTplEspece);
197
		espece.setMode(ComboBox.REMOTE);
198
		// commune.setPageSize(10); // Ne fonctionne pas
199
		espece.setItemSelector("div.search-item-espece");
200
		espece.setTypeAhead(true);
201
		espece.setLoadingText("Recherche...");
202
 
203
		espece.setHideTrigger(true);
204
 
205
 
206
 
207
	    panneauPremierColonne.add(espece);
208
 
12 david 209
	    comment = new TextField("Notes", "comment", 275);
210
	    comment.setAllowBlank(true);
211
	    panneauPremierColonne.add(comment);
212
 
213
 
214
	    lieudit = new TextField("Lieu-dit", "lieudit", 275);
215
	    lieudit.setAllowBlank(true);
216
	    panneauSecondeColonne.add(lieudit);
217
 
218
 
219
	    milieu = new TextField("Milieu", "milieu", 275);
220
	    milieu.setAllowBlank(true);
221
	    panneauSecondeColonne.add(milieu);
222
 
13 david 223
 
12 david 224
 
225
		panneauIntermediaire.add(panneauPremierColonne, new ColumnLayoutData(.5));
226
		panneauIntermediaire.add(panneauSecondeColonne, new ColumnLayoutData(.5));
227
 
228
		panneauFormulaire.add(panneauIntermediaire);
229
 
20 david 230
 
12 david 231
		panneauFormulaire.addButton(boutonOK);
232
 
20 david 233
 
12 david 234
		panneauFormulaire.addButton(boutonAnnuler);
235
 
236
 
237
		this.add(panneauFormulaire) ;
238
 
239
 
240
		this.setAutoHeight(true);
241
 
242
 
243
		// on ajoute les listeners
244
		ajouterListeners() ;
245
 
246
 
247
 
248
	}
249
 
250
	private void ajouterListeners()
251
	{
20 david 252
 
253
 
254
		// Listener completion communne
255
 
256
		   commune.addListener(new ComboBoxListenerAdapter() {
257
	             public void onSelect(ComboBox comboBox, Record record, int index) {
258
	                 commune.setValue(record.getAsString("commune"));
39 david 259
	                 departement=record.getAsString("departement");
20 david 260
	                 selectionCommune=true;
261
	             }
262
	         });
263
 
264
 
265
			ListenerConfig listenerConfigCommune=new ListenerConfig();
266
			listenerConfigCommune.setDelay(10);
267
			listenerConfigCommune.setStopPropagation(false);
268
			listenerConfigCommune.setStopEvent(false);
269
 
270
 
271
 
272
		    commune.addKeyPressListener(new EventCallback()	{
273
 
274
		    	    public void execute(EventObject e) {
275
 
276
 
277
		    	    		  switch(e.getKey()) {
278
 
279
 
280
		    	    		  case KEY_ALT:
281
		    	    	      case KEY_CTRL:
282
		    	    	      case KEY_DOWN:
283
		    	    	      case KEY_END:
284
		    	    	      case KEY_ESCAPE:
285
		    	    	      case KEY_HOME:
286
		    	    	      case KEY_LEFT:
287
		    	    	      case KEY_PAGEDOWN:
288
		    	    	      case KEY_PAGEUP:
289
		    	    	      case KEY_RIGHT:
290
		    	    	      case KEY_SHIFT:
291
		    	    	      case KEY_TAB:
292
		    	    	      case KEY_UP:
293
 
294
		    	    	        break;
295
 
296
		    	    	      case KEY_ENTER:
297
 
298
		    	    	    	 if (selectionCommune) {
299
		    	    	    		 selectionCommune=false;
300
		    	    	    	 }
301
		    	    	    	 else {
302
		    	    	    		// lancer mise a jour
303
		    	    	    	 }
304
 
305
 
306
		    	    	    	  break;
307
 
308
		    	    	      default:
309
 
310
		    	    	    	  obtenirListeReferentielCommune();
311
 
312
		    	    	        break;
313
		    	    	    }
314
 
315
 
316
 
317
		     		}
318
 
319
		    		},    listenerConfigCommune
320
 
321
			);
322
 
323
			// Listener completion espece
324
 
325
 
326
			espece.addListener(new ComboBoxListenerAdapter() {
327
	             public void onSelect(ComboBox comboBox, Record record, int index) {
328
	            	 espece.setValue(record.getAsString("nom"));
39 david 329
	            	 numeroNom=record.getAsString("numeroNom");
20 david 330
	                 selectionEspece=true;
331
	             }
332
	         });
333
 
334
 
335
			ListenerConfig listenerConfigEspece=new ListenerConfig();
336
			listenerConfigEspece.setDelay(10);
337
			listenerConfigEspece.setStopPropagation(false);
338
			listenerConfigEspece.setStopEvent(false);
339
 
340
 
341
			espece.addKeyPressListener(new EventCallback()	{
342
 
343
		    	    public void execute(EventObject e) {
344
 
345
 
346
		    	    		  switch(e.getKey()) {
347
 
348
 
349
		    	    		  case KEY_ALT:
350
		    	    	      case KEY_CTRL:
351
		    	    	      case KEY_DOWN:
352
		    	    	      case KEY_END:
353
		    	    	      case KEY_ESCAPE:
354
		    	    	      case KEY_HOME:
355
		    	    	      case KEY_LEFT:
356
		    	    	      case KEY_PAGEDOWN:
357
		    	    	      case KEY_PAGEUP:
358
		    	    	      case KEY_RIGHT:
359
		    	    	      case KEY_SHIFT:
360
		    	    	      case KEY_TAB:
361
		    	    	      case KEY_UP:
362
 
363
		    	    	        break;
364
 
365
		    	    	      case KEY_ENTER:
366
 
367
		    	    	    	 if (selectionEspece) {
368
		    	    	    		 selectionEspece=false;
369
		    	    	    	 }
370
		    	    	    	 else {
371
		    	    	    		// lancer mise a jour
372
		    	    	    	 }
373
 
374
 
375
		    	    	    	  break;
376
 
377
		    	    	      default:
378
 
379
		    	    	    	  obtenirListeReferentielNom();
380
 
381
		    	    	        break;
382
		    	    	    }
383
 
384
 
385
 
386
		     		}
387
 
388
		    		},    listenerConfigEspece
389
 
390
			);
391
 
392
 
393
 
394
 
395
		boutonOK.addListener(new ButtonListenerAdapter() {
39 david 396
 
20 david 397
			public void onClick(Button button, EventObject e) {
39 david 398
 
399
				ajouterObservation();
400
 
20 david 401
			}
39 david 402
 
20 david 403
 
404
		});
405
 
12 david 406
		// on ajoute un écouteur
407
		/*validerInfo.addListener(new ButtonListenerAdapter() {
408
 
409
			// gestion du clic
410
 
411
			public void onClick(Button button, EventObject e) {
412
 
413
				// lors du clic sur le bouton valider on met à jour les commentaires et la date
414
		//	getIMediateur().mettreAJourInfo(commentaireGeneral.getText(), dateImage.getRawValue(), noteVue.getNote()) ;
415
 
416
			}
417
		});
418
		*/
419
 
420
 
421
	}
422
 
423
	/**
424
	 * Desactive visuellement ce panneau
425
	 */
426
	public void desactiverPanneau()
427
	{
428
		this.setDisabled(true) ;
429
	}
430
 
431
	/**
432
	 * Active visuellement ce panneau
433
	 */
434
	public void activerPanneau()
435
	{
436
		this.setDisabled(false) ;
437
	}
13 david 438
 
439
	public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
440
		//
441
 
442
 
443
		// si l'on a reçu une liste de commune
444
			if(nouvelleDonnees instanceof ListeReferentielCommune)
445
			{
446
 
447
					ListeReferentielCommune data = (ListeReferentielCommune) nouvelleDonnees ;
448
					Object[][] communeData = new Object[data.size()][2];
449
					int i = 0 ;
450
 
451
					// on la parse et on récupère les informations quiç nous interessent
452
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
453
					{
454
 
455
						ReferentielCommune ref=(ReferentielCommune) data.get(it.next());
456
 
457
						communeData[i][0]= ref.getCommune();
458
						communeData[i][1]= ref.getDepartement();
459
 
460
 
461
						i++ ;
462
					}
463
 
464
					   //	  creation du store
465
					FieldDef defCommune = new StringFieldDef("commune");
466
					FieldDef defDepartement = new StringFieldDef("departement");
467
 
468
 
469
					FieldDef[] defTab = { defCommune, defDepartement};
470
 
471
					RecordDef rd = new RecordDef(defTab);
472
 
473
					final MemoryProxy dataProxy = new MemoryProxy(communeData);
474
					final ArrayReader reader = new ArrayReader(rd);
475
 
20 david 476
					Store store=new Store(dataProxy,reader);
13 david 477
					store.load() ;
478
 
479
					commune.setStore(store);
480
 
481
 
482
 
483
			}
20 david 484
 
485
//			 si l'on a reçu une liste de nom
486
 
487
			if(nouvelleDonnees instanceof ListeReferentielNom)
488
			{
489
 
490
					ListeReferentielNom data = (ListeReferentielNom) nouvelleDonnees ;
491
					Object[][] nomData = new Object[data.size()][2];
492
					int i = 0 ;
493
 
494
					// on la parse et on récupère les informations quiç nous interessent
495
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
496
					{
497
 
498
						ReferentielNom ref=(ReferentielNom) data.get(it.next());
499
 
500
						nomData[i][0]= ref.getNom();
501
						nomData[i][1]= ref.getNumeroNom();
502
 
503
 
504
						i++ ;
505
					}
506
 
507
					   //	  creation du store
508
					FieldDef defNom = new StringFieldDef("nom");
509
					FieldDef defNumeroNom = new StringFieldDef("numeroNom");
510
 
511
 
512
					FieldDef[] defTab = { defNom, defNumeroNom};
513
 
514
					RecordDef rd = new RecordDef(defTab);
515
 
516
					final MemoryProxy dataProxy = new MemoryProxy(nomData);
517
					final ArrayReader reader = new ArrayReader(rd);
518
 
519
					Store store=new Store(dataProxy,reader);
520
					store.load() ;
521
 
522
					espece.setStore(store);
523
 
524
 
525
 
526
			}
527
 
528
 
13 david 529
	}
12 david 530
 
531
 
13 david 532
	public void obtenirListeReferentielCommune() {
20 david 533
	 String com=commune.getText().replaceAll(" ","/");
534
	 com=com.replaceAll("%","");
535
 
536
	 observationMediateur.obtenirListeReferentielCommune(this,com);
13 david 537
 
538
	}
20 david 539
 
540
 
541
	public void obtenirListeReferentielNom() {
542
 
543
	  String esp=espece.getText().replaceAll(" ","/");
544
	  esp=esp.replaceAll("%","");
545
 
546
	  observationMediateur.obtenirListeReferentielNom(this,esp);
547
 
548
	}
549
 
550
 
39 david 551
	public void ajouterObservation() {
552
 
553
 
554
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getText());
555
 
556
		observationMediateur.ajouterObservation(this, obs);
557
	}
12 david 558
 
559
 
560
}