Subversion Repositories eFlore/Applications.cel

Rev

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