Subversion Repositories eFlore/Applications.cel

Rev

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