Subversion Repositories eFlore/Applications.cel

Rev

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