Subversion Repositories eFlore/Applications.cel

Rev

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