Subversion Repositories eFlore/Applications.cel

Rev

Rev 120 | 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;
13 david 14
import com.gwtext.client.core.EventCallback;
15
import com.gwtext.client.core.EventObject;
16
import com.gwtext.client.core.ListenerConfig;
12 david 17
import com.gwtext.client.core.Position;
13 david 18
import com.gwtext.client.data.ArrayReader;
19
import com.gwtext.client.data.FieldDef;
20
import com.gwtext.client.data.MemoryProxy;
21
import com.gwtext.client.data.RecordDef;
71 jpm 22
import com.gwtext.client.data.SimpleStore;
13 david 23
import com.gwtext.client.data.Store;
24
import com.gwtext.client.data.StringFieldDef;
12 david 25
import com.gwtext.client.widgets.Button;
26
import com.gwtext.client.widgets.Panel;
71 jpm 27
import com.gwtext.client.widgets.Toolbar;
20 david 28
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
13 david 29
import com.gwtext.client.widgets.form.ComboBox;
12 david 30
import com.gwtext.client.widgets.form.DateField;
31
import com.gwtext.client.widgets.form.FormPanel;
128 aurelien 32
import com.gwtext.client.widgets.form.TextArea;
12 david 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;
74 david 64
	private String numeroOrdre = null;
20 david 65
 
118 david 66
	// Pour remise a zero partielle lors d'une validation
67
 
68
	private  enum Champs {
69
	    DATE, LIEUDIT, STATION, MILIEU, COMMENT, COMMUNE, ESPECE, TOUT
70
	};
71
 
72
 
73
 
110 aurelien 74
	private String formatDate = null ;
71 jpm 75
	private Button boutonOK = new Button("Créer");
77 jpm 76
	private Button boutonAnnuler = new Button("Réinitialiser");
20 david 77
 
13 david 78
	private boolean selectionCommune=false;
20 david 79
	private boolean selectionEspece=false;
12 david 80
 
71 jpm 81
	private boolean modification = false ;
82
	private Toolbar bt = null ;
13 david 83
 
20 david 84
	private final int KEY_ALT = 18;
85
	private final int KEY_BACKSPACE = 8;
86
	private final int KEY_CTRL = 17;
87
	private final int KEY_DELETE = 46;
88
	private final int KEY_DOWN = 40;
89
	private final int KEY_END = 35;
90
	private final int KEY_ENTER = 13;
91
	private final int KEY_ESCAPE = 27;
92
	private final int KEY_HOME = 36;
93
	private final int KEY_LEFT = 37;
94
	private final int KEY_PAGEDOWN = 34;
95
	private final int KEY_PAGEUP = 33;
96
	private final int KEY_RIGHT = 39;
97
	private final int KEY_SHIFT = 16;
98
	private final int KEY_TAB = 9;
99
	private final int KEY_UP = 38;
13 david 100
 
128 aurelien 101
	private int tailleChamps = 350 ;
102
 
71 jpm 103
	/**
104
	 * Combobox permettant de selectionner le mode
105
	 * modification ou bien création
106
	 */
107
	private ComboBox selecteurMode = new ComboBox();
13 david 108
 
71 jpm 109
	Store storeMode = null ;
13 david 110
 
12 david 111
	/**
112
	 * Booleen d'instanciation
113
	 */
114
	boolean estInstancie = false ;
115
 
116
	/**
117
	 * Constructeur sans argument (privé car ne doit pas être utilisé)
118
	 */
71 jpm 119
	@SuppressWarnings("unused")
12 david 120
	private FormulaireSaisieObservationVue()
121
	{
122
		super() ;
123
	}
124
 
125
	/**
126
	 * Constructeur avec argument
127
	 * @param im
128
	 */
129
	public FormulaireSaisieObservationVue(ObservationMediateur obs)
130
	{
131
		// on associe le médiateur
132
		observationMediateur = obs ;
133
 
134
 
53 david 135
		setHeader(true);
12 david 136
 
137
		FormPanel panneauFormulaire = new FormPanel(Position.RIGHT);
138
		panneauFormulaire.setBorder(false);
139
 
140
		// Panneau intermediaire qui contient deux colonnes de formulaire
141
 
142
		Panel panneauIntermediaire = new Panel();
143
		panneauIntermediaire.setLayout(new ColumnLayout());
144
		panneauIntermediaire.setBorder(false);
145
 
146
		//create first panel and add fields to it
147
		Panel panneauPremierColonne = new Panel();
148
		panneauPremierColonne.setLayout(new FormLayout());
149
		panneauPremierColonne.setBorder(false);
150
 
151
		//create second panel and add fields to it
152
	    Panel panneauSecondeColonne = new Panel();
153
		panneauSecondeColonne.setLayout(new FormLayout());
154
		panneauSecondeColonne.setBorder(false);
42 jpm 155
 
156
		this.setPaddings(5) ;
12 david 157
 
20 david 158
 
49 david 159
 
128 aurelien 160
		commune=new ComboBox("Commune","commune",tailleChamps );
13 david 161
 
162
 
20 david 163
		final String resultTplCommune = "<div class=\"search-item-commune\">{commune}</div>";
13 david 164
 
165
 
20 david 166
		commune.setTpl(resultTplCommune);
13 david 167
		commune.setMode(ComboBox.REMOTE);
168
		// commune.setPageSize(10); // Ne fonctionne pas
20 david 169
		commune.setItemSelector("div.search-item-commune");
13 david 170
		commune.setTypeAhead(true);
171
		commune.setLoadingText("Recherche...");
172
 
173
		commune.setHideTrigger(true);
174
 
175
 
20 david 176
 
13 david 177
 
178
 
179
	    panneauPremierColonne.add(commune);
180
 
181
 
182
 
128 aurelien 183
	    station = new TextField("Station", "station", tailleChamps);
12 david 184
	    station.setAllowBlank(true);
185
	    panneauPremierColonne.add(station);
186
 
187
	    date = new DateField("Date", "date", 100);
188
	    date.setAllowBlank(true);
110 aurelien 189
	    formatDate = "d/m/Y";
190
	    date.setFormat(formatDate) ;
12 david 191
	    panneauPremierColonne.add(date);
20 david 192
 
193
 
128 aurelien 194
		espece=new ComboBox("Espèce","nom",tailleChamps );
12 david 195
 
20 david 196
 
197
		final String resultTplEspece = "<div class=\"search-item-espece\">{nom}</div>";
198
 
199
 
200
		espece.setTpl(resultTplEspece);
201
		espece.setMode(ComboBox.REMOTE);
202
		// commune.setPageSize(10); // Ne fonctionne pas
203
		espece.setItemSelector("div.search-item-espece");
204
		espece.setTypeAhead(true);
205
		espece.setLoadingText("Recherche...");
206
 
207
		espece.setHideTrigger(true);
208
 
209
 
210
 
128 aurelien 211
	    panneauPremierColonne.add(espece);
20 david 212
 
128 aurelien 213
	    lieudit = new TextField("Lieu-dit", "lieudit", tailleChamps);
12 david 214
	    lieudit.setAllowBlank(true);
215
	    panneauSecondeColonne.add(lieudit);
216
 
217
 
128 aurelien 218
	    milieu = new TextField("Milieu", "milieu", tailleChamps);
12 david 219
	    milieu.setAllowBlank(true);
110 aurelien 220
	    panneauSecondeColonne.add(milieu);
128 aurelien 221
 
222
	    comment = new TextArea("Notes", "comment");
223
	    comment.setAllowBlank(true);
224
	    comment.setHeight(50);
225
	    comment.setWidth(tailleChamps);
226
	    panneauSecondeColonne.add(comment);
12 david 227
 
228
		panneauIntermediaire.add(panneauPremierColonne, new ColumnLayoutData(.5));
229
		panneauIntermediaire.add(panneauSecondeColonne, new ColumnLayoutData(.5));
230
 
231
		panneauFormulaire.add(panneauIntermediaire);
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) ;
97 jpm 243
		selecteurMode.setCls("x-selec-crea") ;
71 jpm 244
 
245
		bt = new Toolbar() ;
246
		bt.addSpacer() ;
247
		bt.addText("Mode de saisie ") ;
248
		bt.addField(selecteurMode) ;
249
 
74 david 250
 
251
 
252
 
12 david 253
		panneauFormulaire.addButton(boutonOK);
254
 
255
		panneauFormulaire.addButton(boutonAnnuler);
71 jpm 256
 
257
		selecteurMode.addListener(new ComboBoxListenerAdapter() {
258
 
259
			public void onSelect(ComboBox comboBox, Record record, int index) {
260
 
261
				// et on met la valeur à jour dans la combobox
262
				comboBox.setValue(record.getAsString("nom_mode"));
263
				setModification(record.getAsString("mode")) ;
264
			}
265
 
266
		});
12 david 267
 
268
		this.add(panneauFormulaire) ;
80 jpm 269
		this.setTopToolbar(bt) ;
12 david 270
 
120 aurelien 271
		this.setAutoScroll(true);
272
		//this.setAutoHeight(true);
12 david 273
 
274
 
275
		// on ajoute les listeners
276
		ajouterListeners() ;
277
 
278
 
279
 
280
	}
281
 
282
	private void ajouterListeners()
94 jpm 283
	{
20 david 284
		// Listener completion communne
285
 
286
		   commune.addListener(new ComboBoxListenerAdapter() {
287
	             public void onSelect(ComboBox comboBox, Record record, int index) {
288
	                 commune.setValue(record.getAsString("commune"));
39 david 289
	                 departement=record.getAsString("departement");
20 david 290
	                 selectionCommune=true;
291
	             }
292
	         });
293
 
294
 
295
			ListenerConfig listenerConfigCommune=new ListenerConfig();
296
			listenerConfigCommune.setDelay(10);
297
			listenerConfigCommune.setStopPropagation(false);
298
			listenerConfigCommune.setStopEvent(false);
299
 
300
 
301
 
302
		    commune.addKeyPressListener(new EventCallback()	{
303
 
120 aurelien 304
	    	    public void execute(EventObject e) {
305
 
306
 
307
	    	    		switch(e.getKey()) {
308
 
309
	    	    	    	case KEY_ENTER:
310
 
20 david 311
		    	    	    	 if (selectionCommune) {
312
		    	    	    		 selectionCommune=false;
313
		    	    	    	 }
120 aurelien 314
		    	    	    	else {
315
 
118 david 316
		    	    	    		validerSaisie(Champs.COMMUNE);
20 david 317
		    	    	    		// lancer mise a jour
318
		    	    	    	 }
120 aurelien 319
		    	    	    break;
320
 
321
		    	    	    default:
20 david 322
 
83 david 323
		    	    	    	  departement="";
20 david 324
		    	    	    	  obtenirListeReferentielCommune();
325
 
120 aurelien 326
		    	    	    break;
327
	    	    	    }
328
	     			}
329
	    		},    listenerConfigCommune
20 david 330
			);
331
 
120 aurelien 332
		    date.addKeyPressListener(new EventCallback() {
20 david 333
 
120 aurelien 334
				public void execute(EventObject e) {
335
					// TODO Auto-generated method stub
336
					switch(e.getKey()) {
337
 
338
	  	    	      case KEY_ENTER:
339
	  	    	    		validerSaisie(Champs.DATE);
340
	  	    	    	  break;
341
 
342
	  	    	      default:
343
					}
344
				}
345
		    });
346
 
347
		    station.addKeyPressListener(new EventCallback() {
348
 
349
				public void execute(EventObject e) {
350
					// TODO Auto-generated method stub
351
					switch(e.getKey()) {
352
 
353
	  	    	      case KEY_ENTER:
354
	  	    	    		validerSaisie(Champs.STATION);
355
	  	    	    	  break;
356
 
357
	  	    	      default:
358
					}
359
				}
360
		    });
361
 
362
 
20 david 363
 
120 aurelien 364
			// Listener completion espece
20 david 365
			espece.addListener(new ComboBoxListenerAdapter() {
366
	             public void onSelect(ComboBox comboBox, Record record, int index) {
367
	            	 espece.setValue(record.getAsString("nom"));
39 david 368
	            	 numeroNom=record.getAsString("numeroNom");
20 david 369
	                 selectionEspece=true;
128 aurelien 370
	                 observationMediateur.obtenirImageInformationExternes(numeroNom);
20 david 371
	             }
372
	         });
373
 
374
 
375
			ListenerConfig listenerConfigEspece=new ListenerConfig();
376
			listenerConfigEspece.setDelay(10);
377
			listenerConfigEspece.setStopPropagation(false);
378
			listenerConfigEspece.setStopEvent(false);
379
 
380
 
381
			espece.addKeyPressListener(new EventCallback()	{
382
 
383
		    	    public void execute(EventObject e) {
384
 
385
 
386
		    	    		  switch(e.getKey()) {
387
 
388
 
389
		    	    		  case KEY_ALT:
390
		    	    	      case KEY_CTRL:
391
		    	    	      case KEY_DOWN:
392
		    	    	      case KEY_END:
393
		    	    	      case KEY_ESCAPE:
394
		    	    	      case KEY_HOME:
395
		    	    	      case KEY_LEFT:
396
		    	    	      case KEY_PAGEDOWN:
397
		    	    	      case KEY_PAGEUP:
398
		    	    	      case KEY_RIGHT:
399
		    	    	      case KEY_SHIFT:
400
		    	    	      case KEY_TAB:
401
		    	    	      case KEY_UP:
402
 
403
		    	    	        break;
404
 
405
		    	    	      case KEY_ENTER:
406
 
407
		    	    	    	 if (selectionEspece) {
408
		    	    	    		 selectionEspece=false;
409
		    	    	    	 }
410
		    	    	    	 else {
120 aurelien 411
		    	    	    		validerSaisie(Champs.ESPECE);
20 david 412
		    	    	    	 }
413
 
414
 
415
		    	    	    	  break;
416
 
417
		    	    	      default:
418
 
83 david 419
		    	    	    	  numeroNom="";
20 david 420
		    	    	    	  obtenirListeReferentielNom();
421
 
422
		    	    	        break;
423
		    	    	    }
424
 
425
 
426
 
427
		     		}
428
 
429
		    		},    listenerConfigEspece
430
 
431
			);
432
 
120 aurelien 433
			lieudit.addKeyPressListener(new EventCallback() {
20 david 434
 
120 aurelien 435
				public void execute(EventObject e) {
436
					// TODO Auto-generated method stub
437
					switch(e.getKey()) {
438
 
439
	  	    	      case KEY_ENTER:
440
	  	    	    		validerSaisie(Champs.LIEUDIT);
441
	  	    	    	  break;
442
 
443
	  	    	      default:
444
					}
445
				}
446
		    });
447
 
448
			milieu.addKeyPressListener(new EventCallback() {
449
 
450
				public void execute(EventObject e) {
451
					// TODO Auto-generated method stub
452
					switch(e.getKey()) {
453
 
454
	  	    	      case KEY_ENTER:
455
	  	    	    		validerSaisie(Champs.MILIEU);
456
	  	    	    	  break;
457
 
458
	  	    	      default:
459
					}
460
				}
461
		    });
462
 
463
			comment.addKeyPressListener(new EventCallback() {
464
 
465
				public void execute(EventObject e) {
466
					// TODO Auto-generated method stub
467
					switch(e.getKey()) {
468
 
469
	  	    	      case KEY_ENTER:
470
	  	    	    		validerSaisie(Champs.COMMENT);
471
	  	    	    	  break;
472
 
473
	  	    	      default:
474
					}
475
				}
476
		    });
477
 
20 david 478
 
479
 
480
		boutonOK.addListener(new ButtonListenerAdapter() {
39 david 481
 
20 david 482
			public void onClick(Button button, EventObject e) {
118 david 483
 
484
				if(modification) {
71 jpm 485
					modifierObservation() ;
486
				}
118 david 487
				else {
71 jpm 488
					ajouterObservation();
489
				}
39 david 490
 
71 jpm 491
 
20 david 492
			}
493
 
494
		});
77 jpm 495
 
496
		boutonAnnuler.addListener(new ButtonListenerAdapter() {
12 david 497
 
498
			public void onClick(Button button, EventObject e) {
499
 
77 jpm 500
				if(modification)
501
				{
502
					supprimerObservation() ;
503
				}
504
				else
505
				{
104 jpm 506
					raz();
77 jpm 507
				}
12 david 508
 
77 jpm 509
 
510
			}
511
 
12 david 512
		});
513
	}
514
 
515
	/**
118 david 516
	 * Validation de la saisie
517
	 */
518
 
519
	private void validerSaisie(Champs champs) {
520
 
521
		if(modification) {
522
			modifierObservation() ;
523
 
524
		}
525
		else {
526
			ajouterObservation();
527
			raz(champs);
528
		}
529
	}
530
 
531
	/**
12 david 532
	 * Desactive visuellement ce panneau
533
	 */
534
	public void desactiverPanneau()
535
	{
536
		this.setDisabled(true) ;
537
	}
538
 
539
	/**
540
	 * Active visuellement ce panneau
541
	 */
542
	public void activerPanneau()
543
	{
544
		this.setDisabled(false) ;
545
	}
13 david 546
 
547
	public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
548
 
49 david 549
		// si l'on a reçu une liste du referentiel commune (completion referentiel commune)
13 david 550
			if(nouvelleDonnees instanceof ListeReferentielCommune)
551
			{
552
 
553
					ListeReferentielCommune data = (ListeReferentielCommune) nouvelleDonnees ;
554
					Object[][] communeData = new Object[data.size()][2];
555
					int i = 0 ;
556
 
557
					// on la parse et on récupère les informations quiç nous interessent
558
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
559
					{
560
 
561
						ReferentielCommune ref=(ReferentielCommune) data.get(it.next());
562
 
563
						communeData[i][0]= ref.getCommune();
564
						communeData[i][1]= ref.getDepartement();
565
 
566
 
567
						i++ ;
568
					}
569
 
570
					   //	  creation du store
571
					FieldDef defCommune = new StringFieldDef("commune");
572
					FieldDef defDepartement = new StringFieldDef("departement");
573
 
574
 
575
					FieldDef[] defTab = { defCommune, defDepartement};
576
 
577
					RecordDef rd = new RecordDef(defTab);
578
 
579
					final MemoryProxy dataProxy = new MemoryProxy(communeData);
580
					final ArrayReader reader = new ArrayReader(rd);
581
 
20 david 582
					Store store=new Store(dataProxy,reader);
13 david 583
					store.load() ;
584
 
41 jpm 585
					commune.setStore(store);
13 david 586
 
587
			}
20 david 588
 
94 jpm 589
			//			 si l'on a reçu une liste du référentiel nom (complétion referentiel nom)
20 david 590
 
591
			if(nouvelleDonnees instanceof ListeReferentielNom)
592
			{
593
 
594
					ListeReferentielNom data = (ListeReferentielNom) nouvelleDonnees ;
595
					Object[][] nomData = new Object[data.size()][2];
596
					int i = 0 ;
597
 
598
					// on la parse et on récupère les informations quiç nous interessent
599
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
600
					{
601
 
602
						ReferentielNom ref=(ReferentielNom) data.get(it.next());
603
 
604
						nomData[i][0]= ref.getNom();
605
						nomData[i][1]= ref.getNumeroNom();
606
 
607
 
608
						i++ ;
609
					}
610
 
611
					   //	  creation du store
612
					FieldDef defNom = new StringFieldDef("nom");
613
					FieldDef defNumeroNom = new StringFieldDef("numeroNom");
614
 
615
 
616
					FieldDef[] defTab = { defNom, defNumeroNom};
617
 
618
					RecordDef rd = new RecordDef(defTab);
619
 
620
					final MemoryProxy dataProxy = new MemoryProxy(nomData);
621
					final ArrayReader reader = new ArrayReader(rd);
622
 
623
					Store store=new Store(dataProxy,reader);
624
					store.load() ;
625
 
626
					espece.setStore(store);
627
 
628
 
629
 
630
			}
631
 
82 david 632
			// On recoit une observation dont on veut afficher le detail
633
 
71 jpm 634
			if(nouvelleDonnees instanceof Observation)
635
			{
636
				Observation obs = (Observation)nouvelleDonnees ;
637
				afficherDetailsObservation(obs) ;
638
			}
77 jpm 639
 
82 david 640
			// Sur Mise à jour ou suppression d'une suppression ?
641
 
77 jpm 642
			if(nouvelleDonnees instanceof String)
643
			{
644
				String str = (String)nouvelleDonnees ;
107 aurelien 645
				observationMediateur.obtenirNombreObservation() ;
77 jpm 646
			}
20 david 647
 
13 david 648
	}
12 david 649
 
650
 
13 david 651
	public void obtenirListeReferentielCommune() {
94 jpm 652
 
20 david 653
	 String com=commune.getText().replaceAll(" ","/");
654
	 com=com.replaceAll("%","");
655
 
656
	 observationMediateur.obtenirListeReferentielCommune(this,com);
13 david 657
 
658
	}
20 david 659
 
660
 
661
	public void obtenirListeReferentielNom() {
662
 
663
	  String esp=espece.getText().replaceAll(" ","/");
664
	  esp=esp.replaceAll("%","");
665
 
666
	  observationMediateur.obtenirListeReferentielNom(this,esp);
667
 
668
	}
669
 
670
 
39 david 671
	public void ajouterObservation() {
672
 
120 aurelien 673
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getRawValue());
46 david 674
		observationMediateur.ajouterObservation(obs);
39 david 675
	}
12 david 676
 
71 jpm 677
	private void modifierObservation() {
678
 
120 aurelien 679
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getRawValue());
79 david 680
		obs.setNumeroOrdre(numeroOrdre);
681
		observationMediateur.modifierObservation(obs);
74 david 682
 
71 jpm 683
	}
77 jpm 684
 
685
	private void supprimerObservation() {
686
 
687
			observationMediateur.supprimerObservation(this, numeroOrdre);
688
	}
12 david 689
 
71 jpm 690
 
691
	public void afficherDetailsObservation(Observation obs)
692
	{
104 jpm 693
		raz() ;
71 jpm 694
 
695
		if(!obs.getDate().equals("null") && !obs.getDate().equals("000null")) {
696
			String[] dateEtHeure = obs.getDate().split(" ", 2);
110 aurelien 697
			if(verifierFormatDate(dateEtHeure[0])) {
698
				date.setValue(dateEtHeure[0]) ;
699
			}
700
			else
701
			{
702
				date.setRawValue("");
703
			}
71 jpm 704
		}
705
		if(!obs.getLieudit().equals("null") && !obs.getLieudit().equals("000null")) {
706
			lieudit.setValue(obs.getLieudit()) ;
707
		}
708
		if(!obs.getStation().equals("null") && !obs.getStation().equals("000null")) {
709
			station.setValue(obs.getStation()) ;
710
		}
711
		if(!obs.getMilieu().equals("null") && !obs.getMilieu().equals("000null")) {
712
			milieu.setValue(obs.getMilieu()) ;
713
		}
714
		if(!obs.getCommentaire().equals("null") && !obs.getCommentaire().equals("000null")) {
715
			comment.setValue(obs.getCommentaire()) ;
716
		}
717
		if(!obs.getLocalite().equals("null") && !obs.getLocalite().equals("000null")) {
718
			commune.setValue(obs.getLocalite()) ;
719
		}
720
		if(!obs.getIdentifiantLocalite().equals("null") && !obs.getIdentifiantLocalite().equals("000null")) {
721
			departement = obs.getIdentifiantLocalite();
722
		}
723
		if(!obs.getNomSaisi().equals("null") && !obs.getNomSaisi().equals("000null")) {
724
			espece.setValue(obs.getNomSaisi()) ;
725
		}
726
		if(!obs.getNumeroNomenclaturalSaisi().equals("null") && !obs.getNumeroNomenclaturalSaisi().equals("000null")) {
727
			numeroNom = obs.getNumeroNomenclaturalSaisi() ;
728
		}
83 david 729
		if(!obs.getNumeroOrdre().equals("null") && !obs.getNumeroOrdre().equals("000nu2ll")) {
74 david 730
			numeroOrdre = obs.getNumeroOrdre() ;
731
		}
732
 
71 jpm 733
	}
734
 
118 david 735
 
104 jpm 736
	public void raz()
71 jpm 737
	{
118 david 738
		raz(Champs.TOUT);
739
 
740
	}
741
	public void raz(Champs champs)
742
	{
743
		switch (champs) {
744
 
745
 
746
			case DATE:
747
				date.reset() ;
748
				break;
749
 
750
			case LIEUDIT:
751
				lieudit.reset() ;
752
				break;
753
 
754
			case STATION:
755
				station.reset() ;
756
				break;
757
 
758
			case MILIEU:
759
				milieu.reset() ;
760
				break;
761
 
762
			case COMMENT:
763
				comment.reset() ;
764
				break;
765
 
766
 
767
			case COMMUNE:
768
				milieu.reset() ;
769
				departement ="";
770
				break;
771
 
772
			case ESPECE:
773
				espece.reset();
774
				numeroNom = "" ;
775
				numeroOrdre = "";
776
				break;
777
 
778
			case TOUT:
779
				date.reset() ;
780
				lieudit.reset() ;
781
				station.reset() ;
782
				milieu.reset() ;
783
				comment.reset() ;
784
				milieu.reset() ;
785
				departement ="";
786
				espece.reset();
787
				numeroNom = "" ;
788
				numeroOrdre = "";
789
				break;
790
 
791
		}
71 jpm 792
 
793
	}
794
 
795
	private void setModification(String mode)
796
	{
797
		if(mode.equals("true")) {
798
 
799
			boutonOK.setText("Modifier") ;
800
			setTitle("Modification") ;
77 jpm 801
			boutonAnnuler.setText("Supprimer") ;
71 jpm 802
			modification = true ;
97 jpm 803
			selecteurMode.removeClass("x-selec-crea") ;
804
			selecteurMode.setCls("x-selec-modif") ;
94 jpm 805
 
71 jpm 806
		}
807
		else
808
		{
809
 
120 aurelien 810
			boutonOK.setText("Ajouter") ;
71 jpm 811
			setTitle("Saisir") ;
77 jpm 812
			boutonAnnuler.setText("Réinitialiser") ;
71 jpm 813
			modification = false ;
97 jpm 814
			selecteurMode.removeClass("x-selec-modif") ;
815
			selecteurMode.setCls("x-selec-crea") ;
94 jpm 816
 
71 jpm 817
		}
818
 
819
	}
820
 
821
 
822
	/**
823
	 * renvoie vrai si on est en mode modification, faux si on est en mode création
824
	 * @return
825
	 */
826
	public boolean getModification()
827
	{
828
		return modification ;
829
	}
110 aurelien 830
 
831
	public boolean verifierFormatDate(String date) {
832
 
833
		String regex = "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]" ;
834
		if(date.matches(regex) && !date.equals("0000-00-00")) {
835
			return true ;
836
		}
837
		else {
838
			return false;
839
		}
840
	}
71 jpm 841
 
12 david 842
}