Subversion Repositories eFlore/Applications.cel

Rev

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