Subversion Repositories eFlore/Applications.cel

Rev

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