Subversion Repositories eFlore/Applications.cel

Rev

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