Subversion Repositories eFlore/Applications.cel

Rev

Rev 246 | 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
 
221 aurelien 5
import java.util.Date;
13 david 6
import java.util.Iterator;
7
 
8
import org.tela_botanica.client.interfaces.Rafraichissable;
248 aurelien 9
import org.tela_botanica.client.modeles.EntiteGeographiqueObservation;
216 aurelien 10
import org.tela_botanica.client.modeles.ListeObservation;
13 david 11
import org.tela_botanica.client.modeles.ListeReferentielCommune;
20 david 12
import org.tela_botanica.client.modeles.ListeReferentielNom;
39 david 13
import org.tela_botanica.client.modeles.Observation;
13 david 14
import org.tela_botanica.client.modeles.ReferentielCommune;
20 david 15
import org.tela_botanica.client.modeles.ReferentielNom;
12 david 16
import org.tela_botanica.client.observation.ObservationMediateur;
132 aurelien 17
 
221 aurelien 18
import com.google.gwt.core.client.JavaScriptObject;
248 aurelien 19
import com.google.gwt.maps.client.geom.LatLng;
216 aurelien 20
import com.google.gwt.user.client.Window;
248 aurelien 21
import com.google.gwt.user.client.ui.HTML;
13 david 22
import com.gwtext.client.core.EventCallback;
23
import com.gwtext.client.core.EventObject;
218 david 24
import com.gwtext.client.core.Ext;
248 aurelien 25
import com.gwtext.client.core.ExtElement;
13 david 26
import com.gwtext.client.core.ListenerConfig;
12 david 27
import com.gwtext.client.core.Position;
13 david 28
import com.gwtext.client.data.ArrayReader;
29
import com.gwtext.client.data.FieldDef;
30
import com.gwtext.client.data.MemoryProxy;
31
import com.gwtext.client.data.RecordDef;
71 jpm 32
import com.gwtext.client.data.SimpleStore;
13 david 33
import com.gwtext.client.data.Store;
34
import com.gwtext.client.data.StringFieldDef;
132 aurelien 35
import com.gwtext.client.widgets.BoxComponent;
12 david 36
import com.gwtext.client.widgets.Button;
221 aurelien 37
import com.gwtext.client.widgets.Component;
132 aurelien 38
import com.gwtext.client.widgets.Container;
221 aurelien 39
import com.gwtext.client.widgets.DatePicker;
12 david 40
import com.gwtext.client.widgets.Panel;
248 aurelien 41
import com.gwtext.client.widgets.ToolTip;
71 jpm 42
import com.gwtext.client.widgets.Toolbar;
230 david 43
import com.gwtext.client.widgets.Viewport;
132 aurelien 44
import com.gwtext.client.widgets.event.BoxComponentListenerAdapter;
20 david 45
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
132 aurelien 46
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
221 aurelien 47
import com.gwtext.client.widgets.event.DatePickerListener;
48
import com.gwtext.client.widgets.event.DatePickerListenerAdapter;
201 david 49
import com.gwtext.client.widgets.event.PanelListenerAdapter;
13 david 50
import com.gwtext.client.widgets.form.ComboBox;
12 david 51
import com.gwtext.client.widgets.form.DateField;
216 aurelien 52
import com.gwtext.client.widgets.form.Field;
12 david 53
import com.gwtext.client.widgets.form.FormPanel;
248 aurelien 54
import com.gwtext.client.widgets.form.MultiFieldPanel;
128 aurelien 55
import com.gwtext.client.widgets.form.TextArea;
12 david 56
import com.gwtext.client.widgets.form.TextField;
13 david 57
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
248 aurelien 58
import com.gwtext.client.widgets.form.event.TextFieldListenerAdapter;
201 david 59
import com.gwtext.client.widgets.layout.AnchorLayoutData;
12 david 60
import com.gwtext.client.widgets.layout.ColumnLayout;
61
import com.gwtext.client.widgets.layout.ColumnLayoutData;
62
import com.gwtext.client.widgets.layout.FormLayout;
230 david 63
import com.gwtext.client.widgets.layout.RowLayout;
13 david 64
import com.gwtext.client.data.Record;
12 david 65
 
66
/**
67
 * Panneau contenant les infos, les métadonnées et l'arbre des mots clés, il implémente l'interface rafraichissable
68
 * @author aurelien
69
 *
70
 */
13 david 71
public class FormulaireSaisieObservationVue extends Panel implements Rafraichissable  {
12 david 72
 
73
 
74
	/**
75
	 * Le médiateur associé à la vue
76
	 */
77
	private ObservationMediateur	observationMediateur		= null;
78
 
205 aurelien 79
	FormPanel panneauFormulaire = null;
20 david 80
 
13 david 81
	private DateField date = null;
12 david 82
	private TextField lieudit = null;
83
	private TextField station = null;
84
	private TextField milieu = null;
85
	private TextField comment = null;
13 david 86
	private ComboBox  commune = null;
39 david 87
	private String departement = null;
20 david 88
	private ComboBox  espece = null;
39 david 89
	private String numeroNom = null;
74 david 90
	private String numeroOrdre = null;
20 david 91
 
118 david 92
	// Pour remise a zero partielle lors d'une validation
93
 
94
	private  enum Champs {
216 aurelien 95
	    DATE, LIEUDIT, STATION, MILIEU, COMMENT, COMMUNE, ESPECE, TOUT ;
96
 
97
	    public String toString() {
98
 
99
	    	switch(this) {
100
	    	case DATE:
101
	    		return "date";
102
 
103
	    	case COMMUNE:
104
	    		return "commune";
105
 
106
    		case LIEUDIT:
107
    			return "lieu dit";
108
 
109
    		case STATION:
110
    			return "station";
111
 
112
    		case MILIEU:
113
    			return "milieu";
114
 
115
    		case COMMENT:
116
    			return "commentaire";
117
 
118
	    	case ESPECE:
119
	    		return "espèce";
120
 
121
	    	case TOUT:
122
	    		return "date, commune, lieu dit, station, milieu, espèce, commentaire";
123
	    	}
124
			return TOUT.toString();
125
	    }
118 david 126
	};
127
 
110 aurelien 128
	private String formatDate = null ;
71 jpm 129
	private Button boutonOK = new Button("Créer");
77 jpm 130
	private Button boutonAnnuler = new Button("Réinitialiser");
20 david 131
 
13 david 132
	private boolean selectionCommune=false;
20 david 133
	private boolean selectionEspece=false;
12 david 134
 
71 jpm 135
	private boolean modification = false ;
136
	private Toolbar bt = null ;
13 david 137
 
216 aurelien 138
	private final String VALEURS_MULTIPLES = "(Valeurs multiples)";
221 aurelien 139
	private final String modeleMessageModif = "commune:lieu-dit:station:milieu:date:espece:commentaire";
216 aurelien 140
	private boolean communeModifiee = false;
221 aurelien 141
	private boolean lieuDitModifie = false;
142
	private boolean stationModifiee = false;
216 aurelien 143
	private boolean milieuModifie = false;
144
	private boolean dateModifiee = false;
145
	private boolean especeModifiee = false;
146
	private boolean commModifie = false;
147
 
148
 
20 david 149
	private final int KEY_ALT = 18;
150
	private final int KEY_BACKSPACE = 8;
151
	private final int KEY_CTRL = 17;
152
	private final int KEY_DELETE = 46;
153
	private final int KEY_DOWN = 40;
154
	private final int KEY_END = 35;
155
	private final int KEY_ENTER = 13;
156
	private final int KEY_ESCAPE = 27;
157
	private final int KEY_HOME = 36;
158
	private final int KEY_LEFT = 37;
159
	private final int KEY_PAGEDOWN = 34;
160
	private final int KEY_PAGEUP = 33;
161
	private final int KEY_RIGHT = 39;
162
	private final int KEY_SHIFT = 16;
163
	private final int KEY_TAB = 9;
164
	private final int KEY_UP = 38;
13 david 165
 
128 aurelien 166
 
71 jpm 167
	/**
168
	 * Combobox permettant de selectionner le mode
169
	 * modification ou bien création
170
	 */
171
	private ComboBox selecteurMode = new ComboBox();
13 david 172
 
71 jpm 173
	Store storeMode = null ;
13 david 174
 
12 david 175
	/**
176
	 * Booleen d'instanciation
177
	 */
178
	boolean estInstancie = false ;
205 aurelien 179
 
180
	private Panel panneauIntermediaire;
181
 
182
	private Panel panneauPremierColonne;
183
 
184
	private Panel panneauSecondeColonne;
216 aurelien 185
 
186
	private boolean masseModification =false ;
248 aurelien 187
 
188
	private TextField longitude;
189
 
190
	private TextField latitude;
191
 
192
	private MultiFieldPanel coordPanel;
193
 
194
	private TextField coordonnees;
195
 
196
	private HTML accesformulaire;
197
 
198
	private HTML basculerverscarto;
12 david 199
 
248 aurelien 200
	private boolean longlatAjoutee;
201
 
12 david 202
	/**
203
	 * Constructeur sans argument (privé car ne doit pas être utilisé)
204
	 */
71 jpm 205
	@SuppressWarnings("unused")
12 david 206
	private FormulaireSaisieObservationVue()
207
	{
208
		super() ;
209
	}
210
 
211
	/**
212
	 * Constructeur avec argument
213
	 * @param im
214
	 */
215
	public FormulaireSaisieObservationVue(ObservationMediateur obs)
216
	{
246 aurelien 217
 
218
		super("Saisie");
12 david 219
		// on associe le médiateur
220
		observationMediateur = obs ;
221
 
201 david 222
 
205 aurelien 223
		panneauFormulaire = new FormPanel(Position.RIGHT);
12 david 224
		panneauFormulaire.setBorder(false);
225
 
218 david 226
 
227
 
12 david 228
		// Panneau intermediaire qui contient deux colonnes de formulaire
229
 
205 aurelien 230
		panneauIntermediaire = new Panel();
230 david 231
 
232
		if (Window.getClientWidth()> Window.getClientHeight()) {
233
			panneauIntermediaire.setLayout(new ColumnLayout());
234
		}
235
		else {
236
			panneauIntermediaire.setLayout(new RowLayout());
237
		}
238
 
12 david 239
		panneauIntermediaire.setBorder(false);
218 david 240
 
241
		if (Ext.isIE6()) {
242
			panneauIntermediaire.setWidth(800);
243
		}
244
 
12 david 245
		//create first panel and add fields to it
205 aurelien 246
		panneauPremierColonne = new Panel();
12 david 247
		panneauPremierColonne.setLayout(new FormLayout());
248
		panneauPremierColonne.setBorder(false);
249
 
250
		//create second panel and add fields to it
205 aurelien 251
	    panneauSecondeColonne = new Panel();
12 david 252
		panneauSecondeColonne.setLayout(new FormLayout());
253
		panneauSecondeColonne.setBorder(false);
42 jpm 254
 
255
		this.setPaddings(5) ;
12 david 256
 
195 david 257
		// Accesskey pour debugging
258
 
201 david 259
		commune=new ComboBox("Commune","commune\" accesskey=\"1");
195 david 260
 
20 david 261
		final String resultTplCommune = "<div class=\"search-item-commune\">{commune}</div>";
262
		commune.setTpl(resultTplCommune);
13 david 263
		commune.setMode(ComboBox.REMOTE);
264
		// commune.setPageSize(10); // Ne fonctionne pas
20 david 265
		commune.setItemSelector("div.search-item-commune");
13 david 266
		commune.setTypeAhead(true);
267
		commune.setLoadingText("Recherche...");
268
 
269
		commune.setHideTrigger(true);
248 aurelien 270
		//commune.setTabIndex(1);
13 david 271
 
201 david 272
	    panneauPremierColonne.add(commune, new AnchorLayoutData("95%"));
13 david 273
 
201 david 274
	    station = new TextField("Station", "station");
132 aurelien 275
	    station.setAllowBlank(true);
248 aurelien 276
	    //station.setTabIndex(3);
201 david 277
	    panneauPremierColonne.add(station, new AnchorLayoutData("95%"));
12 david 278
 
248 aurelien 279
	    longitude = new TextField("X", "x", 100);
280
		longitude.setAllowBlank(true);
281
 
282
		latitude = new TextField("Y", "y", 100);
283
		latitude.setAllowBlank(true);
284
 
285
		// Panneau de type plusieurs champs de formulaire sur une meme ligne, où seront renseignés X/Y
286
		coordPanel = new MultiFieldPanel();
287
		coordPanel.setVisible(false);
288
		coordPanel.addToRow(longitude, new ColumnLayoutData(0.5));
289
		coordPanel.addToRow(latitude, new ColumnLayoutData(0.5));
290
		coordPanel.setBorder(false);
291
 
292
		  //création du champs coordonnées
293
 
294
		coordonnees = new TextField("Coordonnées", "", 0);
295
		coordonnees.setMaxLength(0);
296
		coordonnees.setReadOnly(true);
297
		coordonnees.setCls("fieldname");
298
 
299
		  //création du lien "saisie X/Y" dans le formulaire
300
 
301
		accesformulaire = new HTML("<a id=\"lien_coord\" href=\"#\" tabindex=\"7\">Saisie X/Y</a>");
302
		accesformulaire.addStyleName("lien");
303
 
304
		//création info bulle sur le lien "saisie X/Y"
305
			ToolTip tip1 = new ToolTip();
306
			tip1.setHtml("X / Y sont les longitudes / latitudes, à remplir en degrés décimaux");
307
			tip1.applyTo(accesformulaire.getElement());
308
 
309
			//ajout d'un listener sur le lien "saisie X/Y"
310
 
311
			coordPanel.addListener(new PanelListenerAdapter() {
312
 
313
				public void onAfterLayout(Container c) {
314
					ExtElement lienCoord = Ext.get("lien_coord");
315
					lienCoord.removeAllListeners();
316
					lienCoord.addListener("click", new EventCallback() {
317
						public void execute(EventObject e) {
318
							coordPanel.setVisible(!coordPanel.isVisible());
319
						}
320
					}) ;
321
 
322
					ExtElement lienCarto = Ext.get("lien_carto");
323
					lienCarto.removeAllListeners();
324
					lienCarto.addListener("click", new EventCallback() {
325
 
326
						public void execute(EventObject e) {
327
 
328
							if(coordonneesValides() == null) {
329
								if(commune.getValue() != null && !commune.getValue().equals("")) {
330
									obtenirInformationCommune();
331
									longlatAjoutee = true;
332
 
333
								} else {
334
									Window.alert("Veuillez renseigner au moins une commune ou des coordonnées pour la géolocalisation");
335
								}
336
							} else {
337
								obtenirInformationCoord();
338
							}
339
						}
340
					});
341
				}
342
 
343
			});
344
 
345
 
346
			  //création du lien "Accès carto" dans le formulaire
347
			basculerverscarto = new HTML(" <a id=\"lien_carto\" href=\"#\" tabindex=\"6\">Selection depuis la carto</a>");
348
			basculerverscarto.addStyleName("lien");
349
 
350
			//création info bulle sur le lien "accès carto"
351
			ToolTip tip2 = new ToolTip();
352
			tip2.setHtml("Via une carte, obtenez les coordonnées (longitude/latitude) de votre observation ");
353
			tip2.applyTo(basculerverscarto.getElement());
354
 
355
			//Sur une meme ligne, ajout de plusieurs champs
356
			final MultiFieldPanel htmlPanel = new MultiFieldPanel();
357
			htmlPanel.addToRow(coordonnees, 100);
358
			htmlPanel.addToRow(basculerverscarto, new ColumnLayoutData(0.5));
359
			htmlPanel.addToRow(accesformulaire, new ColumnLayoutData(0.5));
360
			htmlPanel.setBorder(false);
361
			htmlPanel.setId("x-coord-panel");
362
 
363
		panneauPremierColonne.add(htmlPanel);
364
		panneauPremierColonne.add(coordPanel);
365
 
12 david 366
	    date = new DateField("Date", "date", 100);
367
	    date.setAllowBlank(true);
110 aurelien 368
	    formatDate = "d/m/Y";
369
	    date.setFormat(formatDate) ;
248 aurelien 370
	    //date.setTabIndex(5);
201 david 371
	    panneauPremierColonne.add(date, new AnchorLayoutData("60%"));
20 david 372
 
373
 
201 david 374
		espece=new ComboBox("Espèce","nom");
12 david 375
 
20 david 376
 
377
		final String resultTplEspece = "<div class=\"search-item-espece\">{nom}</div>";
378
 
379
 
380
		espece.setTpl(resultTplEspece);
381
		espece.setMode(ComboBox.REMOTE);
382
		// commune.setPageSize(10); // Ne fonctionne pas
383
		espece.setItemSelector("div.search-item-espece");
384
		espece.setTypeAhead(true);
385
		espece.setLoadingText("Recherche...");
386
 
387
		espece.setHideTrigger(true);
248 aurelien 388
		//espece.setTabIndex(6);
20 david 389
 
201 david 390
	    panneauPremierColonne.add(espece, new AnchorLayoutData("95%"));
20 david 391
 
201 david 392
	    lieudit = new TextField("Lieu-dit", "lieudit");
132 aurelien 393
	    lieudit.setAllowBlank(true);
248 aurelien 394
	    //lieudit.setTabIndex(2);
201 david 395
	    panneauSecondeColonne.add(lieudit,  new AnchorLayoutData("95%"));
12 david 396
 
397
 
201 david 398
	    milieu = new TextField("Milieu", "milieu");
132 aurelien 399
	    milieu.setAllowBlank(true);
248 aurelien 400
	    //milieu.setTabIndex(4);
201 david 401
	    panneauSecondeColonne.add(milieu,  new AnchorLayoutData("95%"));
128 aurelien 402
 
403
	    comment = new TextArea("Notes", "comment");
404
	    comment.setAllowBlank(true);
405
	    comment.setHeight(50);
248 aurelien 406
	    //comment.setTabIndex(7);
201 david 407
	    panneauSecondeColonne.add(comment, new AnchorLayoutData("95%") );
12 david 408
 
230 david 409
 
410
 
411
 
412
	    if (Window.getClientWidth()> Window.getClientHeight()) {
413
			panneauIntermediaire.add(panneauPremierColonne, new ColumnLayoutData(.5));
414
			panneauIntermediaire.add(panneauSecondeColonne, new ColumnLayoutData(.5));
415
	    }
416
	    else {
417
			panneauIntermediaire.add(panneauPremierColonne);
418
			panneauIntermediaire.add(panneauSecondeColonne);
419
 
420
	    }
421
 
12 david 422
		panneauFormulaire.add(panneauIntermediaire);
423
 
71 jpm 424
		Object[][] mode = {{"création",false} , {"modification", true} };
425
		storeMode = new SimpleStore(new String[] { "nom_mode", "mode" },
426
				mode);
427
		storeMode.load();
428
		selecteurMode.setStore(storeMode);
429
		selecteurMode.setDisplayField("nom_mode") ;
430
		selecteurMode.setLabel("mode ") ;
431
		selecteurMode.setForceSelection(true) ;
432
		selecteurMode.setValue("création") ;
433
		selecteurMode.setEditable(false) ;
97 jpm 434
		selecteurMode.setCls("x-selec-crea") ;
71 jpm 435
 
436
		bt = new Toolbar() ;
437
		bt.addSpacer() ;
438
		bt.addText("Mode de saisie ") ;
439
		bt.addField(selecteurMode) ;
440
 
132 aurelien 441
		boutonOK.setTabIndex(8);
442
		boutonAnnuler.setTabIndex(9);
74 david 443
 
71 jpm 444
 
218 david 445
		if (Ext.isIE6()) {
446
			panneauPremierColonne.setButtonAlign(Position.RIGHT);
447
			panneauPremierColonne.addButton(boutonOK);
448
			panneauSecondeColonne.setButtonAlign(Position.LEFT);
449
			panneauSecondeColonne.addButton(boutonAnnuler);
450
		}
451
		else {
452
 
453
			panneauFormulaire.addButton(boutonOK);
454
			panneauFormulaire.addButton(boutonAnnuler);
455
		}
456
 
457
 
71 jpm 458
		selecteurMode.addListener(new ComboBoxListenerAdapter() {
459
 
460
			public void onSelect(ComboBox comboBox, Record record, int index) {
461
 
462
				// et on met la valeur à jour dans la combobox
463
				comboBox.setValue(record.getAsString("nom_mode"));
464
				setModification(record.getAsString("mode")) ;
465
			}
466
 
467
		});
12 david 468
 
469
		this.add(panneauFormulaire) ;
80 jpm 470
		this.setTopToolbar(bt) ;
12 david 471
 
120 aurelien 472
		this.setAutoScroll(true);
12 david 473
 
474
 
201 david 475
 
476
		panneauFormulaire.addListener(new PanelListenerAdapter() {
477
	        public void onResize(BoxComponent component, int adjWidth, int adjHeight, int rawWidth, int rawHeight) {
478
	        	panneauIntermediaire.setWidth(rawWidth);
479
	        	panneauIntermediaire.setHeight(rawHeight);
480
	     }});
481
 
12 david 482
		// on ajoute les listeners
201 david 483
 
484
 
12 david 485
		ajouterListeners() ;
486
 
248 aurelien 487
		saisieTabindex();
488
 
12 david 489
	}
490
 
491
	private void ajouterListeners()
94 jpm 492
	{
20 david 493
		// Listener completion communne
494
 
495
		   commune.addListener(new ComboBoxListenerAdapter() {
496
	             public void onSelect(ComboBox comboBox, Record record, int index) {
497
	                 commune.setValue(record.getAsString("commune"));
39 david 498
	                 departement=record.getAsString("departement");
20 david 499
	                 selectionCommune=true;
500
	             }
501
	         });
502
 
503
 
504
			ListenerConfig listenerConfigCommune=new ListenerConfig();
505
			listenerConfigCommune.setDelay(10);
506
			listenerConfigCommune.setStopPropagation(false);
507
			listenerConfigCommune.setStopEvent(false);
508
 
509
		    commune.addKeyPressListener(new EventCallback()	{
510
 
120 aurelien 511
	    	    public void execute(EventObject e) {
512
 
513
 
514
	    	    		switch(e.getKey()) {
515
 
132 aurelien 516
    	    				case KEY_ALT:
517
	    	    	        case KEY_CTRL:
518
	    	    	        case KEY_DOWN:
519
	    	    	        case KEY_END:
520
	    	    	        case KEY_ESCAPE:
521
	    	    	        case KEY_HOME:
522
	    	    	        case KEY_LEFT:
523
	    	    	        case KEY_PAGEDOWN:
524
	    	    	        case KEY_PAGEUP:
525
	    	    	        case KEY_RIGHT:
526
	    	    	        case KEY_SHIFT:
527
	    	    	        case KEY_TAB:
528
	    	    	        case KEY_UP:
529
 
530
	    	    	        break;
531
 
120 aurelien 532
	    	    	    	case KEY_ENTER:
533
 
20 david 534
		    	    	    	 if (selectionCommune) {
216 aurelien 535
		    	    	    		 communeModifiee= true;
20 david 536
		    	    	    		 selectionCommune=false;
537
		    	    	    	 }
120 aurelien 538
		    	    	    	else {
539
 
118 david 540
		    	    	    		validerSaisie(Champs.COMMUNE);
20 david 541
		    	    	    		// lancer mise a jour
542
		    	    	    	 }
120 aurelien 543
		    	    	    break;
544
 
545
		    	    	    default:
20 david 546
 
83 david 547
		    	    	    	  departement="";
20 david 548
		    	    	    	  obtenirListeReferentielCommune();
216 aurelien 549
		    	    	    	  communeModifiee= true;
20 david 550
 
120 aurelien 551
		    	    	    break;
552
	    	    	    }
553
	     			}
554
	    		},    listenerConfigCommune
20 david 555
			);
556
 
120 aurelien 557
		    date.addKeyPressListener(new EventCallback() {
20 david 558
 
120 aurelien 559
				public void execute(EventObject e) {
560
					// TODO Auto-generated method stub
561
					switch(e.getKey()) {
221 aurelien 562
 
563
						case KEY_ALT:
564
		    	        case KEY_CTRL:
565
		    	        case KEY_DOWN:
566
		    	        case KEY_END:
567
		    	        case KEY_ESCAPE:
568
		    	        case KEY_HOME:
569
		    	        case KEY_LEFT:
570
		    	        case KEY_PAGEDOWN:
571
		    	        case KEY_PAGEUP:
572
		    	        case KEY_RIGHT:
573
		    	        case KEY_SHIFT:
574
		    	        case KEY_TAB:
575
		    	        	if(date.getRawValue().equals(VALEURS_MULTIPLES)) {
576
		    	        		date.clearInvalid();
577
		    	        	}
578
		    	        case KEY_UP:
579
 
580
		    	        break;
120 aurelien 581
 
221 aurelien 582
	  	    	      case KEY_ENTER:
583
	  	    	    		validerSaisie(Champs.DATE);
120 aurelien 584
	  	    	    	  break;
585
 
586
	  	    	      default:
221 aurelien 587
	  					dateModifiee = true;
120 aurelien 588
					}
589
				}
590
		    });
591
 
221 aurelien 592
		    date.addListener(new DatePickerListenerAdapter() {
593
 
594
				public void onSelect(DatePicker dataPicker, Date date) {
595
					dateModifiee = true;
596
				}
597
		    });
598
 
120 aurelien 599
		    station.addKeyPressListener(new EventCallback() {
600
 
601
				public void execute(EventObject e) {
602
					// TODO Auto-generated method stub
603
					switch(e.getKey()) {
604
 
221 aurelien 605
						case KEY_ALT:
606
		    	        case KEY_CTRL:
607
		    	        case KEY_DOWN:
608
		    	        case KEY_END:
609
		    	        case KEY_ESCAPE:
610
		    	        case KEY_HOME:
611
		    	        case KEY_LEFT:
612
		    	        case KEY_PAGEDOWN:
613
		    	        case KEY_PAGEUP:
614
		    	        case KEY_RIGHT:
615
		    	        case KEY_SHIFT:
616
		    	        case KEY_TAB:
617
		    	        case KEY_UP:
618
		    	      break;
619
 
120 aurelien 620
	  	    	      case KEY_ENTER:
621
	  	    	    		validerSaisie(Champs.STATION);
622
	  	    	    	  break;
623
 
624
	  	    	      default:
221 aurelien 625
	  	    	    	  stationModifiee = true;
120 aurelien 626
					}
627
				}
628
		    });
629
 
630
 
20 david 631
 
120 aurelien 632
			// Listener completion espece
20 david 633
			espece.addListener(new ComboBoxListenerAdapter() {
634
	             public void onSelect(ComboBox comboBox, Record record, int index) {
635
	            	 espece.setValue(record.getAsString("nom"));
39 david 636
	            	 numeroNom=record.getAsString("numeroNom");
20 david 637
	                 selectionEspece=true;
128 aurelien 638
	                 observationMediateur.obtenirImageInformationExternes(numeroNom);
20 david 639
	             }
640
	         });
641
 
642
 
643
			ListenerConfig listenerConfigEspece=new ListenerConfig();
644
			listenerConfigEspece.setDelay(10);
645
			listenerConfigEspece.setStopPropagation(false);
646
			listenerConfigEspece.setStopEvent(false);
647
 
648
 
649
			espece.addKeyPressListener(new EventCallback()	{
650
 
651
		    	    public void execute(EventObject e) {
652
 
653
 
654
		    	    		  switch(e.getKey()) {
655
 
656
 
657
		    	    		  case KEY_ALT:
658
		    	    	      case KEY_CTRL:
659
		    	    	      case KEY_DOWN:
660
		    	    	      case KEY_END:
661
		    	    	      case KEY_ESCAPE:
662
		    	    	      case KEY_HOME:
663
		    	    	      case KEY_LEFT:
664
		    	    	      case KEY_PAGEDOWN:
665
		    	    	      case KEY_PAGEUP:
666
		    	    	      case KEY_RIGHT:
667
		    	    	      case KEY_SHIFT:
668
		    	    	      case KEY_TAB:
669
		    	    	      case KEY_UP:
670
 
671
		    	    	        break;
672
 
673
		    	    	      case KEY_ENTER:
674
 
140 aurelien 675
			    	    	    	if(selectionEspece) {
216 aurelien 676
			    	    	    		especeModifiee = true;
677
			    	    	    		selectionEspece=false;
140 aurelien 678
			    	    	    	}
679
			    	    	    	else {
680
			    	    	    		validerSaisie(Champs.ESPECE);
681
			    	    	    	}
20 david 682
 
683
		    	    	    	  break;
684
 
685
		    	    	      default:
686
 
83 david 687
		    	    	    	  numeroNom="";
20 david 688
		    	    	    	  obtenirListeReferentielNom();
216 aurelien 689
		    	    	    	  especeModifiee = true;
20 david 690
 
691
		    	    	        break;
692
		    	    	    }
693
 
694
 
695
 
696
		     		}
697
 
698
		    		},    listenerConfigEspece
699
 
700
			);
701
 
120 aurelien 702
			lieudit.addKeyPressListener(new EventCallback() {
20 david 703
 
120 aurelien 704
				public void execute(EventObject e) {
705
					// TODO Auto-generated method stub
706
					switch(e.getKey()) {
707
 
221 aurelien 708
					case KEY_ALT:
709
	  	    	      case KEY_CTRL:
710
	  	    	      case KEY_DOWN:
711
	  	    	      case KEY_END:
712
	  	    	      case KEY_ESCAPE:
713
	  	    	      case KEY_HOME:
714
	  	    	      case KEY_LEFT:
715
	  	    	      case KEY_PAGEDOWN:
716
	  	    	      case KEY_PAGEUP:
717
	  	    	      case KEY_RIGHT:
718
	  	    	      case KEY_SHIFT:
719
	  	    	      case KEY_TAB:
720
	  	    	      case KEY_UP:
721
 
722
  	    	        break;
723
 
120 aurelien 724
	  	    	      case KEY_ENTER:
725
	  	    	    		validerSaisie(Champs.LIEUDIT);
726
	  	    	    	  break;
727
 
728
	  	    	      default:
221 aurelien 729
	  					lieuDitModifie = true;
120 aurelien 730
					}
731
				}
732
		    });
733
 
734
			milieu.addKeyPressListener(new EventCallback() {
735
 
736
				public void execute(EventObject e) {
737
					// TODO Auto-generated method stub
738
					switch(e.getKey()) {
221 aurelien 739
 
740
						case KEY_ALT:
741
	  	    	      case KEY_CTRL:
742
	  	    	      case KEY_DOWN:
743
	  	    	      case KEY_END:
744
	  	    	      case KEY_ESCAPE:
745
	  	    	      case KEY_HOME:
746
	  	    	      case KEY_LEFT:
747
	  	    	      case KEY_PAGEDOWN:
748
	  	    	      case KEY_PAGEUP:
749
	  	    	      case KEY_RIGHT:
750
	  	    	      case KEY_SHIFT:
751
	  	    	      case KEY_TAB:
752
	  	    	      case KEY_UP:
753
 
754
	  	    	        break;
120 aurelien 755
 
756
	  	    	      case KEY_ENTER:
757
	  	    	    		validerSaisie(Champs.MILIEU);
758
	  	    	    	  break;
759
 
760
	  	    	      default:
221 aurelien 761
	  					milieuModifie = true;
120 aurelien 762
					}
763
				}
764
		    });
765
 
216 aurelien 766
			comment.addKeyPressListener(new EventCallback() {
120 aurelien 767
 
768
				public void execute(EventObject e) {
221 aurelien 769
					switch(e.getKey()) {
770
						case KEY_ALT:
771
			    	      case KEY_CTRL:
772
			    	      case KEY_DOWN:
773
			    	      case KEY_END:
774
			    	      case KEY_ESCAPE:
775
			    	      case KEY_HOME:
776
			    	      case KEY_LEFT:
777
			    	      case KEY_PAGEDOWN:
778
			    	      case KEY_PAGEUP:
779
			    	      case KEY_RIGHT:
780
			    	      case KEY_SHIFT:
781
			    	      case KEY_TAB:
782
			    	      case KEY_UP:
783
 
784
		    	        break;
785
 
786
		    	        default:
787
						commModifie = true;
788
					}
120 aurelien 789
				}
216 aurelien 790
		    });
120 aurelien 791
 
20 david 792
 
793
 
794
		boutonOK.addListener(new ButtonListenerAdapter() {
39 david 795
 
20 david 796
			public void onClick(Button button, EventObject e) {
118 david 797
 
798
				if(modification) {
216 aurelien 799
					if(masseModification) {
800
							modifierObservationEnMasse(null);
801
					} else {
802
						modifierObservation() ;
803
					}
71 jpm 804
				}
118 david 805
				else {
71 jpm 806
					ajouterObservation();
807
				}
39 david 808
 
71 jpm 809
 
20 david 810
			}
811
 
812
		});
77 jpm 813
 
814
		boutonAnnuler.addListener(new ButtonListenerAdapter() {
12 david 815
 
816
			public void onClick(Button button, EventObject e) {
817
 
77 jpm 818
				if(modification)
819
				{
820
					supprimerObservation() ;
821
				}
822
				else
823
				{
104 jpm 824
					raz();
77 jpm 825
				}
12 david 826
 
77 jpm 827
 
828
			}
829
 
12 david 830
		});
132 aurelien 831
 
832
		this.addListener(new ContainerListenerAdapter() {
833
			public void onAfterLayout(Container self) {
834
				commune.focus();
835
			}
836
		});
837
 
12 david 838
	}
839
 
840
	/**
118 david 841
	 * Validation de la saisie
842
	 */
843
 
844
	private void validerSaisie(Champs champs) {
845
 
846
		if(modification) {
216 aurelien 847
			if(masseModification) {
848
					modifierObservationEnMasse(champs);
849
			} else {
850
				modifierObservation();
851
			}
852
 
853
			raz(champs);
118 david 854
		}
855
		else {
856
			ajouterObservation();
857
			raz(champs);
858
		}
859
	}
860
 
861
	/**
12 david 862
	 * Desactive visuellement ce panneau
863
	 */
864
	public void desactiverPanneau()
865
	{
866
		this.setDisabled(true) ;
867
	}
868
 
869
	/**
870
	 * Active visuellement ce panneau
871
	 */
872
	public void activerPanneau()
873
	{
874
		this.setDisabled(false) ;
875
	}
13 david 876
 
877
	public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
878
 
49 david 879
		// si l'on a reçu une liste du referentiel commune (completion referentiel commune)
13 david 880
			if(nouvelleDonnees instanceof ListeReferentielCommune)
881
			{
882
 
883
					ListeReferentielCommune data = (ListeReferentielCommune) nouvelleDonnees ;
884
					Object[][] communeData = new Object[data.size()][2];
885
					int i = 0 ;
886
 
887
					// on la parse et on récupère les informations quiç nous interessent
888
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
889
					{
890
 
891
						ReferentielCommune ref=(ReferentielCommune) data.get(it.next());
892
 
893
						communeData[i][0]= ref.getCommune();
894
						communeData[i][1]= ref.getDepartement();
895
 
896
 
897
						i++ ;
898
					}
899
 
900
					   //	  creation du store
901
					FieldDef defCommune = new StringFieldDef("commune");
902
					FieldDef defDepartement = new StringFieldDef("departement");
903
 
904
 
905
					FieldDef[] defTab = { defCommune, defDepartement};
906
 
907
					RecordDef rd = new RecordDef(defTab);
908
 
909
					final MemoryProxy dataProxy = new MemoryProxy(communeData);
910
					final ArrayReader reader = new ArrayReader(rd);
911
 
20 david 912
					Store store=new Store(dataProxy,reader);
13 david 913
					store.load() ;
914
 
132 aurelien 915
					commune.setStore(store);
248 aurelien 916
					commune.expand();
13 david 917
			}
20 david 918
 
94 jpm 919
			//			 si l'on a reçu une liste du référentiel nom (complétion referentiel nom)
20 david 920
 
921
			if(nouvelleDonnees instanceof ListeReferentielNom)
922
			{
923
 
924
					ListeReferentielNom data = (ListeReferentielNom) nouvelleDonnees ;
925
					Object[][] nomData = new Object[data.size()][2];
926
					int i = 0 ;
927
 
928
					// on la parse et on récupère les informations quiç nous interessent
929
					for (Iterator it = data.keySet().iterator(); it.hasNext();)
930
					{
931
 
932
						ReferentielNom ref=(ReferentielNom) data.get(it.next());
933
 
934
						nomData[i][0]= ref.getNom();
935
						nomData[i][1]= ref.getNumeroNom();
936
 
937
 
938
						i++ ;
939
					}
940
 
941
					   //	  creation du store
942
					FieldDef defNom = new StringFieldDef("nom");
943
					FieldDef defNumeroNom = new StringFieldDef("numeroNom");
944
 
945
 
946
					FieldDef[] defTab = { defNom, defNumeroNom};
947
 
948
					RecordDef rd = new RecordDef(defTab);
949
 
950
					final MemoryProxy dataProxy = new MemoryProxy(nomData);
951
					final ArrayReader reader = new ArrayReader(rd);
952
 
953
					Store store=new Store(dataProxy,reader);
954
					store.load() ;
955
 
956
					espece.setStore(store);
957
 
958
			}
959
 
82 david 960
			// On recoit une observation dont on veut afficher le detail
961
 
71 jpm 962
			if(nouvelleDonnees instanceof Observation)
963
			{
964
				Observation obs = (Observation)nouvelleDonnees ;
965
				afficherDetailsObservation(obs) ;
966
			}
77 jpm 967
 
216 aurelien 968
			if(nouvelleDonnees instanceof ListeObservation) {
969
				ListeObservation listeObs = (ListeObservation)nouvelleDonnees;
970
				calculerAfficherDifferences(listeObs);
971
			}
972
 
82 david 973
			// Sur Mise à jour ou suppression d'une suppression ?
974
 
77 jpm 975
			if(nouvelleDonnees instanceof String)
976
			{
977
				String str = (String)nouvelleDonnees ;
107 aurelien 978
				observationMediateur.obtenirNombreObservation() ;
77 jpm 979
			}
140 aurelien 980
 
981
			if(nouvelleDonnees instanceof String[]) {
982
				String[] anumNom = (String[])nouvelleDonnees ;
983
				numeroNom = anumNom[1];
984
				espece.setValue(anumNom[0]);
985
				setModification("false");
986
			}
248 aurelien 987
 
988
			if(nouvelleDonnees instanceof EntiteGeographiqueObservation)
989
			{
990
				EntiteGeographiqueObservation infosComm = (EntiteGeographiqueObservation)nouvelleDonnees ;
991
				rafraichirCommuneEtCoord(infosComm);
992
			}
20 david 993
 
13 david 994
	}
248 aurelien 995
 
996
 
997
	private void rafraichirCommuneEtCoord(EntiteGeographiqueObservation infosCom) {
998
 
999
		String nCommune = "";
1000
 
1001
 
1002
		if(infosCom.getLocation() != null && !infosCom.getLocation().equals("")) {
1003
			nCommune += infosCom.getLocation();
1004
		}
1005
 
1006
		if(infosCom.getIdLocation() != null && !infosCom.getIdLocation().equals("")) {
1007
			nCommune += " ("+infosCom.getIdLocation()+")";
1008
			departement = infosCom.getIdLocation();
1009
		}
1010
 
1011
		commune.setValue(nCommune);
1012
 
1013
		if(infosCom.getLat() != null && !infosCom.getLat().equals("")) {
1014
			latitude.setValue(infosCom.getLat());
1015
		}
1016
 
1017
		if(infosCom.getLon() != null && !infosCom.getLon().equals("")) {
1018
			longitude.setValue(infosCom.getLon());
1019
		}
1020
	}
1021
 
13 david 1022
	public void obtenirListeReferentielCommune() {
94 jpm 1023
 
248 aurelien 1024
	 String com=commune.getText()/*.replaceAll(" ","/")*/;
20 david 1025
	 com=com.replaceAll("%","");
1026
 
1027
	 observationMediateur.obtenirListeReferentielCommune(this,com);
13 david 1028
 
1029
	}
20 david 1030
 
1031
 
1032
	public void obtenirListeReferentielNom() {
1033
 
248 aurelien 1034
	  String esp=espece.getText().replaceAll(" ","/*");
20 david 1035
	  esp=esp.replaceAll("%","");
1036
 
1037
	  observationMediateur.obtenirListeReferentielNom(this,esp);
1038
 
1039
	}
1040
 
1041
 
39 david 1042
	public void ajouterObservation() {
140 aurelien 1043
 
1044
		if(departement.equals("000null") || departement.equals("")) {
1045
			String[] depCom = commune.getText().split(" ");
1046
			if(depCom.length > 1) {
1047
				String dep = depCom[1].replace('(', ' ');
1048
				dep =dep.replace(')', ' ');
1049
				dep = dep.trim();
1050
				dep = dep.replace('\\',' ');
1051
				dep = dep.trim();
1052
 
1053
				try
1054
				{
1055
					int nDep = Integer.parseInt(dep);
1056
					if(nDep > 0 && nDep < 110) {
1057
						departement = dep ;
1058
					}
1059
				}
1060
				catch(NumberFormatException e)
1061
				{
1062
					departement = "" ;
1063
				}
1064
			}
1065
		}
39 david 1066
 
120 aurelien 1067
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getRawValue());
46 david 1068
		observationMediateur.ajouterObservation(obs);
39 david 1069
	}
12 david 1070
 
71 jpm 1071
	private void modifierObservation() {
229 aurelien 1072
 
1073
		if(departement.equals("000null") || departement.equals("")) {
1074
			String[] depCom = commune.getText().split(" ");
1075
			if(depCom.length > 1) {
1076
				String dep = depCom[1].replace('(', ' ');
1077
				dep =dep.replace(')', ' ');
1078
				dep = dep.trim();
1079
				dep = dep.replace('\\',' ');
1080
				dep = dep.trim();
1081
 
1082
				try
1083
				{
1084
					int nDep = Integer.parseInt(dep);
1085
					if(nDep > 0 && nDep < 110) {
1086
						departement = dep ;
1087
					}
1088
				}
1089
				catch(NumberFormatException e)
1090
				{
1091
					departement = "" ;
1092
				}
1093
			}
1094
		}
1095
 
120 aurelien 1096
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),date.getRawValue());
79 david 1097
		obs.setNumeroOrdre(numeroOrdre);
216 aurelien 1098
 
79 david 1099
		observationMediateur.modifierObservation(obs);
216 aurelien 1100
 
205 aurelien 1101
		selecteurMode.setValue("création");
1102
		setModification("false");
1103
 
71 jpm 1104
	}
77 jpm 1105
 
216 aurelien 1106
	private void modifierObservationEnMasse(Champs champModifie) {
1107
		String communeM = null;
1108
		String departementM = null;
221 aurelien 1109
		String numNomSelM = null;
216 aurelien 1110
		String lieuDitM = null;
1111
		String stationM = null;
1112
		String milieuM = null;
1113
		String dateM = null;
1114
		String especeM = null;
1115
		String commM = null;
1116
 
1117
		String champs = modeleMessageModif;
1118
 
1119
		if(communeModifiee) {
1120
			communeM = commune.getText();
221 aurelien 1121
 
1122
			if(departement.equals("000null") || departement.equals("")) {
1123
				String[] depCom = commune.getText().split(" ");
1124
				if(depCom.length > 1) {
1125
					String dep = depCom[1].replace('(', ' ');
1126
					dep =dep.replace(')', ' ');
1127
					dep = dep.trim();
1128
					dep = dep.replace('\\',' ');
1129
					dep = dep.trim();
1130
 
1131
					try
1132
					{
1133
						int nDep = Integer.parseInt(dep);
1134
						if(nDep > 0 && nDep < 110) {
1135
							departement = dep ;
1136
						}
1137
					}
1138
					catch(NumberFormatException e)
1139
					{
1140
						departement = "" ;
1141
					}
1142
				}
1143
			}
1144
 
1145
			departementM = departement;
216 aurelien 1146
		} else {
221 aurelien 1147
			champs = champs.replaceAll("commune", "");
216 aurelien 1148
		}
1149
 
221 aurelien 1150
		if(lieuDitModifie) {
216 aurelien 1151
			lieuDitM = lieudit.getText();
1152
		}else {
221 aurelien 1153
			champs = champs.replaceAll(":lieu-dit", "");
216 aurelien 1154
		}
1155
 
221 aurelien 1156
		if(stationModifiee) {
216 aurelien 1157
			stationM = station.getText();
1158
		}else {
221 aurelien 1159
			champs = champs.replaceAll(":station", "");
216 aurelien 1160
		}
1161
 
1162
		if(milieuModifie) {
1163
			milieuM = milieu.getText();
1164
		}else {
221 aurelien 1165
			champs = champs.replaceAll(":milieu", "");
216 aurelien 1166
		}
1167
 
221 aurelien 1168
		if(dateModifiee && !date.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1169
			dateM = date.getRawValue();
1170
		}else {
221 aurelien 1171
			champs = champs.replaceAll(":date", "");
216 aurelien 1172
		}
1173
 
1174
		if(especeModifiee) {
1175
			especeM = espece.getText();
221 aurelien 1176
			numNomSelM = numeroNom;
216 aurelien 1177
		}else {
221 aurelien 1178
			champs = champs.replaceAll(":espece", "");
216 aurelien 1179
		}
1180
 
1181
		if(commModifie) {
1182
			commM = comment.getText();
1183
		}else {
221 aurelien 1184
			champs = champs.replaceAll(":commentaire", "");
216 aurelien 1185
		}
1186
 
221 aurelien 1187
		champs = champs.replaceAll(":",", ");
1188
		if(champs.startsWith(",")) {
1189
			champs = champs.replaceFirst(",", "");
1190
		}
216 aurelien 1191
 
221 aurelien 1192
		String message = "Voulez vous modifier le(s) champ(s) suivant(s) : "+champs+"   pour les observations selectionnées ?" ;
1193
 
216 aurelien 1194
		if(champs.trim().equals("")) {
1195
			Window.alert("Aucun champ n'a été modifié");
1196
		} else {
221 aurelien 1197
			Observation obs = new Observation(especeM,numNomSelM,communeM,departementM,lieuDitM,stationM,milieuM, commM,dateM);
216 aurelien 1198
			obs.setNumeroOrdre(numeroOrdre);
1199
			if(Window.confirm(message)) {
1200
				observationMediateur.modifierObservationEnMasse(obs);
221 aurelien 1201
				reinitialiserValeurModifiees();
216 aurelien 1202
			}
1203
		}
1204
	}
1205
 
77 jpm 1206
	private void supprimerObservation() {
1207
 
216 aurelien 1208
		observationMediateur.supprimerObservation(this, numeroOrdre);
77 jpm 1209
	}
12 david 1210
 
71 jpm 1211
 
1212
	public void afficherDetailsObservation(Observation obs)
1213
	{
104 jpm 1214
		raz() ;
216 aurelien 1215
		String idLoc ;
1216
		if(obs.getIdentifiantLocalite() != VALEURS_MULTIPLES) {
1217
			idLoc =obs.getIdentifiantLocalite().replaceAll(" ","/");
1218
			idLoc = idLoc.replaceAll("%","");
1219
			idLoc = idLoc.replaceAll("\"","");
1220
			idLoc = idLoc.replace('\\',' ');
1221
			idLoc = idLoc.trim();
1222
		} else {
1223
			idLoc = obs.getIdentifiantLocalite();
1224
		}
71 jpm 1225
 
221 aurelien 1226
		if(!obs.getDate().equals("null") && !obs.getDate().equals("000null") && !obs.getDate().equals(VALEURS_MULTIPLES)) {
71 jpm 1227
			String[] dateEtHeure = obs.getDate().split(" ", 2);
110 aurelien 1228
			if(verifierFormatDate(dateEtHeure[0])) {
1229
				date.setValue(dateEtHeure[0]) ;
1230
			}
1231
			else
1232
			{
1233
				date.setRawValue("");
1234
			}
221 aurelien 1235
		} else {
1236
			date.setRawValue(VALEURS_MULTIPLES);
1237
			date.clearInvalid();
71 jpm 1238
		}
1239
		if(!obs.getLieudit().equals("null") && !obs.getLieudit().equals("000null")) {
1240
			lieudit.setValue(obs.getLieudit()) ;
1241
		}
1242
		if(!obs.getStation().equals("null") && !obs.getStation().equals("000null")) {
1243
			station.setValue(obs.getStation()) ;
1244
		}
1245
		if(!obs.getMilieu().equals("null") && !obs.getMilieu().equals("000null")) {
1246
			milieu.setValue(obs.getMilieu()) ;
1247
		}
1248
		if(!obs.getCommentaire().equals("null") && !obs.getCommentaire().equals("000null")) {
1249
			comment.setValue(obs.getCommentaire()) ;
1250
		}
1251
		if(!obs.getLocalite().equals("null") && !obs.getLocalite().equals("000null")) {
221 aurelien 1252
			if(!idLoc.equals("000null")) {
1253
				if(!idLoc.equals(VALEURS_MULTIPLES)) {
1254
					commune.setValue(obs.getLocalite()+" ("+idLoc+")") ;
1255
				} else {
1256
					commune.setValue(VALEURS_MULTIPLES);
1257
				}
140 aurelien 1258
			}
1259
			else
1260
			{
1261
				commune.setValue(obs.getLocalite());
1262
			}
71 jpm 1263
		}
1264
		if(!obs.getIdentifiantLocalite().equals("null") && !obs.getIdentifiantLocalite().equals("000null")) {
140 aurelien 1265
			departement = idLoc;
71 jpm 1266
		}
1267
		if(!obs.getNomSaisi().equals("null") && !obs.getNomSaisi().equals("000null")) {
1268
			espece.setValue(obs.getNomSaisi()) ;
1269
		}
1270
		if(!obs.getNumeroNomenclaturalSaisi().equals("null") && !obs.getNumeroNomenclaturalSaisi().equals("000null")) {
1271
			numeroNom = obs.getNumeroNomenclaturalSaisi() ;
1272
		}
83 david 1273
		if(!obs.getNumeroOrdre().equals("null") && !obs.getNumeroOrdre().equals("000nu2ll")) {
74 david 1274
			numeroOrdre = obs.getNumeroOrdre() ;
1275
		}
1276
 
71 jpm 1277
	}
1278
 
118 david 1279
 
104 jpm 1280
	public void raz()
71 jpm 1281
	{
118 david 1282
		raz(Champs.TOUT);
1283
 
1284
	}
1285
	public void raz(Champs champs)
1286
	{
1287
		switch (champs) {
1288
 
1289
 
1290
			case DATE:
1291
				date.reset() ;
1292
				break;
1293
 
1294
			case LIEUDIT:
1295
				lieudit.reset() ;
1296
				break;
1297
 
1298
			case STATION:
1299
				station.reset() ;
1300
				break;
1301
 
1302
			case MILIEU:
1303
				milieu.reset() ;
1304
				break;
1305
 
1306
			case COMMENT:
1307
				comment.reset() ;
1308
				break;
1309
 
1310
 
1311
			case COMMUNE:
172 aurelien 1312
				commune.reset() ;
118 david 1313
				departement ="";
1314
				break;
1315
 
1316
			case ESPECE:
1317
				espece.reset();
1318
				numeroNom = "" ;
1319
				numeroOrdre = "";
1320
				break;
1321
 
1322
			case TOUT:
132 aurelien 1323
				commune.reset();
118 david 1324
				date.reset() ;
1325
				lieudit.reset() ;
1326
				station.reset() ;
1327
				milieu.reset() ;
1328
				comment.reset() ;
1329
				milieu.reset() ;
248 aurelien 1330
				latitude.reset();
1331
				longitude.reset();
118 david 1332
				departement ="";
1333
				espece.reset();
1334
				numeroNom = "" ;
1335
				numeroOrdre = "";
1336
				break;
1337
 
1338
		}
71 jpm 1339
 
1340
	}
1341
 
1342
	private void setModification(String mode)
1343
	{
1344
		if(mode.equals("true")) {
1345
 
1346
			boutonOK.setText("Modifier") ;
1347
			setTitle("Modification") ;
77 jpm 1348
			boutonAnnuler.setText("Supprimer") ;
71 jpm 1349
			modification = true ;
97 jpm 1350
			selecteurMode.removeClass("x-selec-crea") ;
1351
			selecteurMode.setCls("x-selec-modif") ;
216 aurelien 1352
			observationMediateur.onModeModification();
71 jpm 1353
		}
1354
		else
1355
		{
120 aurelien 1356
			boutonOK.setText("Ajouter") ;
71 jpm 1357
			setTitle("Saisir") ;
77 jpm 1358
			boutonAnnuler.setText("Réinitialiser") ;
71 jpm 1359
			modification = false ;
97 jpm 1360
			selecteurMode.removeClass("x-selec-modif") ;
1361
			selecteurMode.setCls("x-selec-crea") ;
246 aurelien 1362
			observationMediateur.onModeCreation();
94 jpm 1363
 
132 aurelien 1364
		}
71 jpm 1365
	}
1366
 
1367
	/**
1368
	 * renvoie vrai si on est en mode modification, faux si on est en mode création
1369
	 * @return
1370
	 */
1371
	public boolean getModification()
1372
	{
1373
		return modification ;
1374
	}
110 aurelien 1375
 
216 aurelien 1376
	/**
1377
	 * renvoie vrai si on est en mode modification de masse, faux sinon
1378
	 * @return
1379
	 */
1380
	public boolean getMasseModification()
1381
	{
1382
		return masseModification ;
1383
	}
1384
 
110 aurelien 1385
	public boolean verifierFormatDate(String date) {
1386
 
132 aurelien 1387
		String regex = "[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}" ;
110 aurelien 1388
		if(date.matches(regex) && !date.equals("0000-00-00")) {
1389
			return true ;
1390
		}
1391
		else {
1392
			return false;
1393
		}
1394
	}
216 aurelien 1395
 
1396
	public void setMasseModification(boolean masseModification) {
1397
		this.masseModification = masseModification;
1398
		if(masseModification) {
1399
			reinitialiserValeurModifiees();
1400
		}
1401
	}
132 aurelien 1402
 
216 aurelien 1403
	private void calculerAfficherDifferences(ListeObservation listeObs) {
1404
 
1405
		String departement = null;
1406
		String commune = null;
1407
		String lieuDit = null;
1408
		String station = null;
1409
		String milieu = null;
1410
		String espece = null;
1411
		String date = null;
1412
		String notes = null;
1413
 
1414
		String ordreObs = "";
1415
 
1416
		for(Iterator<String> it = listeObs.keySet().iterator();it.hasNext();) {
1417
			Observation obsEnCours = listeObs.get(it.next());
1418
			departement = comparerDifferencesChamps(departement, obsEnCours.getIdentifiantLocalite());
1419
			commune = comparerDifferencesChamps(commune, obsEnCours.getLocalite());
1420
			lieuDit = comparerDifferencesChamps(lieuDit, obsEnCours.getLieudit());
1421
			station = comparerDifferencesChamps(station, obsEnCours.getStation());
1422
			milieu = comparerDifferencesChamps(milieu, obsEnCours.getMilieu());
1423
			espece = comparerDifferencesChamps(espece, obsEnCours.getNomSaisi());
1424
			date = comparerDifferencesChamps(date, obsEnCours.getDate());
1425
			notes = comparerDifferencesChamps(notes, obsEnCours.getCommentaire());
1426
 
1427
			ordreObs += obsEnCours.getNumeroOrdre()+",";
1428
		}
1429
 
1430
		Observation obs=new Observation(espece,numeroNom,commune,departement,lieuDit,station,milieu, notes,date);
1431
		obs.setNumeroOrdre(ordreObs);
1432
		rafraichir(obs, false);
1433
 
1434
	}
1435
 
1436
	private String comparerDifferencesChamps(String valeurActuelle, String nouvelleValeur) {
1437
 
1438
		String retour = "000null";
1439
 
1440
			if(valeurActuelle == null) {
1441
				retour = nouvelleValeur;
1442
			} else {
1443
				if(valeurActuelle.equals(nouvelleValeur)) {
1444
					retour = valeurActuelle;
1445
				} else {
1446
					retour = VALEURS_MULTIPLES;
1447
				}
1448
			}
1449
		return retour;
1450
	}
1451
 
1452
	private void reinitialiserValeurModifiees() {
1453
 
1454
		communeModifiee = false;
221 aurelien 1455
		lieuDitModifie = false;
1456
		stationModifiee = false;
216 aurelien 1457
		milieuModifie = false;
1458
		dateModifiee = false;
1459
		especeModifiee = false;
1460
		commModifie = false;
1461
	}
1462
 
248 aurelien 1463
	public void saisieTabindex()
1464
	{
1465
 
1466
		selecteurMode.setTabIndex(0);
1467
		commune.setTabIndex(1);
1468
		lieudit.setTabIndex(2);
1469
		station.setTabIndex(3);
1470
		milieu.setTabIndex(4);
1471
		coordonnees.setTabIndex(-1);
1472
		coordonnees.addListener(new TextFieldListenerAdapter() {
1473
 
1474
			public void onFocus(Field field) {
1475
				if(coordPanel.isVisible()) {
1476
					longitude.focus();
1477
				} else {
1478
					Ext.get("lien_carto").focus();
1479
				}
1480
			}
1481
		});
1482
 
1483
		longitude.setTabIndex(8);
1484
		latitude.setTabIndex(9);
1485
		comment.setTabIndex(10);
1486
		date.setTabIndex(11);
1487
		espece.setTabIndex(12);
1488
		boutonOK.setTabIndex(13);
1489
		boutonAnnuler.setTabIndex(14);
1490
 
1491
	}
1492
 
1493
	private void obtenirInformationCoord() {
1494
		if(coordonneesValides() != null) {
1495
			observationMediateur.obtenirInformationCoord(LatLng.newInstance(coordonneesValides()[0],coordonneesValides()[1]));
1496
		} else {
1497
			Window.alert("Les coordonnées saisies sont invalides");
1498
		}
1499
 
1500
	}
1501
 
1502
	private void obtenirInformationCommune() {
1503
		observationMediateur.obtenirInformationCommune(commune.getValue(), obtenirDepartementAPartirChampCommune());
1504
	}
1505
 
1506
	private double[] coordonneesValides() {
1507
 
1508
		try {
1509
 
1510
			double lat = Double.parseDouble(latitude.getValueAsString().replaceAll(",", "."));
1511
			double lon = Double.parseDouble(longitude.getValueAsString().replaceAll(",", "."));
1512
 
1513
			double[] coord = {lat, lon};
1514
			return coord;
1515
 
1516
		} catch (NumberFormatException ne) {
1517
			return null;
1518
		}
1519
	}
1520
 
1521
	private String obtenirDepartementAPartirChampCommune() {
1522
		if(departement.equals("000null") || departement.equals("")) {
1523
			String[] depCom = commune.getText().split(" ");
1524
			if(depCom.length > 1) {
1525
				String dep = depCom[1].replace('(', ' ');
1526
				dep =dep.replace(')', ' ');
1527
				dep = dep.trim();
1528
				dep = dep.replace('\\',' ');
1529
				dep = dep.trim();
1530
 
1531
				try
1532
				{
1533
					int nDep = Integer.parseInt(dep);
1534
					if(nDep > 0 && nDep < 110) {
1535
						departement = dep ;
1536
					}
1537
				}
1538
				catch(NumberFormatException e)
1539
				{
1540
					departement = "" ;
1541
				}
1542
			}
1543
		}
1544
 
1545
		return departement;
1546
	}
1547
 
216 aurelien 1548
	private Field obtenirCorrespondanceChampsEnum(Champs champ) {
1549
		switch(champ) {
1550
    	case DATE:
1551
    		return date;
1552
 
1553
    	case COMMUNE:
1554
    		return commune;
1555
 
1556
		case LIEUDIT:
1557
			return lieudit;
1558
 
1559
		case STATION:
1560
			return station;
1561
 
1562
		case MILIEU:
1563
			return milieu;
1564
 
1565
		case COMMENT:
1566
			return comment;
1567
 
1568
    	case ESPECE:
1569
    		return espece;
1570
    	}
1571
		return null;
1572
	}
12 david 1573
}