Subversion Repositories eFlore/Applications.cel

Rev

Rev 146 | 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
 
128 aurelien 166
		commune=new ComboBox("Commune","commune",tailleChamps );
20 david 167
		final String resultTplCommune = "<div class=\"search-item-commune\">{commune}</div>";
168
		commune.setTpl(resultTplCommune);
13 david 169
		commune.setMode(ComboBox.REMOTE);
170
		// commune.setPageSize(10); // Ne fonctionne pas
20 david 171
		commune.setItemSelector("div.search-item-commune");
13 david 172
		commune.setTypeAhead(true);
173
		commune.setLoadingText("Recherche...");
174
 
175
		commune.setHideTrigger(true);
132 aurelien 176
		commune.setTabIndex(1);
13 david 177
 
178
	    panneauPremierColonne.add(commune);
179
 
128 aurelien 180
	    station = new TextField("Station", "station", tailleChamps);
132 aurelien 181
	    station.setAllowBlank(true);
182
	    station.setTabIndex(3);
12 david 183
	    panneauPremierColonne.add(station);
184
 
185
	    date = new DateField("Date", "date", 100);
186
	    date.setAllowBlank(true);
110 aurelien 187
	    formatDate = "d/m/Y";
188
	    date.setFormat(formatDate) ;
132 aurelien 189
	    date.setTabIndex(5);
12 david 190
	    panneauPremierColonne.add(date);
20 david 191
 
192
 
128 aurelien 193
		espece=new ComboBox("Espèce","nom",tailleChamps );
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);
132 aurelien 207
		espece.setTabIndex(6);
20 david 208
 
128 aurelien 209
	    panneauPremierColonne.add(espece);
20 david 210
 
128 aurelien 211
	    lieudit = new TextField("Lieu-dit", "lieudit", tailleChamps);
132 aurelien 212
	    lieudit.setAllowBlank(true);
213
	    lieudit.setTabIndex(2);
12 david 214
	    panneauSecondeColonne.add(lieudit);
215
 
216
 
128 aurelien 217
	    milieu = new TextField("Milieu", "milieu", tailleChamps);
132 aurelien 218
	    milieu.setAllowBlank(true);
219
	    milieu.setTabIndex(4);
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);
132 aurelien 226
	    comment.setTabIndex(7);
128 aurelien 227
	    panneauSecondeColonne.add(comment);
12 david 228
 
229
		panneauIntermediaire.add(panneauPremierColonne, new ColumnLayoutData(.5));
230
		panneauIntermediaire.add(panneauSecondeColonne, new ColumnLayoutData(.5));
231
 
232
		panneauFormulaire.add(panneauIntermediaire);
233
 
71 jpm 234
		Object[][] mode = {{"création",false} , {"modification", true} };
235
		storeMode = new SimpleStore(new String[] { "nom_mode", "mode" },
236
				mode);
237
		storeMode.load();
238
		selecteurMode.setStore(storeMode);
239
		selecteurMode.setDisplayField("nom_mode") ;
240
		selecteurMode.setLabel("mode ") ;
241
		selecteurMode.setForceSelection(true) ;
242
		selecteurMode.setValue("création") ;
243
		selecteurMode.setEditable(false) ;
97 jpm 244
		selecteurMode.setCls("x-selec-crea") ;
71 jpm 245
 
246
		bt = new Toolbar() ;
247
		bt.addSpacer() ;
248
		bt.addText("Mode de saisie ") ;
249
		bt.addField(selecteurMode) ;
250
 
132 aurelien 251
		boutonOK.setTabIndex(8);
252
		boutonAnnuler.setTabIndex(9);
74 david 253
 
12 david 254
		panneauFormulaire.addButton(boutonOK);
255
 
256
		panneauFormulaire.addButton(boutonAnnuler);
71 jpm 257
 
258
		selecteurMode.addListener(new ComboBoxListenerAdapter() {
259
 
260
			public void onSelect(ComboBox comboBox, Record record, int index) {
261
 
262
				// et on met la valeur à jour dans la combobox
263
				comboBox.setValue(record.getAsString("nom_mode"));
264
				setModification(record.getAsString("mode")) ;
265
			}
266
 
267
		});
12 david 268
 
269
		this.add(panneauFormulaire) ;
80 jpm 270
		this.setTopToolbar(bt) ;
12 david 271
 
120 aurelien 272
		this.setAutoScroll(true);
273
		//this.setAutoHeight(true);
12 david 274
 
275
 
276
		// on ajoute les listeners
277
		ajouterListeners() ;
278
 
279
	}
280
 
281
	private void ajouterListeners()
94 jpm 282
	{
20 david 283
		// Listener completion communne
284
 
285
		   commune.addListener(new ComboBoxListenerAdapter() {
286
	             public void onSelect(ComboBox comboBox, Record record, int index) {
287
	                 commune.setValue(record.getAsString("commune"));
39 david 288
	                 departement=record.getAsString("departement");
20 david 289
	                 selectionCommune=true;
290
	             }
291
	         });
292
 
293
 
294
			ListenerConfig listenerConfigCommune=new ListenerConfig();
295
			listenerConfigCommune.setDelay(10);
296
			listenerConfigCommune.setStopPropagation(false);
297
			listenerConfigCommune.setStopEvent(false);
298
 
299
		    commune.addKeyPressListener(new EventCallback()	{
300
 
120 aurelien 301
	    	    public void execute(EventObject e) {
302
 
303
 
304
	    	    		switch(e.getKey()) {
305
 
132 aurelien 306
    	    				case KEY_ALT:
307
	    	    	        case KEY_CTRL:
308
	    	    	        case KEY_DOWN:
309
	    	    	        case KEY_END:
310
	    	    	        case KEY_ESCAPE:
311
	    	    	        case KEY_HOME:
312
	    	    	        case KEY_LEFT:
313
	    	    	        case KEY_PAGEDOWN:
314
	    	    	        case KEY_PAGEUP:
315
	    	    	        case KEY_RIGHT:
316
	    	    	        case KEY_SHIFT:
317
	    	    	        case KEY_TAB:
318
	    	    	        case KEY_UP:
319
 
320
	    	    	        break;
321
 
120 aurelien 322
	    	    	    	case KEY_ENTER:
323
 
20 david 324
		    	    	    	 if (selectionCommune) {
325
		    	    	    		 selectionCommune=false;
326
		    	    	    	 }
120 aurelien 327
		    	    	    	else {
328
 
118 david 329
		    	    	    		validerSaisie(Champs.COMMUNE);
20 david 330
		    	    	    		// lancer mise a jour
331
		    	    	    	 }
120 aurelien 332
		    	    	    break;
333
 
334
		    	    	    default:
20 david 335
 
83 david 336
		    	    	    	  departement="";
20 david 337
		    	    	    	  obtenirListeReferentielCommune();
338
 
120 aurelien 339
		    	    	    break;
340
	    	    	    }
341
	     			}
342
	    		},    listenerConfigCommune
20 david 343
			);
344
 
120 aurelien 345
		    date.addKeyPressListener(new EventCallback() {
20 david 346
 
120 aurelien 347
				public void execute(EventObject e) {
348
					// TODO Auto-generated method stub
349
					switch(e.getKey()) {
350
 
351
	  	    	      case KEY_ENTER:
352
	  	    	    		validerSaisie(Champs.DATE);
353
	  	    	    	  break;
354
 
355
	  	    	      default:
356
					}
357
				}
358
		    });
359
 
360
		    station.addKeyPressListener(new EventCallback() {
361
 
362
				public void execute(EventObject e) {
363
					// TODO Auto-generated method stub
364
					switch(e.getKey()) {
365
 
366
	  	    	      case KEY_ENTER:
367
	  	    	    		validerSaisie(Champs.STATION);
368
	  	    	    	  break;
369
 
370
	  	    	      default:
371
					}
372
				}
373
		    });
374
 
375
 
20 david 376
 
120 aurelien 377
			// Listener completion espece
20 david 378
			espece.addListener(new ComboBoxListenerAdapter() {
379
	             public void onSelect(ComboBox comboBox, Record record, int index) {
380
	            	 espece.setValue(record.getAsString("nom"));
39 david 381
	            	 numeroNom=record.getAsString("numeroNom");
20 david 382
	                 selectionEspece=true;
128 aurelien 383
	                 observationMediateur.obtenirImageInformationExternes(numeroNom);
20 david 384
	             }
385
	         });
386
 
387
 
388
			ListenerConfig listenerConfigEspece=new ListenerConfig();
389
			listenerConfigEspece.setDelay(10);
390
			listenerConfigEspece.setStopPropagation(false);
391
			listenerConfigEspece.setStopEvent(false);
392
 
393
 
394
			espece.addKeyPressListener(new EventCallback()	{
395
 
396
		    	    public void execute(EventObject e) {
397
 
398
 
399
		    	    		  switch(e.getKey()) {
400
 
401
 
402
		    	    		  case KEY_ALT:
403
		    	    	      case KEY_CTRL:
404
		    	    	      case KEY_DOWN:
405
		    	    	      case KEY_END:
406
		    	    	      case KEY_ESCAPE:
407
		    	    	      case KEY_HOME:
408
		    	    	      case KEY_LEFT:
409
		    	    	      case KEY_PAGEDOWN:
410
		    	    	      case KEY_PAGEUP:
411
		    	    	      case KEY_RIGHT:
412
		    	    	      case KEY_SHIFT:
413
		    	    	      case KEY_TAB:
414
		    	    	      case KEY_UP:
415
 
416
		    	    	        break;
417
 
418
		    	    	      case KEY_ENTER:
419
 
140 aurelien 420
			    	    	    	if(selectionEspece) {
421
			    	    	    		 selectionEspece=false;
422
			    	    	    	}
423
			    	    	    	else {
424
			    	    	    		validerSaisie(Champs.ESPECE);
425
			    	    	    	}
20 david 426
 
427
		    	    	    	  break;
428
 
429
		    	    	      default:
430
 
83 david 431
		    	    	    	  numeroNom="";
20 david 432
		    	    	    	  obtenirListeReferentielNom();
433
 
434
		    	    	        break;
435
		    	    	    }
436
 
437
 
438
 
439
		     		}
440
 
441
		    		},    listenerConfigEspece
442
 
443
			);
444
 
120 aurelien 445
			lieudit.addKeyPressListener(new EventCallback() {
20 david 446
 
120 aurelien 447
				public void execute(EventObject e) {
448
					// TODO Auto-generated method stub
449
					switch(e.getKey()) {
450
 
451
	  	    	      case KEY_ENTER:
452
	  	    	    		validerSaisie(Champs.LIEUDIT);
453
	  	    	    	  break;
454
 
455
	  	    	      default:
456
					}
457
				}
458
		    });
459
 
460
			milieu.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.MILIEU);
468
	  	    	    	  break;
469
 
470
	  	    	      default:
471
					}
472
				}
473
		    });
474
 
140 aurelien 475
			/*comment.addKeyPressListener(new EventCallback() {
120 aurelien 476
 
477
				public void execute(EventObject e) {
478
					// TODO Auto-generated method stub
479
					switch(e.getKey()) {
480
 
481
	  	    	      case KEY_ENTER:
482
	  	    	    		validerSaisie(Champs.COMMENT);
483
	  	    	    	  break;
484
 
485
	  	    	      default:
486
					}
487
				}
140 aurelien 488
		    });*/
120 aurelien 489
 
20 david 490
 
491
 
492
		boutonOK.addListener(new ButtonListenerAdapter() {
39 david 493
 
20 david 494
			public void onClick(Button button, EventObject e) {
118 david 495
 
496
				if(modification) {
71 jpm 497
					modifierObservation() ;
498
				}
118 david 499
				else {
71 jpm 500
					ajouterObservation();
501
				}
39 david 502
 
71 jpm 503
 
20 david 504
			}
505
 
506
		});
77 jpm 507
 
508
		boutonAnnuler.addListener(new ButtonListenerAdapter() {
12 david 509
 
510
			public void onClick(Button button, EventObject e) {
511
 
77 jpm 512
				if(modification)
513
				{
514
					supprimerObservation() ;
515
				}
516
				else
517
				{
104 jpm 518
					raz();
77 jpm 519
				}
12 david 520
 
77 jpm 521
 
522
			}
523
 
12 david 524
		});
132 aurelien 525
 
526
		this.addListener(new ContainerListenerAdapter() {
527
			public void onAfterLayout(Container self) {
528
 
529
				ajusterTailleChamps();
530
				commune.focus();
531
			}
532
		});
533
 
534
		this.addListener(new BoxComponentListenerAdapter() {
535
				public void onResize(BoxComponent component, int adjWidth, int adjHeight, int rawWidth, int rawHeight)  {
536
 
537
				ajusterTailleChamps();
538
			}
539
		});
12 david 540
	}
541
 
542
	/**
118 david 543
	 * Validation de la saisie
544
	 */
545
 
546
	private void validerSaisie(Champs champs) {
547
 
548
		if(modification) {
549
			modifierObservation() ;
550
 
551
		}
552
		else {
553
			ajouterObservation();
554
			raz(champs);
555
		}
556
	}
557
 
558
	/**
12 david 559
	 * Desactive visuellement ce panneau
560
	 */
561
	public void desactiverPanneau()
562
	{
563
		this.setDisabled(true) ;
564
	}
565
 
566
	/**
567
	 * Active visuellement ce panneau
568
	 */
569
	public void activerPanneau()
570
	{
571
		this.setDisabled(false) ;
572
	}
13 david 573
 
574
	public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
575
 
49 david 576
		// si l'on a reçu une liste du referentiel commune (completion referentiel commune)
13 david 577
			if(nouvelleDonnees instanceof ListeReferentielCommune)
578
			{
579
 
580
					ListeReferentielCommune data = (ListeReferentielCommune) nouvelleDonnees ;
581
					Object[][] communeData = new Object[data.size()][2];
582
					int i = 0 ;
583
 
584
					// on la parse et on récupère les informations quiç nous interessent
585
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
586
					{
587
 
588
						ReferentielCommune ref=(ReferentielCommune) data.get(it.next());
589
 
590
						communeData[i][0]= ref.getCommune();
591
						communeData[i][1]= ref.getDepartement();
592
 
593
 
594
						i++ ;
595
					}
596
 
597
					   //	  creation du store
598
					FieldDef defCommune = new StringFieldDef("commune");
599
					FieldDef defDepartement = new StringFieldDef("departement");
600
 
601
 
602
					FieldDef[] defTab = { defCommune, defDepartement};
603
 
604
					RecordDef rd = new RecordDef(defTab);
605
 
606
					final MemoryProxy dataProxy = new MemoryProxy(communeData);
607
					final ArrayReader reader = new ArrayReader(rd);
608
 
20 david 609
					Store store=new Store(dataProxy,reader);
13 david 610
					store.load() ;
611
 
132 aurelien 612
					commune.setStore(store);
13 david 613
			}
20 david 614
 
94 jpm 615
			//			 si l'on a reçu une liste du référentiel nom (complétion referentiel nom)
20 david 616
 
617
			if(nouvelleDonnees instanceof ListeReferentielNom)
618
			{
619
 
620
					ListeReferentielNom data = (ListeReferentielNom) nouvelleDonnees ;
621
					Object[][] nomData = new Object[data.size()][2];
622
					int i = 0 ;
623
 
624
					// on la parse et on récupère les informations quiç nous interessent
625
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
626
					{
627
 
628
						ReferentielNom ref=(ReferentielNom) data.get(it.next());
629
 
630
						nomData[i][0]= ref.getNom();
631
						nomData[i][1]= ref.getNumeroNom();
632
 
633
 
634
						i++ ;
635
					}
636
 
637
					   //	  creation du store
638
					FieldDef defNom = new StringFieldDef("nom");
639
					FieldDef defNumeroNom = new StringFieldDef("numeroNom");
640
 
641
 
642
					FieldDef[] defTab = { defNom, defNumeroNom};
643
 
644
					RecordDef rd = new RecordDef(defTab);
645
 
646
					final MemoryProxy dataProxy = new MemoryProxy(nomData);
647
					final ArrayReader reader = new ArrayReader(rd);
648
 
649
					Store store=new Store(dataProxy,reader);
650
					store.load() ;
651
 
652
					espece.setStore(store);
653
 
654
 
655
 
656
			}
657
 
82 david 658
			// On recoit une observation dont on veut afficher le detail
659
 
71 jpm 660
			if(nouvelleDonnees instanceof Observation)
661
			{
662
				Observation obs = (Observation)nouvelleDonnees ;
663
				afficherDetailsObservation(obs) ;
664
			}
77 jpm 665
 
82 david 666
			// Sur Mise à jour ou suppression d'une suppression ?
667
 
77 jpm 668
			if(nouvelleDonnees instanceof String)
669
			{
670
				String str = (String)nouvelleDonnees ;
107 aurelien 671
				observationMediateur.obtenirNombreObservation() ;
77 jpm 672
			}
140 aurelien 673
 
674
			if(nouvelleDonnees instanceof String[]) {
675
				String[] anumNom = (String[])nouvelleDonnees ;
676
				numeroNom = anumNom[1];
677
				espece.setValue(anumNom[0]);
678
				setModification("false");
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() {
140 aurelien 705
 
706
		if(departement.equals("000null") || departement.equals("")) {
707
			String[] depCom = commune.getText().split(" ");
708
			if(depCom.length > 1) {
709
				String dep = depCom[1].replace('(', ' ');
710
				dep =dep.replace(')', ' ');
711
				dep = dep.trim();
712
				dep = dep.replace('\\',' ');
713
				dep = dep.trim();
714
 
715
				try
716
				{
717
					int nDep = Integer.parseInt(dep);
718
					if(nDep > 0 && nDep < 110) {
719
						departement = dep ;
720
					}
721
				}
722
				catch(NumberFormatException e)
723
				{
724
					departement = "" ;
725
				}
726
			}
727
		}
39 david 728
 
120 aurelien 729
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getRawValue());
46 david 730
		observationMediateur.ajouterObservation(obs);
39 david 731
	}
12 david 732
 
71 jpm 733
	private void modifierObservation() {
734
 
120 aurelien 735
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getRawValue());
79 david 736
		obs.setNumeroOrdre(numeroOrdre);
737
		observationMediateur.modifierObservation(obs);
74 david 738
 
71 jpm 739
	}
77 jpm 740
 
741
	private void supprimerObservation() {
742
 
743
			observationMediateur.supprimerObservation(this, numeroOrdre);
744
	}
12 david 745
 
71 jpm 746
 
747
	public void afficherDetailsObservation(Observation obs)
748
	{
104 jpm 749
		raz() ;
140 aurelien 750
		char g ;
71 jpm 751
 
140 aurelien 752
		String idLoc =obs.getIdentifiantLocalite().replaceAll(" ","/");
753
		idLoc = idLoc.replaceAll("%","");
754
		idLoc = idLoc.replaceAll("\"","");
755
		idLoc = idLoc.replace('\\',' ');
756
		idLoc = idLoc.trim();
757
 
71 jpm 758
		if(!obs.getDate().equals("null") && !obs.getDate().equals("000null")) {
759
			String[] dateEtHeure = obs.getDate().split(" ", 2);
110 aurelien 760
			if(verifierFormatDate(dateEtHeure[0])) {
761
				date.setValue(dateEtHeure[0]) ;
762
			}
763
			else
764
			{
765
				date.setRawValue("");
766
			}
71 jpm 767
		}
768
		if(!obs.getLieudit().equals("null") && !obs.getLieudit().equals("000null")) {
769
			lieudit.setValue(obs.getLieudit()) ;
770
		}
771
		if(!obs.getStation().equals("null") && !obs.getStation().equals("000null")) {
772
			station.setValue(obs.getStation()) ;
773
		}
774
		if(!obs.getMilieu().equals("null") && !obs.getMilieu().equals("000null")) {
775
			milieu.setValue(obs.getMilieu()) ;
776
		}
777
		if(!obs.getCommentaire().equals("null") && !obs.getCommentaire().equals("000null")) {
778
			comment.setValue(obs.getCommentaire()) ;
779
		}
780
		if(!obs.getLocalite().equals("null") && !obs.getLocalite().equals("000null")) {
140 aurelien 781
			if(!idLoc.equals("000null")) {
782
				commune.setValue(obs.getLocalite()+" ("+idLoc+")") ;
783
			}
784
			else
785
			{
786
				commune.setValue(obs.getLocalite());
787
			}
71 jpm 788
		}
789
		if(!obs.getIdentifiantLocalite().equals("null") && !obs.getIdentifiantLocalite().equals("000null")) {
140 aurelien 790
			departement = idLoc;
71 jpm 791
		}
792
		if(!obs.getNomSaisi().equals("null") && !obs.getNomSaisi().equals("000null")) {
793
			espece.setValue(obs.getNomSaisi()) ;
794
		}
795
		if(!obs.getNumeroNomenclaturalSaisi().equals("null") && !obs.getNumeroNomenclaturalSaisi().equals("000null")) {
796
			numeroNom = obs.getNumeroNomenclaturalSaisi() ;
797
		}
83 david 798
		if(!obs.getNumeroOrdre().equals("null") && !obs.getNumeroOrdre().equals("000nu2ll")) {
74 david 799
			numeroOrdre = obs.getNumeroOrdre() ;
800
		}
801
 
71 jpm 802
	}
803
 
118 david 804
 
104 jpm 805
	public void raz()
71 jpm 806
	{
118 david 807
		raz(Champs.TOUT);
808
 
809
	}
810
	public void raz(Champs champs)
811
	{
812
		switch (champs) {
813
 
814
 
815
			case DATE:
816
				date.reset() ;
817
				break;
818
 
819
			case LIEUDIT:
820
				lieudit.reset() ;
821
				break;
822
 
823
			case STATION:
824
				station.reset() ;
825
				break;
826
 
827
			case MILIEU:
828
				milieu.reset() ;
829
				break;
830
 
831
			case COMMENT:
832
				comment.reset() ;
833
				break;
834
 
835
 
836
			case COMMUNE:
172 aurelien 837
				commune.reset() ;
118 david 838
				departement ="";
839
				break;
840
 
841
			case ESPECE:
842
				espece.reset();
843
				numeroNom = "" ;
844
				numeroOrdre = "";
845
				break;
846
 
847
			case TOUT:
132 aurelien 848
				commune.reset();
118 david 849
				date.reset() ;
850
				lieudit.reset() ;
851
				station.reset() ;
852
				milieu.reset() ;
853
				comment.reset() ;
854
				milieu.reset() ;
855
				departement ="";
856
				espece.reset();
857
				numeroNom = "" ;
858
				numeroOrdre = "";
859
				break;
860
 
861
		}
71 jpm 862
 
863
	}
864
 
865
	private void setModification(String mode)
866
	{
867
		if(mode.equals("true")) {
868
 
869
			boutonOK.setText("Modifier") ;
870
			setTitle("Modification") ;
77 jpm 871
			boutonAnnuler.setText("Supprimer") ;
71 jpm 872
			modification = true ;
97 jpm 873
			selecteurMode.removeClass("x-selec-crea") ;
874
			selecteurMode.setCls("x-selec-modif") ;
94 jpm 875
 
71 jpm 876
		}
877
		else
878
		{
879
 
120 aurelien 880
			boutonOK.setText("Ajouter") ;
71 jpm 881
			setTitle("Saisir") ;
77 jpm 882
			boutonAnnuler.setText("Réinitialiser") ;
71 jpm 883
			modification = false ;
97 jpm 884
			selecteurMode.removeClass("x-selec-modif") ;
885
			selecteurMode.setCls("x-selec-crea") ;
94 jpm 886
 
132 aurelien 887
		}
71 jpm 888
	}
889
 
890
	/**
891
	 * renvoie vrai si on est en mode modification, faux si on est en mode création
892
	 * @return
893
	 */
894
	public boolean getModification()
895
	{
896
		return modification ;
897
	}
110 aurelien 898
 
899
	public boolean verifierFormatDate(String date) {
900
 
132 aurelien 901
		String regex = "[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}" ;
110 aurelien 902
		if(date.matches(regex) && !date.equals("0000-00-00")) {
903
			return true ;
904
		}
905
		else {
906
			return false;
907
		}
908
	}
132 aurelien 909
 
910
	private void ajusterTailleChamps() {
911
 
912
		int tailleChamps = (this.getInnerWidth()/100)*40;
913
 
914
		this.tailleChamps = tailleChamps ;
915
 
916
		commune.setWidth(tailleChamps);
917
		station.setWidth(tailleChamps);
918
		espece.setWidth(tailleChamps);
919
		lieudit.setWidth(tailleChamps);
920
		milieu.setWidth(tailleChamps);
921
		comment.setWidth(tailleChamps);
71 jpm 922
 
132 aurelien 923
	}
924
 
12 david 925
}