Subversion Repositories eFlore/Applications.cel

Rev

Rev 195 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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