Subversion Repositories eFlore/Applications.cel

Rev

Rev 71 | 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
 
71 jpm 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;
71 jpm 21
import com.gwtext.client.core.Template;
13 david 22
import com.gwtext.client.data.ArrayReader;
23
import com.gwtext.client.data.FieldDef;
24
import com.gwtext.client.data.MemoryProxy;
25
import com.gwtext.client.data.RecordDef;
71 jpm 26
import com.gwtext.client.data.SimpleStore;
13 david 27
import com.gwtext.client.data.Store;
28
import com.gwtext.client.data.StringFieldDef;
12 david 29
import com.gwtext.client.widgets.Button;
30
import com.gwtext.client.widgets.Panel;
71 jpm 31
import com.gwtext.client.widgets.Toolbar;
20 david 32
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
13 david 33
import com.gwtext.client.widgets.form.ComboBox;
12 david 34
import com.gwtext.client.widgets.form.DateField;
35
import com.gwtext.client.widgets.form.FormPanel;
74 david 36
import com.gwtext.client.widgets.form.Hidden;
12 david 37
import com.gwtext.client.widgets.form.TextField;
13 david 38
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
12 david 39
import com.gwtext.client.widgets.layout.ColumnLayout;
40
import com.gwtext.client.widgets.layout.ColumnLayoutData;
41
import com.gwtext.client.widgets.layout.FormLayout;
13 david 42
import com.gwtext.client.data.Record;
12 david 43
 
44
/**
45
 * Panneau contenant les infos, les métadonnées et l'arbre des mots clés, il implémente l'interface rafraichissable
46
 * @author aurelien
47
 *
48
 */
13 david 49
public class FormulaireSaisieObservationVue extends Panel implements Rafraichissable  {
12 david 50
 
51
 
52
	/**
53
	 * Le médiateur associé à la vue
54
	 */
55
	private ObservationMediateur	observationMediateur		= null;
56
 
57
 
20 david 58
 
13 david 59
	private DateField date = null;
12 david 60
	private TextField lieudit = null;
61
	private TextField station = null;
62
	private TextField milieu = null;
63
	private TextField comment = null;
13 david 64
	private ComboBox  commune = null;
39 david 65
	private String departement = null;
20 david 66
	private ComboBox  espece = null;
39 david 67
	private String numeroNom = null;
74 david 68
	private String numeroOrdre = null;
20 david 69
 
74 david 70
 
71 jpm 71
	private Button boutonOK = new Button("Créer");
20 david 72
	private Button boutonAnnuler = new Button("Annuler");
73
 
13 david 74
	private boolean selectionCommune=false;
20 david 75
	private boolean selectionEspece=false;
12 david 76
 
71 jpm 77
	private boolean modification = false ;
78
	private Toolbar bt = null ;
13 david 79
 
20 david 80
	private final int KEY_ALT = 18;
81
	private final int KEY_BACKSPACE = 8;
82
	private final int KEY_CTRL = 17;
83
	private final int KEY_DELETE = 46;
84
	private final int KEY_DOWN = 40;
85
	private final int KEY_END = 35;
86
	private final int KEY_ENTER = 13;
87
	private final int KEY_ESCAPE = 27;
88
	private final int KEY_HOME = 36;
89
	private final int KEY_LEFT = 37;
90
	private final int KEY_PAGEDOWN = 34;
91
	private final int KEY_PAGEUP = 33;
92
	private final int KEY_RIGHT = 39;
93
	private final int KEY_SHIFT = 16;
94
	private final int KEY_TAB = 9;
95
	private final int KEY_UP = 38;
13 david 96
 
71 jpm 97
	/**
98
	 * Combobox permettant de selectionner le mode
99
	 * modification ou bien création
100
	 */
101
	private ComboBox selecteurMode = new ComboBox();
13 david 102
 
71 jpm 103
	Store storeMode = null ;
13 david 104
 
12 david 105
	/**
106
	 * Booleen d'instanciation
107
	 */
108
	boolean estInstancie = false ;
109
 
110
	/**
111
	 * Constructeur sans argument (privé car ne doit pas être utilisé)
112
	 */
71 jpm 113
	@SuppressWarnings("unused")
12 david 114
	private FormulaireSaisieObservationVue()
115
	{
116
		super() ;
117
	}
118
 
119
	/**
120
	 * Constructeur avec argument
121
	 * @param im
122
	 */
123
	public FormulaireSaisieObservationVue(ObservationMediateur obs)
124
	{
125
 
126
 
127
		// on associe le médiateur
128
		observationMediateur = obs ;
129
 
130
 
53 david 131
		setHeader(true);
12 david 132
 
133
		FormPanel panneauFormulaire = new FormPanel(Position.RIGHT);
134
		panneauFormulaire.setBorder(false);
135
 
136
		// Panneau intermediaire qui contient deux colonnes de formulaire
137
 
138
		Panel panneauIntermediaire = new Panel();
139
		panneauIntermediaire.setLayout(new ColumnLayout());
140
		panneauIntermediaire.setBorder(false);
141
 
142
		//create first panel and add fields to it
143
		Panel panneauPremierColonne = new Panel();
144
		panneauPremierColonne.setLayout(new FormLayout());
145
		panneauPremierColonne.setBorder(false);
146
 
147
		//create second panel and add fields to it
148
	    Panel panneauSecondeColonne = new Panel();
149
		panneauSecondeColonne.setLayout(new FormLayout());
150
		panneauSecondeColonne.setBorder(false);
42 jpm 151
 
152
		this.setPaddings(5) ;
12 david 153
 
20 david 154
 
49 david 155
 
13 david 156
		commune=new ComboBox("Commune","commune",275 );
157
 
158
 
20 david 159
		final String resultTplCommune = "<div class=\"search-item-commune\">{commune}</div>";
13 david 160
 
161
 
20 david 162
		commune.setTpl(resultTplCommune);
13 david 163
		commune.setMode(ComboBox.REMOTE);
164
		// commune.setPageSize(10); // Ne fonctionne pas
20 david 165
		commune.setItemSelector("div.search-item-commune");
13 david 166
		commune.setTypeAhead(true);
167
		commune.setLoadingText("Recherche...");
168
 
169
		commune.setHideTrigger(true);
170
 
171
 
20 david 172
 
13 david 173
 
174
 
175
	    panneauPremierColonne.add(commune);
176
 
177
 
178
 
12 david 179
	    station = new TextField("Station", "station", 275);
180
	    station.setAllowBlank(true);
181
	    panneauPremierColonne.add(station);
182
 
183
	    date = new DateField("Date", "date", 100);
184
	    date.setAllowBlank(true);
20 david 185
	    date.setFormat("d/m/Y") ;
12 david 186
	    panneauPremierColonne.add(date);
20 david 187
 
188
 
189
		espece=new ComboBox("Espèce","nom",275 );
12 david 190
 
20 david 191
 
192
		final String resultTplEspece = "<div class=\"search-item-espece\">{nom}</div>";
193
 
194
 
195
		espece.setTpl(resultTplEspece);
196
		espece.setMode(ComboBox.REMOTE);
197
		// commune.setPageSize(10); // Ne fonctionne pas
198
		espece.setItemSelector("div.search-item-espece");
199
		espece.setTypeAhead(true);
200
		espece.setLoadingText("Recherche...");
201
 
202
		espece.setHideTrigger(true);
203
 
204
 
205
 
206
	    panneauPremierColonne.add(espece);
207
 
12 david 208
	    comment = new TextField("Notes", "comment", 275);
209
	    comment.setAllowBlank(true);
210
	    panneauPremierColonne.add(comment);
211
 
212
 
213
	    lieudit = new TextField("Lieu-dit", "lieudit", 275);
214
	    lieudit.setAllowBlank(true);
215
	    panneauSecondeColonne.add(lieudit);
216
 
217
 
218
	    milieu = new TextField("Milieu", "milieu", 275);
219
	    milieu.setAllowBlank(true);
220
	    panneauSecondeColonne.add(milieu);
221
 
13 david 222
 
12 david 223
 
224
		panneauIntermediaire.add(panneauPremierColonne, new ColumnLayoutData(.5));
225
		panneauIntermediaire.add(panneauSecondeColonne, new ColumnLayoutData(.5));
226
 
227
		panneauFormulaire.add(panneauIntermediaire);
228
 
71 jpm 229
		/*final Template tp = new Template("<div class=\"x-combo-list-item\">"
230
				+ "{nom_mode}" + "<div class=\"x-clear\"></div></div>");
231
		tp.compile();*/
20 david 232
 
71 jpm 233
		Object[][] mode = {{"création",false} , {"modification", true} };
234
		storeMode = new SimpleStore(new String[] { "nom_mode", "mode" },
235
				mode);
236
		storeMode.load();
237
		selecteurMode.setStore(storeMode);
238
		selecteurMode.setDisplayField("nom_mode") ;
239
		selecteurMode.setLabel("mode ") ;
240
		selecteurMode.setForceSelection(true) ;
241
		selecteurMode.setValue("création") ;
242
		selecteurMode.setEditable(false) ;
243
 
244
		bt = new Toolbar() ;
245
		bt.addSpacer() ;
246
		bt.addText("Mode de saisie ") ;
247
		bt.addField(selecteurMode) ;
248
 
74 david 249
 
250
 
251
 
12 david 252
		panneauFormulaire.addButton(boutonOK);
253
 
254
		panneauFormulaire.addButton(boutonAnnuler);
71 jpm 255
 
256
		selecteurMode.addListener(new ComboBoxListenerAdapter() {
257
 
258
			public void onSelect(ComboBox comboBox, Record record, int index) {
259
 
260
				// et on met la valeur à jour dans la combobox
261
				comboBox.setValue(record.getAsString("nom_mode"));
262
				setModification(record.getAsString("mode")) ;
263
			}
264
 
265
		});
12 david 266
 
267
		this.add(panneauFormulaire) ;
71 jpm 268
		this.setBottomToolbar(bt) ;
12 david 269
 
270
 
271
		this.setAutoHeight(true);
272
 
273
 
274
		// on ajoute les listeners
275
		ajouterListeners() ;
276
 
277
 
278
 
279
	}
280
 
281
	private void ajouterListeners()
282
	{
20 david 283
 
284
 
285
		// Listener completion communne
286
 
287
		   commune.addListener(new ComboBoxListenerAdapter() {
288
	             public void onSelect(ComboBox comboBox, Record record, int index) {
289
	                 commune.setValue(record.getAsString("commune"));
39 david 290
	                 departement=record.getAsString("departement");
20 david 291
	                 selectionCommune=true;
292
	             }
293
	         });
294
 
295
 
296
			ListenerConfig listenerConfigCommune=new ListenerConfig();
297
			listenerConfigCommune.setDelay(10);
298
			listenerConfigCommune.setStopPropagation(false);
299
			listenerConfigCommune.setStopEvent(false);
300
 
301
 
302
 
303
		    commune.addKeyPressListener(new EventCallback()	{
304
 
305
		    	    public void execute(EventObject e) {
306
 
307
 
308
		    	    		  switch(e.getKey()) {
309
 
310
 
311
		    	    		  case KEY_ALT:
312
		    	    	      case KEY_CTRL:
313
		    	    	      case KEY_DOWN:
314
		    	    	      case KEY_END:
315
		    	    	      case KEY_ESCAPE:
316
		    	    	      case KEY_HOME:
317
		    	    	      case KEY_LEFT:
318
		    	    	      case KEY_PAGEDOWN:
319
		    	    	      case KEY_PAGEUP:
320
		    	    	      case KEY_RIGHT:
321
		    	    	      case KEY_SHIFT:
322
		    	    	      case KEY_TAB:
323
		    	    	      case KEY_UP:
324
 
325
		    	    	        break;
326
 
327
		    	    	      case KEY_ENTER:
328
 
329
		    	    	    	 if (selectionCommune) {
330
		    	    	    		 selectionCommune=false;
331
		    	    	    	 }
332
		    	    	    	 else {
333
		    	    	    		// lancer mise a jour
334
		    	    	    	 }
335
 
336
 
337
		    	    	    	  break;
338
 
339
		    	    	      default:
340
 
341
		    	    	    	  obtenirListeReferentielCommune();
342
 
343
		    	    	        break;
344
		    	    	    }
345
 
346
 
347
 
348
		     		}
349
 
350
		    		},    listenerConfigCommune
351
 
352
			);
353
 
354
			// Listener completion espece
355
 
356
 
357
			espece.addListener(new ComboBoxListenerAdapter() {
358
	             public void onSelect(ComboBox comboBox, Record record, int index) {
359
	            	 espece.setValue(record.getAsString("nom"));
39 david 360
	            	 numeroNom=record.getAsString("numeroNom");
20 david 361
	                 selectionEspece=true;
362
	             }
363
	         });
364
 
365
 
366
			ListenerConfig listenerConfigEspece=new ListenerConfig();
367
			listenerConfigEspece.setDelay(10);
368
			listenerConfigEspece.setStopPropagation(false);
369
			listenerConfigEspece.setStopEvent(false);
370
 
371
 
372
			espece.addKeyPressListener(new EventCallback()	{
373
 
374
		    	    public void execute(EventObject e) {
375
 
376
 
377
		    	    		  switch(e.getKey()) {
378
 
379
 
380
		    	    		  case KEY_ALT:
381
		    	    	      case KEY_CTRL:
382
		    	    	      case KEY_DOWN:
383
		    	    	      case KEY_END:
384
		    	    	      case KEY_ESCAPE:
385
		    	    	      case KEY_HOME:
386
		    	    	      case KEY_LEFT:
387
		    	    	      case KEY_PAGEDOWN:
388
		    	    	      case KEY_PAGEUP:
389
		    	    	      case KEY_RIGHT:
390
		    	    	      case KEY_SHIFT:
391
		    	    	      case KEY_TAB:
392
		    	    	      case KEY_UP:
393
 
394
		    	    	        break;
395
 
396
		    	    	      case KEY_ENTER:
397
 
398
		    	    	    	 if (selectionEspece) {
399
		    	    	    		 selectionEspece=false;
400
		    	    	    	 }
401
		    	    	    	 else {
402
		    	    	    		// lancer mise a jour
403
		    	    	    	 }
404
 
405
 
406
		    	    	    	  break;
407
 
408
		    	    	      default:
409
 
410
		    	    	    	  obtenirListeReferentielNom();
411
 
412
		    	    	        break;
413
		    	    	    }
414
 
415
 
416
 
417
		     		}
418
 
419
		    		},    listenerConfigEspece
420
 
421
			);
422
 
423
 
424
 
425
 
426
		boutonOK.addListener(new ButtonListenerAdapter() {
39 david 427
 
20 david 428
			public void onClick(Button button, EventObject e) {
39 david 429
 
71 jpm 430
				if(modification)
431
				{
432
					modifierObservation() ;
433
				}
434
				else
435
				{
436
					ajouterObservation();
437
				}
39 david 438
 
71 jpm 439
 
20 david 440
			}
441
 
442
		});
443
 
12 david 444
		// on ajoute un écouteur
445
		/*validerInfo.addListener(new ButtonListenerAdapter() {
446
 
447
			// gestion du clic
448
 
449
			public void onClick(Button button, EventObject e) {
450
 
451
				// lors du clic sur le bouton valider on met à jour les commentaires et la date
452
		//	getIMediateur().mettreAJourInfo(commentaireGeneral.getText(), dateImage.getRawValue(), noteVue.getNote()) ;
453
 
454
			}
455
		});
456
		*/
457
 
458
 
459
	}
460
 
461
	/**
462
	 * Desactive visuellement ce panneau
463
	 */
464
	public void desactiverPanneau()
465
	{
466
		this.setDisabled(true) ;
467
	}
468
 
469
	/**
470
	 * Active visuellement ce panneau
471
	 */
472
	public void activerPanneau()
473
	{
474
		this.setDisabled(false) ;
475
	}
13 david 476
 
477
	public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
478
 
49 david 479
		// si l'on a reçu une liste du referentiel commune (completion referentiel commune)
13 david 480
			if(nouvelleDonnees instanceof ListeReferentielCommune)
481
			{
482
 
483
					ListeReferentielCommune data = (ListeReferentielCommune) nouvelleDonnees ;
484
					Object[][] communeData = new Object[data.size()][2];
485
					int i = 0 ;
486
 
487
					// on la parse et on récupère les informations quiç nous interessent
488
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
489
					{
490
 
491
						ReferentielCommune ref=(ReferentielCommune) data.get(it.next());
492
 
493
						communeData[i][0]= ref.getCommune();
494
						communeData[i][1]= ref.getDepartement();
495
 
496
 
497
						i++ ;
498
					}
499
 
500
					   //	  creation du store
501
					FieldDef defCommune = new StringFieldDef("commune");
502
					FieldDef defDepartement = new StringFieldDef("departement");
503
 
504
 
505
					FieldDef[] defTab = { defCommune, defDepartement};
506
 
507
					RecordDef rd = new RecordDef(defTab);
508
 
509
					final MemoryProxy dataProxy = new MemoryProxy(communeData);
510
					final ArrayReader reader = new ArrayReader(rd);
511
 
20 david 512
					Store store=new Store(dataProxy,reader);
13 david 513
					store.load() ;
514
 
41 jpm 515
					commune.setStore(store);
13 david 516
 
517
			}
20 david 518
 
49 david 519
			//			 si l'on a reçu une liste du referentiel nom (complétion referentiel nom)
20 david 520
 
521
			if(nouvelleDonnees instanceof ListeReferentielNom)
522
			{
523
 
524
					ListeReferentielNom data = (ListeReferentielNom) nouvelleDonnees ;
525
					Object[][] nomData = new Object[data.size()][2];
526
					int i = 0 ;
527
 
528
					// on la parse et on récupère les informations quiç nous interessent
529
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
530
					{
531
 
532
						ReferentielNom ref=(ReferentielNom) data.get(it.next());
533
 
534
						nomData[i][0]= ref.getNom();
535
						nomData[i][1]= ref.getNumeroNom();
536
 
537
 
538
						i++ ;
539
					}
540
 
541
					   //	  creation du store
542
					FieldDef defNom = new StringFieldDef("nom");
543
					FieldDef defNumeroNom = new StringFieldDef("numeroNom");
544
 
545
 
546
					FieldDef[] defTab = { defNom, defNumeroNom};
547
 
548
					RecordDef rd = new RecordDef(defTab);
549
 
550
					final MemoryProxy dataProxy = new MemoryProxy(nomData);
551
					final ArrayReader reader = new ArrayReader(rd);
552
 
553
					Store store=new Store(dataProxy,reader);
554
					store.load() ;
555
 
556
					espece.setStore(store);
557
 
558
 
559
 
560
			}
561
 
71 jpm 562
			if(nouvelleDonnees instanceof Observation)
563
			{
564
				Observation obs = (Observation)nouvelleDonnees ;
565
				afficherDetailsObservation(obs) ;
566
			}
20 david 567
 
13 david 568
	}
12 david 569
 
570
 
13 david 571
	public void obtenirListeReferentielCommune() {
20 david 572
	 String com=commune.getText().replaceAll(" ","/");
573
	 com=com.replaceAll("%","");
574
 
575
	 observationMediateur.obtenirListeReferentielCommune(this,com);
13 david 576
 
577
	}
20 david 578
 
579
 
580
	public void obtenirListeReferentielNom() {
581
 
582
	  String esp=espece.getText().replaceAll(" ","/");
583
	  esp=esp.replaceAll("%","");
584
 
585
	  observationMediateur.obtenirListeReferentielNom(this,esp);
586
 
587
	}
588
 
589
 
39 david 590
	public void ajouterObservation() {
591
 
41 jpm 592
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getText());
46 david 593
		observationMediateur.ajouterObservation(obs);
39 david 594
	}
12 david 595
 
71 jpm 596
	private void modifierObservation() {
597
 
74 david 598
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getText());
599
		observationMediateur.modifierObservation(obs,numeroOrdre);
600
 
71 jpm 601
	}
12 david 602
 
71 jpm 603
 
604
	public void afficherDetailsObservation(Observation obs)
605
	{
606
		viderChampsObservation() ;
607
 
608
		if(!obs.getDate().equals("null") && !obs.getDate().equals("000null")) {
609
			String[] dateEtHeure = obs.getDate().split(" ", 2);
610
			date.setRawValue(dateEtHeure[0]) ;
611
		}
612
		if(!obs.getLieudit().equals("null") && !obs.getLieudit().equals("000null")) {
613
			lieudit.setValue(obs.getLieudit()) ;
614
		}
615
		if(!obs.getStation().equals("null") && !obs.getStation().equals("000null")) {
616
			station.setValue(obs.getStation()) ;
617
		}
618
		if(!obs.getMilieu().equals("null") && !obs.getMilieu().equals("000null")) {
619
			milieu.setValue(obs.getMilieu()) ;
620
		}
621
		if(!obs.getCommentaire().equals("null") && !obs.getCommentaire().equals("000null")) {
622
			comment.setValue(obs.getCommentaire()) ;
623
		}
624
		if(!obs.getLocalite().equals("null") && !obs.getLocalite().equals("000null")) {
625
			commune.setValue(obs.getLocalite()) ;
626
		}
627
		if(!obs.getIdentifiantLocalite().equals("null") && !obs.getIdentifiantLocalite().equals("000null")) {
628
			departement = obs.getIdentifiantLocalite();
629
		}
630
		if(!obs.getNomSaisi().equals("null") && !obs.getNomSaisi().equals("000null")) {
631
			espece.setValue(obs.getNomSaisi()) ;
632
		}
633
		if(!obs.getNumeroNomenclaturalSaisi().equals("null") && !obs.getNumeroNomenclaturalSaisi().equals("000null")) {
634
			numeroNom = obs.getNumeroNomenclaturalSaisi() ;
635
		}
74 david 636
		if(!obs.getNumeroOrdre().equals("null") && !obs.getNumeroOrdre().equals("000null")) {
637
			numeroOrdre = obs.getNumeroOrdre() ;
638
		}
639
 
71 jpm 640
	}
641
 
642
	public void viderChampsObservation()
643
	{
644
 
645
		date.reset() ;
646
		lieudit.reset() ;
647
		station.reset() ;
648
		milieu.reset();
649
		comment.reset();
650
		commune.reset();
651
		departement = "";
652
		espece.reset();
653
		numeroNom = "" ;
74 david 654
		numeroOrdre = "";
71 jpm 655
 
656
	}
657
 
658
	private void setModification(String mode)
659
	{
660
		if(mode.equals("true")) {
661
 
662
			boutonOK.setText("Modifier") ;
663
			setTitle("Modification") ;
664
			modification = true ;
665
		}
666
		else
667
		{
668
 
669
			boutonOK.setText("Créer") ;
670
			setTitle("Saisir") ;
671
			modification = false ;
672
		}
673
 
674
	}
675
 
676
 
677
	/**
678
	 * renvoie vrai si on est en mode modification, faux si on est en mode création
679
	 * @return
680
	 */
681
	public boolean getModification()
682
	{
683
		return modification ;
684
	}
685
 
686
 
12 david 687
}