Subversion Repositories eFlore/Applications.cel

Rev

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