Subversion Repositories eFlore/Applications.cel

Rev

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