Subversion Repositories eFlore/Applications.cel

Rev

Rev 132 | 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
 
140 aurelien 426
			    	    	    	if(selectionEspece) {
427
			    	    	    		 selectionEspece=false;
428
			    	    	    	}
429
			    	    	    	else {
430
			    	    	    		validerSaisie(Champs.ESPECE);
431
			    	    	    	}
20 david 432
 
433
		    	    	    	  break;
434
 
435
		    	    	      default:
436
 
83 david 437
		    	    	    	  numeroNom="";
20 david 438
		    	    	    	  obtenirListeReferentielNom();
439
 
440
		    	    	        break;
441
		    	    	    }
442
 
443
 
444
 
445
		     		}
446
 
447
		    		},    listenerConfigEspece
448
 
449
			);
450
 
120 aurelien 451
			lieudit.addKeyPressListener(new EventCallback() {
20 david 452
 
120 aurelien 453
				public void execute(EventObject e) {
454
					// TODO Auto-generated method stub
455
					switch(e.getKey()) {
456
 
457
	  	    	      case KEY_ENTER:
458
	  	    	    		validerSaisie(Champs.LIEUDIT);
459
	  	    	    	  break;
460
 
461
	  	    	      default:
462
					}
463
				}
464
		    });
465
 
466
			milieu.addKeyPressListener(new EventCallback() {
467
 
468
				public void execute(EventObject e) {
469
					// TODO Auto-generated method stub
470
					switch(e.getKey()) {
471
 
472
	  	    	      case KEY_ENTER:
473
	  	    	    		validerSaisie(Champs.MILIEU);
474
	  	    	    	  break;
475
 
476
	  	    	      default:
477
					}
478
				}
479
		    });
480
 
140 aurelien 481
			/*comment.addKeyPressListener(new EventCallback() {
120 aurelien 482
 
483
				public void execute(EventObject e) {
484
					// TODO Auto-generated method stub
485
					switch(e.getKey()) {
486
 
487
	  	    	      case KEY_ENTER:
488
	  	    	    		validerSaisie(Champs.COMMENT);
489
	  	    	    	  break;
490
 
491
	  	    	      default:
492
					}
493
				}
140 aurelien 494
		    });*/
120 aurelien 495
 
20 david 496
 
497
 
498
		boutonOK.addListener(new ButtonListenerAdapter() {
39 david 499
 
20 david 500
			public void onClick(Button button, EventObject e) {
118 david 501
 
502
				if(modification) {
71 jpm 503
					modifierObservation() ;
504
				}
118 david 505
				else {
71 jpm 506
					ajouterObservation();
507
				}
39 david 508
 
71 jpm 509
 
20 david 510
			}
511
 
512
		});
77 jpm 513
 
514
		boutonAnnuler.addListener(new ButtonListenerAdapter() {
12 david 515
 
516
			public void onClick(Button button, EventObject e) {
517
 
77 jpm 518
				if(modification)
519
				{
520
					supprimerObservation() ;
521
				}
522
				else
523
				{
104 jpm 524
					raz();
77 jpm 525
				}
12 david 526
 
77 jpm 527
 
528
			}
529
 
12 david 530
		});
132 aurelien 531
 
532
		this.addListener(new ContainerListenerAdapter() {
533
			public void onAfterLayout(Container self) {
534
 
535
				ajusterTailleChamps();
536
				commune.focus();
537
			}
538
		});
539
 
540
		this.addListener(new BoxComponentListenerAdapter() {
541
				public void onResize(BoxComponent component, int adjWidth, int adjHeight, int rawWidth, int rawHeight)  {
542
 
543
				ajusterTailleChamps();
544
			}
545
		});
12 david 546
	}
547
 
548
	/**
118 david 549
	 * Validation de la saisie
550
	 */
551
 
552
	private void validerSaisie(Champs champs) {
553
 
554
		if(modification) {
555
			modifierObservation() ;
556
 
557
		}
558
		else {
559
			ajouterObservation();
560
			raz(champs);
561
		}
562
	}
563
 
564
	/**
12 david 565
	 * Desactive visuellement ce panneau
566
	 */
567
	public void desactiverPanneau()
568
	{
569
		this.setDisabled(true) ;
570
	}
571
 
572
	/**
573
	 * Active visuellement ce panneau
574
	 */
575
	public void activerPanneau()
576
	{
577
		this.setDisabled(false) ;
578
	}
13 david 579
 
580
	public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
581
 
49 david 582
		// si l'on a reçu une liste du referentiel commune (completion referentiel commune)
13 david 583
			if(nouvelleDonnees instanceof ListeReferentielCommune)
584
			{
585
 
586
					ListeReferentielCommune data = (ListeReferentielCommune) nouvelleDonnees ;
587
					Object[][] communeData = new Object[data.size()][2];
588
					int i = 0 ;
589
 
590
					// on la parse et on récupère les informations quiç nous interessent
591
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
592
					{
593
 
594
						ReferentielCommune ref=(ReferentielCommune) data.get(it.next());
595
 
596
						communeData[i][0]= ref.getCommune();
597
						communeData[i][1]= ref.getDepartement();
598
 
599
 
600
						i++ ;
601
					}
602
 
603
					   //	  creation du store
604
					FieldDef defCommune = new StringFieldDef("commune");
605
					FieldDef defDepartement = new StringFieldDef("departement");
606
 
607
 
608
					FieldDef[] defTab = { defCommune, defDepartement};
609
 
610
					RecordDef rd = new RecordDef(defTab);
611
 
612
					final MemoryProxy dataProxy = new MemoryProxy(communeData);
613
					final ArrayReader reader = new ArrayReader(rd);
614
 
20 david 615
					Store store=new Store(dataProxy,reader);
13 david 616
					store.load() ;
617
 
132 aurelien 618
					commune.setStore(store);
13 david 619
			}
20 david 620
 
94 jpm 621
			//			 si l'on a reçu une liste du référentiel nom (complétion referentiel nom)
20 david 622
 
623
			if(nouvelleDonnees instanceof ListeReferentielNom)
624
			{
625
 
626
					ListeReferentielNom data = (ListeReferentielNom) nouvelleDonnees ;
627
					Object[][] nomData = new Object[data.size()][2];
628
					int i = 0 ;
629
 
630
					// on la parse et on récupère les informations quiç nous interessent
631
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
632
					{
633
 
634
						ReferentielNom ref=(ReferentielNom) data.get(it.next());
635
 
636
						nomData[i][0]= ref.getNom();
637
						nomData[i][1]= ref.getNumeroNom();
638
 
639
 
640
						i++ ;
641
					}
642
 
643
					   //	  creation du store
644
					FieldDef defNom = new StringFieldDef("nom");
645
					FieldDef defNumeroNom = new StringFieldDef("numeroNom");
646
 
647
 
648
					FieldDef[] defTab = { defNom, defNumeroNom};
649
 
650
					RecordDef rd = new RecordDef(defTab);
651
 
652
					final MemoryProxy dataProxy = new MemoryProxy(nomData);
653
					final ArrayReader reader = new ArrayReader(rd);
654
 
655
					Store store=new Store(dataProxy,reader);
656
					store.load() ;
657
 
658
					espece.setStore(store);
659
 
660
 
661
 
662
			}
663
 
82 david 664
			// On recoit une observation dont on veut afficher le detail
665
 
71 jpm 666
			if(nouvelleDonnees instanceof Observation)
667
			{
668
				Observation obs = (Observation)nouvelleDonnees ;
669
				afficherDetailsObservation(obs) ;
670
			}
77 jpm 671
 
82 david 672
			// Sur Mise à jour ou suppression d'une suppression ?
673
 
77 jpm 674
			if(nouvelleDonnees instanceof String)
675
			{
676
				String str = (String)nouvelleDonnees ;
107 aurelien 677
				observationMediateur.obtenirNombreObservation() ;
77 jpm 678
			}
140 aurelien 679
 
680
			if(nouvelleDonnees instanceof String[]) {
681
				String[] anumNom = (String[])nouvelleDonnees ;
682
				numeroNom = anumNom[1];
683
				espece.setValue(anumNom[0]);
684
				setModification("false");
685
			}
20 david 686
 
13 david 687
	}
12 david 688
 
689
 
13 david 690
	public void obtenirListeReferentielCommune() {
94 jpm 691
 
20 david 692
	 String com=commune.getText().replaceAll(" ","/");
693
	 com=com.replaceAll("%","");
694
 
695
	 observationMediateur.obtenirListeReferentielCommune(this,com);
13 david 696
 
697
	}
20 david 698
 
699
 
700
	public void obtenirListeReferentielNom() {
701
 
702
	  String esp=espece.getText().replaceAll(" ","/");
703
	  esp=esp.replaceAll("%","");
704
 
705
	  observationMediateur.obtenirListeReferentielNom(this,esp);
706
 
707
	}
708
 
709
 
39 david 710
	public void ajouterObservation() {
140 aurelien 711
 
712
		if(departement.equals("000null") || departement.equals("")) {
713
			String[] depCom = commune.getText().split(" ");
714
			if(depCom.length > 1) {
715
				String dep = depCom[1].replace('(', ' ');
716
				dep =dep.replace(')', ' ');
717
				dep = dep.trim();
718
				dep = dep.replace('\\',' ');
719
				dep = dep.trim();
720
 
721
				try
722
				{
723
					int nDep = Integer.parseInt(dep);
724
					if(nDep > 0 && nDep < 110) {
725
						departement = dep ;
726
					}
727
				}
728
				catch(NumberFormatException e)
729
				{
730
					departement = "" ;
731
				}
732
			}
733
		}
39 david 734
 
120 aurelien 735
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getRawValue());
46 david 736
		observationMediateur.ajouterObservation(obs);
39 david 737
	}
12 david 738
 
71 jpm 739
	private void modifierObservation() {
740
 
120 aurelien 741
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getRawValue());
79 david 742
		obs.setNumeroOrdre(numeroOrdre);
743
		observationMediateur.modifierObservation(obs);
74 david 744
 
71 jpm 745
	}
77 jpm 746
 
747
	private void supprimerObservation() {
748
 
749
			observationMediateur.supprimerObservation(this, numeroOrdre);
750
	}
12 david 751
 
71 jpm 752
 
753
	public void afficherDetailsObservation(Observation obs)
754
	{
104 jpm 755
		raz() ;
140 aurelien 756
		char g ;
71 jpm 757
 
140 aurelien 758
		String idLoc =obs.getIdentifiantLocalite().replaceAll(" ","/");
759
		idLoc = idLoc.replaceAll("%","");
760
		idLoc = idLoc.replaceAll("\"","");
761
		idLoc = idLoc.replace('\\',' ');
762
		idLoc = idLoc.trim();
763
 
71 jpm 764
		if(!obs.getDate().equals("null") && !obs.getDate().equals("000null")) {
765
			String[] dateEtHeure = obs.getDate().split(" ", 2);
110 aurelien 766
			if(verifierFormatDate(dateEtHeure[0])) {
767
				date.setValue(dateEtHeure[0]) ;
768
			}
769
			else
770
			{
771
				date.setRawValue("");
772
			}
71 jpm 773
		}
774
		if(!obs.getLieudit().equals("null") && !obs.getLieudit().equals("000null")) {
775
			lieudit.setValue(obs.getLieudit()) ;
776
		}
777
		if(!obs.getStation().equals("null") && !obs.getStation().equals("000null")) {
778
			station.setValue(obs.getStation()) ;
779
		}
780
		if(!obs.getMilieu().equals("null") && !obs.getMilieu().equals("000null")) {
781
			milieu.setValue(obs.getMilieu()) ;
782
		}
783
		if(!obs.getCommentaire().equals("null") && !obs.getCommentaire().equals("000null")) {
784
			comment.setValue(obs.getCommentaire()) ;
785
		}
786
		if(!obs.getLocalite().equals("null") && !obs.getLocalite().equals("000null")) {
140 aurelien 787
			if(!idLoc.equals("000null")) {
788
				commune.setValue(obs.getLocalite()+" ("+idLoc+")") ;
789
			}
790
			else
791
			{
792
				commune.setValue(obs.getLocalite());
793
			}
71 jpm 794
		}
795
		if(!obs.getIdentifiantLocalite().equals("null") && !obs.getIdentifiantLocalite().equals("000null")) {
140 aurelien 796
			departement = idLoc;
71 jpm 797
		}
798
		if(!obs.getNomSaisi().equals("null") && !obs.getNomSaisi().equals("000null")) {
799
			espece.setValue(obs.getNomSaisi()) ;
800
		}
801
		if(!obs.getNumeroNomenclaturalSaisi().equals("null") && !obs.getNumeroNomenclaturalSaisi().equals("000null")) {
802
			numeroNom = obs.getNumeroNomenclaturalSaisi() ;
803
		}
83 david 804
		if(!obs.getNumeroOrdre().equals("null") && !obs.getNumeroOrdre().equals("000nu2ll")) {
74 david 805
			numeroOrdre = obs.getNumeroOrdre() ;
806
		}
807
 
71 jpm 808
	}
809
 
118 david 810
 
104 jpm 811
	public void raz()
71 jpm 812
	{
118 david 813
		raz(Champs.TOUT);
814
 
815
	}
816
	public void raz(Champs champs)
817
	{
818
		switch (champs) {
819
 
820
 
821
			case DATE:
822
				date.reset() ;
823
				break;
824
 
825
			case LIEUDIT:
826
				lieudit.reset() ;
827
				break;
828
 
829
			case STATION:
830
				station.reset() ;
831
				break;
832
 
833
			case MILIEU:
834
				milieu.reset() ;
835
				break;
836
 
837
			case COMMENT:
838
				comment.reset() ;
839
				break;
840
 
841
 
842
			case COMMUNE:
843
				milieu.reset() ;
844
				departement ="";
845
				break;
846
 
847
			case ESPECE:
848
				espece.reset();
849
				numeroNom = "" ;
850
				numeroOrdre = "";
851
				break;
852
 
853
			case TOUT:
132 aurelien 854
				commune.reset();
118 david 855
				date.reset() ;
856
				lieudit.reset() ;
857
				station.reset() ;
858
				milieu.reset() ;
859
				comment.reset() ;
860
				milieu.reset() ;
861
				departement ="";
862
				espece.reset();
863
				numeroNom = "" ;
864
				numeroOrdre = "";
865
				break;
866
 
867
		}
71 jpm 868
 
869
	}
870
 
871
	private void setModification(String mode)
872
	{
873
		if(mode.equals("true")) {
874
 
875
			boutonOK.setText("Modifier") ;
876
			setTitle("Modification") ;
77 jpm 877
			boutonAnnuler.setText("Supprimer") ;
71 jpm 878
			modification = true ;
97 jpm 879
			selecteurMode.removeClass("x-selec-crea") ;
880
			selecteurMode.setCls("x-selec-modif") ;
94 jpm 881
 
71 jpm 882
		}
883
		else
884
		{
885
 
120 aurelien 886
			boutonOK.setText("Ajouter") ;
71 jpm 887
			setTitle("Saisir") ;
77 jpm 888
			boutonAnnuler.setText("Réinitialiser") ;
71 jpm 889
			modification = false ;
97 jpm 890
			selecteurMode.removeClass("x-selec-modif") ;
891
			selecteurMode.setCls("x-selec-crea") ;
94 jpm 892
 
132 aurelien 893
		}
71 jpm 894
	}
895
 
896
	/**
897
	 * renvoie vrai si on est en mode modification, faux si on est en mode création
898
	 * @return
899
	 */
900
	public boolean getModification()
901
	{
902
		return modification ;
903
	}
110 aurelien 904
 
905
	public boolean verifierFormatDate(String date) {
906
 
132 aurelien 907
		String regex = "[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}" ;
110 aurelien 908
		if(date.matches(regex) && !date.equals("0000-00-00")) {
909
			return true ;
910
		}
911
		else {
912
			return false;
913
		}
914
	}
132 aurelien 915
 
916
	private void ajusterTailleChamps() {
917
 
918
		int tailleChamps = (this.getInnerWidth()/100)*40;
919
 
920
		this.tailleChamps = tailleChamps ;
921
 
922
		commune.setWidth(tailleChamps);
923
		station.setWidth(tailleChamps);
924
		espece.setWidth(tailleChamps);
925
		lieudit.setWidth(tailleChamps);
926
		milieu.setWidth(tailleChamps);
927
		comment.setWidth(tailleChamps);
71 jpm 928
 
132 aurelien 929
	}
930
 
12 david 931
}