Subversion Repositories eFlore/Applications.cel

Rev

Rev 962 | Rev 989 | 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;
728 aurelien 21
import org.tela_botanica.client.util.AutoCompletionRefComboBox;
708 aurelien 22
import org.tela_botanica.client.util.Util;
132 aurelien 23
 
656 aurelien 24
import com.google.gwt.core.client.GWT;
25
import com.google.gwt.core.client.JavaScriptObject;
26
import com.google.gwt.event.dom.client.KeyPressEvent;
248 aurelien 27
import com.google.gwt.maps.client.geom.LatLng;
268 aurelien 28
import com.google.gwt.user.client.Timer;
216 aurelien 29
import com.google.gwt.user.client.Window;
248 aurelien 30
import com.google.gwt.user.client.ui.HTML;
13 david 31
import com.gwtext.client.core.EventCallback;
32
import com.gwtext.client.core.EventObject;
218 david 33
import com.gwtext.client.core.Ext;
248 aurelien 34
import com.gwtext.client.core.ExtElement;
391 aurelien 35
import com.gwtext.client.core.Function;
13 david 36
import com.gwtext.client.core.ListenerConfig;
12 david 37
import com.gwtext.client.core.Position;
13 david 38
import com.gwtext.client.data.ArrayReader;
39
import com.gwtext.client.data.FieldDef;
40
import com.gwtext.client.data.MemoryProxy;
41
import com.gwtext.client.data.RecordDef;
71 jpm 42
import com.gwtext.client.data.SimpleStore;
13 david 43
import com.gwtext.client.data.Store;
44
import com.gwtext.client.data.StringFieldDef;
132 aurelien 45
import com.gwtext.client.widgets.BoxComponent;
12 david 46
import com.gwtext.client.widgets.Button;
656 aurelien 47
import com.gwtext.client.widgets.Component;
132 aurelien 48
import com.gwtext.client.widgets.Container;
221 aurelien 49
import com.gwtext.client.widgets.DatePicker;
12 david 50
import com.gwtext.client.widgets.Panel;
248 aurelien 51
import com.gwtext.client.widgets.ToolTip;
71 jpm 52
import com.gwtext.client.widgets.Toolbar;
20 david 53
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
132 aurelien 54
import com.gwtext.client.widgets.event.ContainerListenerAdapter;
221 aurelien 55
import com.gwtext.client.widgets.event.DatePickerListenerAdapter;
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;
656 aurelien 65
import com.gwtext.client.widgets.form.event.ComboBoxCallback;
66
import com.gwtext.client.widgets.form.event.ComboBoxListener;
13 david 67
import com.gwtext.client.widgets.form.event.ComboBoxListenerAdapter;
656 aurelien 68
import com.gwtext.client.widgets.form.event.TextFieldListener;
248 aurelien 69
import com.gwtext.client.widgets.form.event.TextFieldListenerAdapter;
201 david 70
import com.gwtext.client.widgets.layout.AnchorLayoutData;
12 david 71
import com.gwtext.client.widgets.layout.ColumnLayout;
72
import com.gwtext.client.widgets.layout.ColumnLayoutData;
73
import com.gwtext.client.widgets.layout.FormLayout;
230 david 74
import com.gwtext.client.widgets.layout.RowLayout;
13 david 75
import com.gwtext.client.data.Record;
12 david 76
 
77
/**
78
 * Panneau contenant les infos, les métadonnées et l'arbre des mots clés, il implémente l'interface rafraichissable
79
 * @author aurelien
80
 *
81
 */
13 david 82
public class FormulaireSaisieObservationVue extends Panel implements Rafraichissable  {
12 david 83
 
84
 
85
	/**
86
	 * Le médiateur associé à la vue
87
	 */
88
	private ObservationMediateur	observationMediateur		= null;
89
 
205 aurelien 90
	FormPanel panneauFormulaire = null;
20 david 91
 
13 david 92
	private DateField date = null;
708 aurelien 93
	private ComboBox lieudit = null;
94
	private ComboBox station = null;
95
	private ComboBox milieu = null;
12 david 96
	private TextField comment = null;
13 david 97
	private ComboBox  commune = null;
39 david 98
	private String departement = null;
20 david 99
	private ComboBox  espece = null;
39 david 100
	private String numeroNom = null;
74 david 101
	private String numeroOrdre = null;
264 aurelien 102
 
962 aurelien 103
	private String codeInseeCommune = null;
104
 
264 aurelien 105
	private String referentielGeo = null;
20 david 106
 
118 david 107
	// Pour remise a zero partielle lors d'une validation
108
 
109
	private  enum Champs {
264 aurelien 110
	    DATE, LIEUDIT, STATION, MILIEU, COMMENT, COMMUNE, ESPECE, TOUT, LATITUDE, LONGITUDE ;
216 aurelien 111
 
112
	    public String toString() {
113
 
114
	    	switch(this) {
115
	    	case DATE:
116
	    		return "date";
117
 
118
	    	case COMMUNE:
119
	    		return "commune";
120
 
121
    		case LIEUDIT:
122
    			return "lieu dit";
123
 
124
    		case STATION:
125
    			return "station";
126
 
127
    		case MILIEU:
128
    			return "milieu";
129
 
130
    		case COMMENT:
131
    			return "commentaire";
132
 
133
	    	case ESPECE:
134
	    		return "espèce";
264 aurelien 135
 
136
	    	case LATITUDE:
137
	    		return "latitude";
138
 
139
	    	case LONGITUDE:
140
	    		return "longitude";
216 aurelien 141
 
142
	    	case TOUT:
264 aurelien 143
	    		return "date, commune, lieu dit, station, milieu, espèce, commentaire, latitude, longitude";
216 aurelien 144
	    	}
145
			return TOUT.toString();
146
	    }
118 david 147
	};
148
 
110 aurelien 149
	private String formatDate = null ;
71 jpm 150
	private Button boutonOK = new Button("Créer");
77 jpm 151
	private Button boutonAnnuler = new Button("Réinitialiser");
20 david 152
 
13 david 153
	private boolean selectionCommune=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
 
728 aurelien 322
	    station = new AutoCompletionRefComboBox("Station", "station", observationMediateur, TypesReferentiels.REFERENTIEL_STATION) {
268 aurelien 323
 
728 aurelien 324
			public void onModificationValeur() {
325
				stationModifiee = true;
326
			}
327
 
328
			public void onValidationSaisie() {
329
				validerSaisie(Champs.STATION);
330
			}
331
	    };
201 david 332
	    panneauPremierColonne.add(station, new AnchorLayoutData("95%"));
12 david 333
 
781 aurelien 334
		latitude = new TextField("Lat", "lat");
282 aurelien 335
		latitude.setGrowMax(70);
264 aurelien 336
		latitude.setAllowBlank(true);
337
 
781 aurelien 338
	    longitude = new TextField("Lon", "lon");
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
 
783 aurelien 349
		// Panneau de type plusieurs champs de formulaire sur une meme ligne, où seront renseignés Lat/Lon
248 aurelien 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
 
728 aurelien 470
	    lieudit = new AutoCompletionRefComboBox("Lieu-dit", "lieudit",observationMediateur,TypesReferentiels.REFERENTIEL_LIEU_DIT) {
471
 
472
			public void onModificationValeur() {
473
				lieuDitModifie = true;
474
			}
475
 
476
			public void onValidationSaisie() {
477
				validerSaisie(Champs.LIEUDIT);
478
			}
479
	    };
201 david 480
	    panneauSecondeColonne.add(lieudit,  new AnchorLayoutData("95%"));
728 aurelien 481
 
482
	    milieu = new AutoCompletionRefComboBox("Milieu","milieu",observationMediateur,TypesReferentiels.REFERENTIEL_MILIEU) {
483
 
484
			public void onModificationValeur() {
485
				milieuModifie = true;
486
			}
487
 
488
			public void onValidationSaisie() {
489
				validerSaisie(Champs.MILIEU);
490
			}
491
 
492
	    };
201 david 493
	    panneauSecondeColonne.add(milieu,  new AnchorLayoutData("95%"));
128 aurelien 494
 
495
	    comment = new TextArea("Notes", "comment");
496
	    comment.setAllowBlank(true);
497
	    comment.setHeight(50);
391 aurelien 498
 
248 aurelien 499
	    //comment.setTabIndex(7);
201 david 500
	    panneauSecondeColonne.add(comment, new AnchorLayoutData("95%") );
230 david 501
 
276 aurelien 502
	    if (Window.getClientWidth() > Window.getClientHeight() || Window.getClientWidth() < 800) {
230 david 503
			panneauIntermediaire.add(panneauPremierColonne, new ColumnLayoutData(.5));
504
			panneauIntermediaire.add(panneauSecondeColonne, new ColumnLayoutData(.5));
505
	    }
506
	    else {
507
			panneauIntermediaire.add(panneauPremierColonne);
508
			panneauIntermediaire.add(panneauSecondeColonne);
509
 
510
	    }
511
 
12 david 512
		panneauFormulaire.add(panneauIntermediaire);
513
 
71 jpm 514
		Object[][] mode = {{"création",false} , {"modification", true} };
515
		storeMode = new SimpleStore(new String[] { "nom_mode", "mode" },
516
				mode);
517
		storeMode.load();
518
		selecteurMode.setStore(storeMode);
519
		selecteurMode.setDisplayField("nom_mode") ;
520
		selecteurMode.setLabel("mode ") ;
521
		selecteurMode.setForceSelection(true) ;
522
		selecteurMode.setValue("création") ;
523
		selecteurMode.setEditable(false) ;
97 jpm 524
		selecteurMode.setCls("x-selec-crea") ;
71 jpm 525
 
526
		bt = new Toolbar() ;
527
		bt.addSpacer() ;
528
		bt.addText("Mode de saisie ") ;
529
		bt.addField(selecteurMode) ;
530
 
74 david 531
 
276 aurelien 532
		if (Ext.isIE()) {
218 david 533
			panneauPremierColonne.setButtonAlign(Position.RIGHT);
534
			panneauPremierColonne.addButton(boutonOK);
535
			panneauSecondeColonne.setButtonAlign(Position.LEFT);
276 aurelien 536
			panneauPremierColonne.addButton(boutonAnnuler);
218 david 537
		}
538
		else {
539
 
540
			panneauFormulaire.addButton(boutonOK);
541
			panneauFormulaire.addButton(boutonAnnuler);
542
		}
543
 
544
 
71 jpm 545
		selecteurMode.addListener(new ComboBoxListenerAdapter() {
546
 
547
			public void onSelect(ComboBox comboBox, Record record, int index) {
548
 
549
				// et on met la valeur à jour dans la combobox
550
				comboBox.setValue(record.getAsString("nom_mode"));
551
				setModification(record.getAsString("mode")) ;
552
			}
553
 
554
		});
12 david 555
 
556
		this.add(panneauFormulaire) ;
80 jpm 557
		this.setTopToolbar(bt) ;
12 david 558
 
120 aurelien 559
		this.setAutoScroll(true);
12 david 560
 
201 david 561
 
562
		panneauFormulaire.addListener(new PanelListenerAdapter() {
563
	        public void onResize(BoxComponent component, int adjWidth, int adjHeight, int rawWidth, int rawHeight) {
564
	        	panneauIntermediaire.setWidth(rawWidth);
565
	        	panneauIntermediaire.setHeight(rawHeight);
276 aurelien 566
 
567
	        	panneauPremierColonne.doLayout();
568
	        	panneauSecondeColonne.doLayout();
681 aurelien 569
 
276 aurelien 570
	        	htmlCommunePanel.doLayout();
571
	        	htmlPanel.doLayout();
318 aurelien 572
 
573
	        	doLayout();
201 david 574
	     }});
575
 
12 david 576
		// on ajoute les listeners
201 david 577
 
578
 
12 david 579
		ajouterListeners() ;
580
 
248 aurelien 581
		saisieTabindex();
582
 
12 david 583
	}
584
 
585
	private void ajouterListeners()
94 jpm 586
	{
20 david 587
		// Listener completion communne
268 aurelien 588
		final Rafraichissable r = this;
20 david 589
 
590
		   commune.addListener(new ComboBoxListenerAdapter() {
591
	             public void onSelect(ComboBox comboBox, Record record, int index) {
592
	                 commune.setValue(record.getAsString("commune"));
39 david 593
	                 departement=record.getAsString("departement");
20 david 594
	                 selectionCommune=true;
656 aurelien 595
	                 commune.collapse();
20 david 596
	             }
656 aurelien 597
 
598
	             public void onExpand(ComboBox comboBox) {
599
	            	 comboBox.focus();
600
	             }
20 david 601
	         });
602
 
603
 
604
			ListenerConfig listenerConfigCommune=new ListenerConfig();
656 aurelien 605
			listenerConfigCommune.setDelay(200);
20 david 606
			listenerConfigCommune.setStopPropagation(false);
607
			listenerConfigCommune.setStopEvent(false);
608
 
609
		    commune.addKeyPressListener(new EventCallback()	{
610
 
120 aurelien 611
	    	    public void execute(EventObject e) {
612
 
613
 
614
	    	    		switch(e.getKey()) {
615
 
132 aurelien 616
    	    				case KEY_ALT:
617
	    	    	        case KEY_CTRL:
618
	    	    	        case KEY_DOWN:
619
	    	    	        case KEY_END:
620
	    	    	        case KEY_ESCAPE:
621
	    	    	        case KEY_HOME:
622
	    	    	        case KEY_LEFT:
623
	    	    	        case KEY_PAGEDOWN:
624
	    	    	        case KEY_PAGEUP:
625
	    	    	        case KEY_RIGHT:
626
	    	    	        case KEY_SHIFT:
627
	    	    	        case KEY_TAB:
628
	    	    	        case KEY_UP:
629
 
630
	    	    	        break;
631
 
120 aurelien 632
	    	    	    	case KEY_ENTER:
633
 
20 david 634
		    	    	    	 if (selectionCommune) {
216 aurelien 635
		    	    	    		 communeModifiee= true;
20 david 636
		    	    	    		 selectionCommune=false;
637
		    	    	    	 }
120 aurelien 638
		    	    	    	else {
639
 
118 david 640
		    	    	    		validerSaisie(Champs.COMMUNE);
20 david 641
		    	    	    		// lancer mise a jour
642
		    	    	    	 }
120 aurelien 643
		    	    	    break;
644
 
645
		    	    	    default:
20 david 646
 
83 david 647
		    	    	    	  departement="";
656 aurelien 648
		    	    	    	  commune.collapse();
20 david 649
		    	    	    	  obtenirListeReferentielCommune();
216 aurelien 650
		    	    	    	  communeModifiee= true;
20 david 651
 
120 aurelien 652
		    	    	    break;
653
	    	    	    }
654
	     			}
655
	    		},    listenerConfigCommune
20 david 656
			);
657
 
120 aurelien 658
		    date.addKeyPressListener(new EventCallback() {
20 david 659
 
120 aurelien 660
				public void execute(EventObject e) {
661
					// TODO Auto-generated method stub
662
					switch(e.getKey()) {
221 aurelien 663
 
664
						case KEY_ALT:
665
		    	        case KEY_CTRL:
666
		    	        case KEY_DOWN:
667
		    	        case KEY_END:
668
		    	        case KEY_ESCAPE:
669
		    	        case KEY_HOME:
670
		    	        case KEY_LEFT:
671
		    	        case KEY_PAGEDOWN:
672
		    	        case KEY_PAGEUP:
673
		    	        case KEY_RIGHT:
674
		    	        case KEY_SHIFT:
675
		    	        case KEY_TAB:
676
		    	        	if(date.getRawValue().equals(VALEURS_MULTIPLES)) {
677
		    	        		date.clearInvalid();
678
		    	        	}
679
		    	        case KEY_UP:
680
 
681
		    	        break;
120 aurelien 682
 
221 aurelien 683
	  	    	      case KEY_ENTER:
684
	  	    	    		validerSaisie(Champs.DATE);
120 aurelien 685
	  	    	    	  break;
686
 
687
	  	    	      default:
221 aurelien 688
	  					dateModifiee = true;
120 aurelien 689
					}
690
				}
691
		    });
692
 
221 aurelien 693
		    date.addListener(new DatePickerListenerAdapter() {
694
 
695
				public void onSelect(DatePicker dataPicker, Date date) {
696
					dateModifiee = true;
697
				}
698
		    });
699
 
708 aurelien 700
		    ListenerConfig listenerConfigAutocompletion=new ListenerConfig();
701
		    listenerConfigAutocompletion.setDelay(200);
702
		    listenerConfigAutocompletion.setStopPropagation(false);
703
		    listenerConfigAutocompletion.setStopEvent(false);
120 aurelien 704
 
728 aurelien 705
 
120 aurelien 706
			// Listener completion espece
20 david 707
			espece.addListener(new ComboBoxListenerAdapter() {
708
	             public void onSelect(ComboBox comboBox, Record record, int index) {
709
	            	 espece.setValue(record.getAsString("nom"));
39 david 710
	            	 numeroNom=record.getAsString("numeroNom");
20 david 711
	                 selectionEspece=true;
128 aurelien 712
	                 observationMediateur.obtenirImageInformationExternes(numeroNom);
20 david 713
	             }
714
	         });
715
 
716
 
717
			ListenerConfig listenerConfigEspece=new ListenerConfig();
718
			listenerConfigEspece.setDelay(10);
719
			listenerConfigEspece.setStopPropagation(false);
720
			listenerConfigEspece.setStopEvent(false);
721
 
722
 
723
			espece.addKeyPressListener(new EventCallback()	{
724
 
725
		    	    public void execute(EventObject e) {
726
 
727
 
728
		    	    		  switch(e.getKey()) {
729
 
730
 
731
		    	    		  case KEY_ALT:
732
		    	    	      case KEY_CTRL:
733
		    	    	      case KEY_DOWN:
734
		    	    	      case KEY_END:
735
		    	    	      case KEY_ESCAPE:
736
		    	    	      case KEY_HOME:
737
		    	    	      case KEY_LEFT:
738
		    	    	      case KEY_PAGEDOWN:
739
		    	    	      case KEY_PAGEUP:
740
		    	    	      case KEY_RIGHT:
741
		    	    	      case KEY_SHIFT:
742
		    	    	      case KEY_TAB:
743
		    	    	      case KEY_UP:
744
 
745
		    	    	        break;
746
 
747
		    	    	      case KEY_ENTER:
748
 
140 aurelien 749
			    	    	    	if(selectionEspece) {
216 aurelien 750
			    	    	    		especeModifiee = true;
751
			    	    	    		selectionEspece=false;
140 aurelien 752
			    	    	    	}
753
			    	    	    	else {
754
			    	    	    		validerSaisie(Champs.ESPECE);
755
			    	    	    	}
20 david 756
 
757
		    	    	    	  break;
758
 
759
		    	    	      default:
760
 
83 david 761
		    	    	    	  numeroNom="";
20 david 762
		    	    	    	  obtenirListeReferentielNom();
216 aurelien 763
		    	    	    	  especeModifiee = true;
20 david 764
 
765
		    	    	        break;
766
		    	    	    }
767
 
768
 
769
 
770
		     		}
771
 
772
		    		},    listenerConfigEspece
773
 
774
			);
708 aurelien 775
 
216 aurelien 776
			comment.addKeyPressListener(new EventCallback() {
120 aurelien 777
 
778
				public void execute(EventObject e) {
221 aurelien 779
					switch(e.getKey()) {
780
						case KEY_ALT:
781
			    	      case KEY_CTRL:
782
			    	      case KEY_DOWN:
783
			    	      case KEY_END:
784
			    	      case KEY_ESCAPE:
785
			    	      case KEY_HOME:
786
			    	      case KEY_LEFT:
787
			    	      case KEY_PAGEDOWN:
788
			    	      case KEY_PAGEUP:
789
			    	      case KEY_RIGHT:
790
			    	      case KEY_SHIFT:
791
			    	      case KEY_TAB:
792
			    	      case KEY_UP:
793
 
794
		    	        break;
795
 
796
		    	        default:
797
						commModifie = true;
798
					}
120 aurelien 799
				}
216 aurelien 800
		    });
264 aurelien 801
 
268 aurelien 802
			tCoord = new Timer() {
803
 
804
				public void run() {
805
    	        	double[] coord = coordonneesValides();
806
    	        	if(!rechercheCommuneEnCours && coord != null && (longModifiee || latModifiee)) {
807
    	        		rechercheCommuneEnCours = true;
808
    	        		Ext.get(lienSelectionCommune.getElement()).mask("recherche");
809
    	        		observationMediateur.obtenirInformationCoord(r,LatLng.newInstance(coord[0], coord[1]));
810
    	        	}
811
				}
812
 
813
			};
814
 
264 aurelien 815
			latitude.addKeyPressListener(new EventCallback() {
120 aurelien 816
 
264 aurelien 817
				public void execute(EventObject e) {
818
					switch(e.getKey()) {
819
						case KEY_ALT:
820
			    	      case KEY_CTRL:
821
			    	      case KEY_DOWN:
822
			    	      case KEY_END:
823
			    	      case KEY_ESCAPE:
824
			    	      case KEY_HOME:
825
			    	      case KEY_LEFT:
826
			    	      case KEY_PAGEDOWN:
827
			    	      case KEY_PAGEUP:
828
			    	      case KEY_RIGHT:
829
			    	      case KEY_SHIFT:
830
			    	      case KEY_TAB:
831
			    	      case KEY_UP:
832
 
833
		    	        break;
834
 
835
			    	      case KEY_ENTER:
836
	  	    	    		validerSaisie(Champs.LATITUDE);
837
	  	    	    	  break;
838
 
839
		    	        default:
840
						latModifiee = true;
268 aurelien 841
	    	        	tCoord.cancel();
842
	    	        	tCoord.schedule(250);
264 aurelien 843
					}
844
				}
845
		    });
846
 
847
			longitude.addKeyPressListener(new EventCallback() {
848
 
849
				public void execute(EventObject e) {
850
					switch(e.getKey()) {
268 aurelien 851
 
264 aurelien 852
						case KEY_ALT:
853
			    	      case KEY_CTRL:
854
			    	      case KEY_DOWN:
855
			    	      case KEY_END:
856
			    	      case KEY_ESCAPE:
857
			    	      case KEY_HOME:
858
			    	      case KEY_LEFT:
859
			    	      case KEY_PAGEDOWN:
860
			    	      case KEY_PAGEUP:
861
			    	      case KEY_RIGHT:
862
			    	      case KEY_SHIFT:
268 aurelien 863
			    	      case KEY_UP:
264 aurelien 864
			    	      case KEY_TAB:
268 aurelien 865
			    	      break;
866
 
264 aurelien 867
			    	      case KEY_ENTER:
868
		  	    	    		validerSaisie(Champs.LONGITUDE);
268 aurelien 869
		  	    	    	break;
264 aurelien 870
 
871
		    	        default:
268 aurelien 872
							longModifiee = true;
873
		    	        	tCoord.cancel();
874
		    	        	tCoord.schedule(250);
264 aurelien 875
					}
876
				}
877
		    });
878
 
20 david 879
		boutonOK.addListener(new ButtonListenerAdapter() {
39 david 880
 
20 david 881
			public void onClick(Button button, EventObject e) {
118 david 882
 
883
				if(modification) {
216 aurelien 884
					if(masseModification) {
885
							modifierObservationEnMasse(null);
886
					} else {
887
						modifierObservation() ;
888
					}
71 jpm 889
				}
118 david 890
				else {
71 jpm 891
					ajouterObservation();
892
				}
39 david 893
 
71 jpm 894
 
20 david 895
			}
896
 
897
		});
77 jpm 898
 
899
		boutonAnnuler.addListener(new ButtonListenerAdapter() {
12 david 900
 
901
			public void onClick(Button button, EventObject e) {
902
 
77 jpm 903
				if(modification)
904
				{
905
					supprimerObservation() ;
906
				}
907
				else
908
				{
104 jpm 909
					raz();
77 jpm 910
				}
911
			}
912
 
12 david 913
		});
132 aurelien 914
 
915
		this.addListener(new ContainerListenerAdapter() {
916
			public void onAfterLayout(Container self) {
917
				commune.focus();
918
			}
919
		});
276 aurelien 920
 
12 david 921
	}
708 aurelien 922
 
12 david 923
	/**
118 david 924
	 * Validation de la saisie
925
	 */
926
 
927
	private void validerSaisie(Champs champs) {
928
 
929
		if(modification) {
216 aurelien 930
			if(masseModification) {
931
					modifierObservationEnMasse(champs);
932
			} else {
933
				modifierObservation();
934
			}
935
 
936
			raz(champs);
118 david 937
		}
938
		else {
939
			ajouterObservation();
940
			raz(champs);
941
		}
942
	}
943
 
944
	/**
12 david 945
	 * Desactive visuellement ce panneau
946
	 */
947
	public void desactiverPanneau()
948
	{
949
		this.setDisabled(true) ;
950
	}
951
 
952
	/**
953
	 * Active visuellement ce panneau
954
	 */
955
	public void activerPanneau()
956
	{
957
		this.setDisabled(false) ;
958
	}
13 david 959
 
960
	public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
961
 
49 david 962
		// si l'on a reçu une liste du referentiel commune (completion referentiel commune)
13 david 963
			if(nouvelleDonnees instanceof ListeReferentielCommune)
964
			{
282 aurelien 965
				ListeReferentielCommune data = (ListeReferentielCommune) nouvelleDonnees ;
966
				Object[][] communeData = new Object[data.size()][2];
967
				int i = 0 ;
968
 
969
				// on la parse et on récupère les informations quiç nous interessent
970
				for (Iterator it = data.keySet().iterator(); it.hasNext();)
971
				{
13 david 972
 
282 aurelien 973
					ReferentielCommune ref=(ReferentielCommune) data.get(it.next());
389 david 974
 
13 david 975
 
282 aurelien 976
					communeData[i][0]= ref.getCommune();
977
					communeData[i][1]= ref.getDepartement();
13 david 978
 
282 aurelien 979
					i++ ;
980
				}
981
 
982
				   //	  creation du store
983
				FieldDef defCommune = new StringFieldDef("commune");
984
				FieldDef defDepartement = new StringFieldDef("departement");
985
 
986
 
987
				FieldDef[] defTab = { defCommune, defDepartement};
988
 
989
				RecordDef rd = new RecordDef(defTab);
990
 
991
				final MemoryProxy dataProxy = new MemoryProxy(communeData);
992
				final ArrayReader reader = new ArrayReader(rd);
656 aurelien 993
 
994
				Store store=new Store(dataProxy,reader);
995
				commune.setStore(store);
996
				store.load();
282 aurelien 997
 
13 david 998
			}
20 david 999
 
94 jpm 1000
			//			 si l'on a reçu une liste du référentiel nom (complétion referentiel nom)
20 david 1001
 
1002
			if(nouvelleDonnees instanceof ListeReferentielNom)
1003
			{
1004
 
282 aurelien 1005
				ListeReferentielNom data = (ListeReferentielNom) nouvelleDonnees ;
389 david 1006
				Object[][] nomData = new Object[data.size()][3];
282 aurelien 1007
				int i = 0 ;
1008
 
1009
				// on la parse et on récupère les informations quiç nous interessent
1010
				for (Iterator it = data.keySet().iterator(); it.hasNext();)
1011
				{
20 david 1012
 
282 aurelien 1013
					ReferentielNom ref=(ReferentielNom) data.get(it.next());
20 david 1014
 
282 aurelien 1015
					nomData[i][0]= ref.getNom();
1016
					nomData[i][1]= ref.getNumeroNom();
389 david 1017
					if (ref.getStatut().equals("3")) {
1018
						nomData[i][2]="nom_retenu";
1019
					}
1020
					else {
1021
						nomData[i][2]="";
1022
					}
20 david 1023
 
282 aurelien 1024
 
1025
					i++ ;
1026
				}
20 david 1027
 
282 aurelien 1028
				   //	  creation du store
1029
				FieldDef defNom = new StringFieldDef("nom");
1030
				FieldDef defNumeroNom = new StringFieldDef("numeroNom");
389 david 1031
				FieldDef indicateurNomRetenu = new StringFieldDef("indicateurNomRetenu");
282 aurelien 1032
 
1033
 
389 david 1034
				FieldDef[] defTab = { defNom, defNumeroNom, indicateurNomRetenu};
282 aurelien 1035
 
1036
				RecordDef rd = new RecordDef(defTab);
1037
 
1038
				final MemoryProxy dataProxy = new MemoryProxy(nomData);
1039
				final ArrayReader reader = new ArrayReader(rd);
1040
 
1041
				Store store=new Store(dataProxy,reader);
1042
				store.load() ;
1043
 
1044
				espece.setStore(store);
1045
 
20 david 1046
			}
1047
 
82 david 1048
			// On recoit une observation dont on veut afficher le detail
1049
 
71 jpm 1050
			if(nouvelleDonnees instanceof Observation)
1051
			{
1052
				Observation obs = (Observation)nouvelleDonnees ;
1053
				afficherDetailsObservation(obs) ;
1054
			}
77 jpm 1055
 
216 aurelien 1056
			if(nouvelleDonnees instanceof ListeObservation) {
357 aurelien 1057
 
216 aurelien 1058
				ListeObservation listeObs = (ListeObservation)nouvelleDonnees;
1059
				calculerAfficherDifferences(listeObs);
1060
			}
1061
 
82 david 1062
			// Sur Mise à jour ou suppression d'une suppression ?
1063
 
77 jpm 1064
			if(nouvelleDonnees instanceof String)
1065
			{
1066
				String str = (String)nouvelleDonnees ;
107 aurelien 1067
				observationMediateur.obtenirNombreObservation() ;
77 jpm 1068
			}
140 aurelien 1069
 
1070
			if(nouvelleDonnees instanceof String[]) {
1071
				String[] anumNom = (String[])nouvelleDonnees ;
1072
				numeroNom = anumNom[1];
1073
				espece.setValue(anumNom[0]);
1074
				setModification("false");
1075
			}
248 aurelien 1076
 
1077
			if(nouvelleDonnees instanceof EntiteGeographiqueObservation)
1078
			{
1079
				EntiteGeographiqueObservation infosComm = (EntiteGeographiqueObservation)nouvelleDonnees ;
268 aurelien 1080
				if(rechercheCommuneEnCours) {
1081
					afficherIndicationCommune(infosComm);
1082
				} else {
1083
					rafraichirCommuneEtCoord(infosComm);
1084
				}
248 aurelien 1085
			}
20 david 1086
 
13 david 1087
	}
248 aurelien 1088
 
1089
 
268 aurelien 1090
	private void afficherIndicationCommune(
1091
			final EntiteGeographiqueObservation infosCom) {
248 aurelien 1092
 
1093
		String nCommune = "";
962 aurelien 1094
		if(infosCom != null && !infosCom.getZoneGeo().trim().equals("")){
1095
			nCommune += infosCom.getZoneGeo();
1096
			if(!infosCom.getIdZoneGeo().trim().equals(""))
1097
			nCommune += " ("+Util.convertirChaineZoneGeoVersCodeInsee(infosCom.getIdZoneGeo())+")";
681 aurelien 1098
 
1099
			lienSelectionCommune.setHtml("<a id=\"lien_selection_commune\" tabindex=\"9\">"+nCommune+"</a>");
1100
			lienSelectionCommune.setStyleName("img-curseur-depl");
1101
 
1102
			Ext.get("lien_selection_commune").addListener("click",new EventCallback() {
1103
				public void execute(EventObject e) {
1104
					rafraichirCommune(infosCom);
1105
				}
1106
			});
1107
 
1108
			Ext.get("lien_selection_commune").addListener("keypress",new EventCallback() {
1109
				public void execute(EventObject e) {
1110
					if(e.getCharCode() == KEY_ENTER) {
1111
						rafraichirCommune(infosCom);
1112
					}
1113
				}
1114
			});
1115
 
1116
			Ext.get("lien_selection_commune").addListener("focus",new EventCallback() {
1117
				public void execute(EventObject e) {
1118
					Ext.get("lien_selection_commune").toggleClass("lien_sel");
1119
				}
1120
			});
1121
 
1122
			Ext.get("lien_selection_commune").addListener("blur",new EventCallback() {
1123
				public void execute(EventObject e) {
1124
					Ext.get("lien_selection_commune").toggleClass("lien_sel");
1125
				}
1126
			});
1127
 
1128
		} else {
1129
			if(rechercheCommuneEnCours) {
1130
				lienSelectionCommune.setHtml("<span id=\"aucune_selection_commune\"> Erreur de localisation </span>");
1131
			} else {
1132
				lienSelectionCommune.setHtml("<span id=\"aucune_selection_commune\"> </span>");
1133
			}
268 aurelien 1134
		}
248 aurelien 1135
 
268 aurelien 1136
		Ext.get(lienSelectionCommune.getElement()).unmask();
1137
		rechercheCommuneEnCours = false;
1138
	}
1139
 
1140
	private void rafraichirCommune(EntiteGeographiqueObservation infosCom) {
1141
		String nCommune = "";
1142
 
248 aurelien 1143
 
962 aurelien 1144
		if(infosCom.getZoneGeo() != null && !infosCom.getZoneGeo().equals("")) {
1145
			nCommune += infosCom.getZoneGeo();
248 aurelien 1146
		}
1147
 
962 aurelien 1148
		if(infosCom.getIdZoneGeo() != null && !infosCom.getIdZoneGeo().equals("")) {
1149
			String codeGeoFormate = Util.convertirChaineZoneGeoVersCodeInsee(infosCom.getIdZoneGeo());
1150
			nCommune += " ("+codeGeoFormate+")";
1151
			departement = Util.convertirChaineZoneGeoVersCodeInsee(infosCom.getIdZoneGeo());;
248 aurelien 1152
		}
1153
		commune.setValue(nCommune);
357 aurelien 1154
		communeModifiee = true;
268 aurelien 1155
	}
248 aurelien 1156
 
268 aurelien 1157
	private void rafraichirCommuneEtCoord(EntiteGeographiqueObservation infosCom) {
391 aurelien 1158
		;
1159
		// on ne remplace la commune que si le champ était vide
1160
		if(commune.getRawValue() == null || commune.getRawValue().equals("")) {
1161
			rafraichirCommune(infosCom);
1162
		}
268 aurelien 1163
 
248 aurelien 1164
		if(infosCom.getLat() != null && !infosCom.getLat().equals("")) {
1165
			latitude.setValue(infosCom.getLat());
1166
		}
1167
 
1168
		if(infosCom.getLon() != null && !infosCom.getLon().equals("")) {
1169
			longitude.setValue(infosCom.getLon());
1170
		}
264 aurelien 1171
 
357 aurelien 1172
		latModifiee = true;
1173
		longModifiee = true;
1174
 
264 aurelien 1175
		coordPanel.setVisible(true);
248 aurelien 1176
	}
1177
 
13 david 1178
	public void obtenirListeReferentielCommune() {
94 jpm 1179
 
268 aurelien 1180
	 String com=commune.getText();
20 david 1181
	 com=com.replaceAll("%","");
1182
 
1183
	 observationMediateur.obtenirListeReferentielCommune(this,com);
13 david 1184
 
1185
	}
20 david 1186
 
1187
 
1188
	public void obtenirListeReferentielNom() {
1189
 
389 david 1190
	 // FIXME : trouver un autre moyen que le hack "/*" pour rechercher les taxons lors de la saisie d'un espace apres le genre
1191
 
248 aurelien 1192
	  String esp=espece.getText().replaceAll(" ","/*");
20 david 1193
	  esp=esp.replaceAll("%","");
1194
 
1195
	  observationMediateur.obtenirListeReferentielNom(this,esp);
1196
 
1197
	}
708 aurelien 1198
 
1199
 
1200
	protected void obtenirReferentielStation() {
1201
		observationMediateur.obtenirListeReferentielPerso(this,TypesReferentiels.REFERENTIEL_STATION,station.getText());
1202
	}
1203
 
1204
 
1205
	protected void obtenirListeReferentielMilieu() {
1206
		observationMediateur.obtenirListeReferentielPerso(this,TypesReferentiels.REFERENTIEL_MILIEU,milieu.getText());
1207
	}
1208
 
1209
	protected void obtenirReferentielLieuDit() {
1210
		observationMediateur.obtenirListeReferentielPerso(this,TypesReferentiels.REFERENTIEL_LIEU_DIT,lieudit.getText());
1211
	}
20 david 1212
 
1213
 
39 david 1214
	public void ajouterObservation() {
140 aurelien 1215
 
681 aurelien 1216
		if(!Util.verifierDateFormatCel(date.getRawValue()) && !date.getRawValue().equals("")) {
1217
			Window.alert("Attention la date saisie est invalide, la date doit être au format jj/mm/aaaa");
1218
			date.setInvalidText("Date invalide");
1219
			return;
1220
		}
1221
 
389 david 1222
		if(departement != null) {
1223
		// TODO : regler le probleme a la base plutot que ce patch
1224
 
1225
			if(departement.equals("000null") || departement.equals("")) {
1226
				String[] depCom = commune.getText().split(" ");
1227
				if(depCom.length > 1) {
1228
					String dep = depCom[1].replace('(', ' ');
1229
					dep =dep.replace(')', ' ');
1230
					dep = dep.trim();
1231
					dep = dep.replace('\\',' ');
1232
					dep = dep.trim();
1233
 
1234
					try
1235
					{
1236
						int nDep = Integer.parseInt(dep);
1237
						if(nDep > 0 && nDep < 110) {
1238
							departement = dep ;
1239
						}
140 aurelien 1240
					}
389 david 1241
					catch(NumberFormatException e)
1242
					{
1243
						departement = "" ;
1244
					}
140 aurelien 1245
				}
1246
			}
1247
		}
681 aurelien 1248
 
1249
		String dateObs = Util.remplacerSeparateursDateFormatCel(date.getRawValue());
39 david 1250
 
681 aurelien 1251
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),dateObs);
264 aurelien 1252
 
1253
		String[] coords = getValeurCoordonnees();
1254
 
971 aurelien 1255
		obs.setLatitude(coords[0]);
1256
		obs.setLongitude(coords[1]);
264 aurelien 1257
 
46 david 1258
		observationMediateur.ajouterObservation(obs);
39 david 1259
	}
12 david 1260
 
71 jpm 1261
	private void modifierObservation() {
229 aurelien 1262
 
681 aurelien 1263
		if(!Util.verifierDateFormatCel(date.getRawValue()) && !date.getRawValue().equals("")) {
1264
			Window.alert("Attention la date saisie est invalide, la date doit être au format jj/mm/aaaa");
1265
			date.setInvalidText("Date invalide");
1266
			return;
1267
		}
1268
 
229 aurelien 1269
		if(departement.equals("000null") || departement.equals("")) {
1270
			String[] depCom = commune.getText().split(" ");
1271
			if(depCom.length > 1) {
1272
				String dep = depCom[1].replace('(', ' ');
1273
				dep =dep.replace(')', ' ');
1274
				dep = dep.trim();
1275
				dep = dep.replace('\\',' ');
1276
				dep = dep.trim();
1277
 
1278
				try
1279
				{
1280
					int nDep = Integer.parseInt(dep);
1281
					if(nDep > 0 && nDep < 110) {
1282
						departement = dep ;
1283
					}
1284
				}
1285
				catch(NumberFormatException e)
1286
				{
1287
					departement = "" ;
1288
				}
1289
			}
1290
		}
1291
 
681 aurelien 1292
		String dateObs = Util.remplacerSeparateursDateFormatCel(date.getRawValue());
1293
 
1294
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),dateObs);
79 david 1295
		obs.setNumeroOrdre(numeroOrdre);
216 aurelien 1296
 
264 aurelien 1297
		String[] coords = getValeurCoordonnees();
1298
 
971 aurelien 1299
		obs.setLatitude(coords[0]);
1300
		obs.setLongitude(coords[1]);
264 aurelien 1301
 
79 david 1302
		observationMediateur.modifierObservation(obs);
216 aurelien 1303
 
205 aurelien 1304
		selecteurMode.setValue("création");
1305
		setModification("false");
1306
 
71 jpm 1307
	}
77 jpm 1308
 
216 aurelien 1309
	private void modifierObservationEnMasse(Champs champModifie) {
1310
		String communeM = null;
1311
		String departementM = null;
221 aurelien 1312
		String numNomSelM = null;
216 aurelien 1313
		String lieuDitM = null;
1314
		String stationM = null;
1315
		String milieuM = null;
1316
		String dateM = null;
1317
		String especeM = null;
1318
		String commM = null;
264 aurelien 1319
		String latM = null;
1320
		String longM = null;
216 aurelien 1321
 
1322
		String champs = modeleMessageModif;
1323
 
1324
		if(communeModifiee) {
1325
			communeM = commune.getText();
221 aurelien 1326
 
1327
			if(departement.equals("000null") || departement.equals("")) {
1328
				String[] depCom = commune.getText().split(" ");
1329
				if(depCom.length > 1) {
1330
					String dep = depCom[1].replace('(', ' ');
1331
					dep =dep.replace(')', ' ');
1332
					dep = dep.trim();
1333
					dep = dep.replace('\\',' ');
1334
					dep = dep.trim();
1335
 
1336
					try
1337
					{
1338
						int nDep = Integer.parseInt(dep);
1339
						if(nDep > 0 && nDep < 110) {
1340
							departement = dep ;
1341
						}
1342
					}
1343
					catch(NumberFormatException e)
1344
					{
1345
						departement = "" ;
1346
					}
1347
				}
1348
			}
1349
 
1350
			departementM = departement;
216 aurelien 1351
		} else {
221 aurelien 1352
			champs = champs.replaceAll("commune", "");
216 aurelien 1353
		}
1354
 
221 aurelien 1355
		if(lieuDitModifie) {
216 aurelien 1356
			lieuDitM = lieudit.getText();
1357
		}else {
221 aurelien 1358
			champs = champs.replaceAll(":lieu-dit", "");
216 aurelien 1359
		}
1360
 
221 aurelien 1361
		if(stationModifiee) {
216 aurelien 1362
			stationM = station.getText();
1363
		}else {
221 aurelien 1364
			champs = champs.replaceAll(":station", "");
216 aurelien 1365
		}
1366
 
1367
		if(milieuModifie) {
1368
			milieuM = milieu.getText();
1369
		}else {
221 aurelien 1370
			champs = champs.replaceAll(":milieu", "");
216 aurelien 1371
		}
1372
 
221 aurelien 1373
		if(dateModifiee && !date.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1374
			dateM = date.getRawValue();
681 aurelien 1375
			dateM = Util.remplacerSeparateursDateFormatCel(dateM);
216 aurelien 1376
		}else {
221 aurelien 1377
			champs = champs.replaceAll(":date", "");
216 aurelien 1378
		}
1379
 
1380
		if(especeModifiee) {
1381
			especeM = espece.getText();
221 aurelien 1382
			numNomSelM = numeroNom;
216 aurelien 1383
		}else {
221 aurelien 1384
			champs = champs.replaceAll(":espece", "");
216 aurelien 1385
		}
1386
 
1387
		if(commModifie) {
1388
			commM = comment.getText();
1389
		}else {
221 aurelien 1390
			champs = champs.replaceAll(":commentaire", "");
216 aurelien 1391
		}
1392
 
264 aurelien 1393
		if(latModifiee) {
1394
			latM = latitude.getText();
1395
		}else {
1396
			champs = champs.replaceAll(":latitude", "");
1397
		}
1398
 
1399
		if(longModifiee) {
1400
			longM = longitude.getText();
1401
		}else {
1402
			champs = champs.replaceAll(":longitude", "");
1403
		}
1404
 
221 aurelien 1405
		champs = champs.replaceAll(":",", ");
1406
		if(champs.startsWith(",")) {
1407
			champs = champs.replaceFirst(",", "");
1408
		}
216 aurelien 1409
 
221 aurelien 1410
		String message = "Voulez vous modifier le(s) champ(s) suivant(s) : "+champs+"   pour les observations selectionnées ?" ;
1411
 
216 aurelien 1412
		if(champs.trim().equals("")) {
1413
			Window.alert("Aucun champ n'a été modifié");
1414
		} else {
221 aurelien 1415
			Observation obs = new Observation(especeM,numNomSelM,communeM,departementM,lieuDitM,stationM,milieuM, commM,dateM);
216 aurelien 1416
			obs.setNumeroOrdre(numeroOrdre);
971 aurelien 1417
			obs.setLatitude(latM);
1418
			obs.setLongitude(longM);
216 aurelien 1419
			if(Window.confirm(message)) {
1420
				observationMediateur.modifierObservationEnMasse(obs);
221 aurelien 1421
				reinitialiserValeurModifiees();
216 aurelien 1422
			}
1423
		}
1424
	}
1425
 
77 jpm 1426
	private void supprimerObservation() {
1427
 
216 aurelien 1428
		observationMediateur.supprimerObservation(this, numeroOrdre);
77 jpm 1429
	}
71 jpm 1430
 
1431
	public void afficherDetailsObservation(Observation obs)
1432
	{
104 jpm 1433
		raz() ;
216 aurelien 1434
		String idLoc ;
1435
		if(obs.getIdentifiantLocalite() != VALEURS_MULTIPLES) {
1436
			idLoc =obs.getIdentifiantLocalite().replaceAll(" ","/");
1437
			idLoc = idLoc.replaceAll("%","");
1438
			idLoc = idLoc.replaceAll("\"","");
1439
			idLoc = idLoc.replace('\\',' ');
1440
			idLoc = idLoc.trim();
1441
		} else {
1442
			idLoc = obs.getIdentifiantLocalite();
1443
		}
71 jpm 1444
 
221 aurelien 1445
		if(!obs.getDate().equals("null") && !obs.getDate().equals("000null") && !obs.getDate().equals(VALEURS_MULTIPLES)) {
71 jpm 1446
			String[] dateEtHeure = obs.getDate().split(" ", 2);
110 aurelien 1447
			if(verifierFormatDate(dateEtHeure[0])) {
1448
				date.setValue(dateEtHeure[0]) ;
1449
			}
1450
			else
1451
			{
1452
				date.setRawValue("");
1453
			}
221 aurelien 1454
		} else {
1455
			date.setRawValue(VALEURS_MULTIPLES);
1456
			date.clearInvalid();
71 jpm 1457
		}
1458
		if(!obs.getLieudit().equals("null") && !obs.getLieudit().equals("000null")) {
1459
			lieudit.setValue(obs.getLieudit()) ;
1460
		}
1461
		if(!obs.getStation().equals("null") && !obs.getStation().equals("000null")) {
1462
			station.setValue(obs.getStation()) ;
1463
		}
1464
		if(!obs.getMilieu().equals("null") && !obs.getMilieu().equals("000null")) {
1465
			milieu.setValue(obs.getMilieu()) ;
1466
		}
1467
		if(!obs.getCommentaire().equals("null") && !obs.getCommentaire().equals("000null")) {
461 aurelien 1468
 
681 aurelien 1469
			comment.setRawValue(Util.remplacerSautsDeligneMalEncodes(obs.getCommentaire()));
461 aurelien 1470
 
71 jpm 1471
		}
1472
		if(!obs.getLocalite().equals("null") && !obs.getLocalite().equals("000null")) {
962 aurelien 1473
			if(!idLoc.equals("000null") && !idLoc.equals("")) {
221 aurelien 1474
				if(!idLoc.equals(VALEURS_MULTIPLES)) {
1475
					commune.setValue(obs.getLocalite()+" ("+idLoc+")") ;
1476
				} else {
1477
					commune.setValue(VALEURS_MULTIPLES);
1478
				}
140 aurelien 1479
			}
1480
			else
1481
			{
1482
				commune.setValue(obs.getLocalite());
1483
			}
71 jpm 1484
		}
1485
		if(!obs.getIdentifiantLocalite().equals("null") && !obs.getIdentifiantLocalite().equals("000null")) {
140 aurelien 1486
			departement = idLoc;
71 jpm 1487
		}
1488
		if(!obs.getNomSaisi().equals("null") && !obs.getNomSaisi().equals("000null")) {
1489
			espece.setValue(obs.getNomSaisi()) ;
1490
		}
1491
		if(!obs.getNumeroNomenclaturalSaisi().equals("null") && !obs.getNumeroNomenclaturalSaisi().equals("000null")) {
1492
			numeroNom = obs.getNumeroNomenclaturalSaisi() ;
1493
		}
83 david 1494
		if(!obs.getNumeroOrdre().equals("null") && !obs.getNumeroOrdre().equals("000nu2ll")) {
74 david 1495
			numeroOrdre = obs.getNumeroOrdre() ;
1496
		}
1497
 
962 aurelien 1498
		if(!obs.getLatitude().equals("null") && !obs.getLatitude().equals("000null")
1499
				&& !obs.getLongitude().equals("null") && !obs.getLongitude().equals("000null")) {
1500
			latitude.setValue(obs.getLatitude()) ;
1501
			longitude.setValue(obs.getLongitude()) ;
391 aurelien 1502
		}
71 jpm 1503
	}
1504
 
118 david 1505
 
104 jpm 1506
	public void raz()
71 jpm 1507
	{
118 david 1508
		raz(Champs.TOUT);
1509
 
1510
	}
1511
	public void raz(Champs champs)
1512
	{
1513
		switch (champs) {
1514
 
1515
 
1516
			case DATE:
1517
				date.reset() ;
1518
				break;
1519
 
1520
			case LIEUDIT:
1521
				lieudit.reset() ;
1522
				break;
1523
 
1524
			case STATION:
1525
				station.reset() ;
1526
				break;
1527
 
1528
			case MILIEU:
1529
				milieu.reset() ;
1530
				break;
1531
 
1532
			case COMMENT:
1533
				comment.reset() ;
1534
				break;
1535
 
1536
 
1537
			case COMMUNE:
172 aurelien 1538
				commune.reset() ;
118 david 1539
				departement ="";
268 aurelien 1540
				latitude.reset();
1541
				longitude.reset();
118 david 1542
				break;
1543
 
1544
			case ESPECE:
1545
				espece.reset();
1546
				numeroNom = "" ;
1547
				numeroOrdre = "";
1548
				break;
1549
 
264 aurelien 1550
			case LATITUDE:
1551
				latitude.reset();
268 aurelien 1552
				afficherIndicationCommune(null);
264 aurelien 1553
				break;
1554
 
1555
			case LONGITUDE:
1556
				longitude.reset();
268 aurelien 1557
				afficherIndicationCommune(null);
264 aurelien 1558
				break;
1559
 
118 david 1560
			case TOUT:
132 aurelien 1561
				commune.reset();
118 david 1562
				date.reset() ;
1563
				lieudit.reset() ;
1564
				station.reset() ;
1565
				milieu.reset() ;
1566
				comment.reset() ;
1567
				milieu.reset() ;
248 aurelien 1568
				latitude.reset();
1569
				longitude.reset();
118 david 1570
				departement ="";
1571
				espece.reset();
1572
				numeroNom = "" ;
1573
				numeroOrdre = "";
268 aurelien 1574
				afficherIndicationCommune(null);
118 david 1575
				break;
1576
 
1577
		}
71 jpm 1578
 
1579
	}
1580
 
1581
	private void setModification(String mode)
1582
	{
1583
		if(mode.equals("true")) {
1584
 
1585
			boutonOK.setText("Modifier") ;
1586
			setTitle("Modification") ;
77 jpm 1587
			boutonAnnuler.setText("Supprimer") ;
71 jpm 1588
			modification = true ;
97 jpm 1589
			selecteurMode.removeClass("x-selec-crea") ;
1590
			selecteurMode.setCls("x-selec-modif") ;
216 aurelien 1591
			observationMediateur.onModeModification();
71 jpm 1592
		}
1593
		else
1594
		{
264 aurelien 1595
			boutonOK.setText("Créer") ;
71 jpm 1596
			setTitle("Saisir") ;
77 jpm 1597
			boutonAnnuler.setText("Réinitialiser") ;
71 jpm 1598
			modification = false ;
97 jpm 1599
			selecteurMode.removeClass("x-selec-modif") ;
1600
			selecteurMode.setCls("x-selec-crea") ;
246 aurelien 1601
			observationMediateur.onModeCreation();
132 aurelien 1602
		}
71 jpm 1603
	}
1604
 
1605
	/**
1606
	 * renvoie vrai si on est en mode modification, faux si on est en mode création
1607
	 * @return
1608
	 */
1609
	public boolean getModification()
1610
	{
1611
		return modification ;
1612
	}
110 aurelien 1613
 
216 aurelien 1614
	/**
1615
	 * renvoie vrai si on est en mode modification de masse, faux sinon
1616
	 * @return
1617
	 */
1618
	public boolean getMasseModification()
1619
	{
1620
		return masseModification ;
1621
	}
1622
 
110 aurelien 1623
	public boolean verifierFormatDate(String date) {
1624
 
132 aurelien 1625
		String regex = "[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}" ;
110 aurelien 1626
		if(date.matches(regex) && !date.equals("0000-00-00")) {
1627
			return true ;
1628
		}
1629
		else {
1630
			return false;
1631
		}
1632
	}
216 aurelien 1633
 
1634
	public void setMasseModification(boolean masseModification) {
1635
		this.masseModification = masseModification;
1636
		if(masseModification) {
1637
			reinitialiserValeurModifiees();
1638
		}
1639
	}
132 aurelien 1640
 
216 aurelien 1641
	private void calculerAfficherDifferences(ListeObservation listeObs) {
1642
 
1643
		String departement = null;
1644
		String commune = null;
1645
		String lieuDit = null;
1646
		String station = null;
1647
		String milieu = null;
1648
		String espece = null;
1649
		String date = null;
1650
		String notes = null;
264 aurelien 1651
		String lat = null;
1652
		String lon = null;
216 aurelien 1653
 
1654
		String ordreObs = "";
1655
 
1656
		for(Iterator<String> it = listeObs.keySet().iterator();it.hasNext();) {
1657
			Observation obsEnCours = listeObs.get(it.next());
1658
			departement = comparerDifferencesChamps(departement, obsEnCours.getIdentifiantLocalite());
1659
			commune = comparerDifferencesChamps(commune, obsEnCours.getLocalite());
1660
			lieuDit = comparerDifferencesChamps(lieuDit, obsEnCours.getLieudit());
1661
			station = comparerDifferencesChamps(station, obsEnCours.getStation());
1662
			milieu = comparerDifferencesChamps(milieu, obsEnCours.getMilieu());
1663
			espece = comparerDifferencesChamps(espece, obsEnCours.getNomSaisi());
1664
			date = comparerDifferencesChamps(date, obsEnCours.getDate());
1665
			notes = comparerDifferencesChamps(notes, obsEnCours.getCommentaire());
962 aurelien 1666
			lat = comparerDifferencesChamps(lat, obsEnCours.getLatitude());
1667
			lon = comparerDifferencesChamps(lon, obsEnCours.getLongitude());
216 aurelien 1668
 
1669
			ordreObs += obsEnCours.getNumeroOrdre()+",";
1670
		}
1671
 
1672
		Observation obs=new Observation(espece,numeroNom,commune,departement,lieuDit,station,milieu, notes,date);
1673
		obs.setNumeroOrdre(ordreObs);
971 aurelien 1674
		obs.setLatitude(lat);
1675
		obs.setLongitude(lon);
216 aurelien 1676
		rafraichir(obs, false);
1677
 
1678
	}
1679
 
1680
	private String comparerDifferencesChamps(String valeurActuelle, String nouvelleValeur) {
1681
 
1682
		String retour = "000null";
1683
 
1684
			if(valeurActuelle == null) {
1685
				retour = nouvelleValeur;
1686
			} else {
1687
				if(valeurActuelle.equals(nouvelleValeur)) {
1688
					retour = valeurActuelle;
1689
				} else {
1690
					retour = VALEURS_MULTIPLES;
1691
				}
1692
			}
1693
		return retour;
1694
	}
1695
 
1696
	private void reinitialiserValeurModifiees() {
1697
 
1698
		communeModifiee = false;
221 aurelien 1699
		lieuDitModifie = false;
1700
		stationModifiee = false;
216 aurelien 1701
		milieuModifie = false;
1702
		dateModifiee = false;
1703
		especeModifiee = false;
1704
		commModifie = false;
264 aurelien 1705
		latModifiee = false;
1706
		longModifiee = false;
216 aurelien 1707
	}
1708
 
248 aurelien 1709
	public void saisieTabindex()
1710
	{
1711
 
1712
		selecteurMode.setTabIndex(0);
1713
		commune.setTabIndex(1);
268 aurelien 1714
		lieudit.setTabIndex(3);
1715
		station.setTabIndex(4);
1716
		milieu.setTabIndex(5);
248 aurelien 1717
		coordonnees.setTabIndex(-1);
1718
		coordonnees.addListener(new TextFieldListenerAdapter() {
1719
 
1720
			public void onFocus(Field field) {
1721
				if(coordPanel.isVisible()) {
264 aurelien 1722
					latitude.focus();
248 aurelien 1723
				} else {
1724
					Ext.get("lien_carto").focus();
1725
				}
1726
			}
1727
		});
1728
 
681 aurelien 1729
		latitude.setTabIndex(8);
1730
		longitude.setTabIndex(9);
248 aurelien 1731
		comment.setTabIndex(10);
1732
		date.setTabIndex(11);
1733
		espece.setTabIndex(12);
1734
		boutonOK.setTabIndex(13);
1735
		boutonAnnuler.setTabIndex(14);
1736
 
1737
	}
1738
 
1739
	private void obtenirInformationCoord() {
1740
		if(coordonneesValides() != null) {
1741
			observationMediateur.obtenirInformationCoord(LatLng.newInstance(coordonneesValides()[0],coordonneesValides()[1]));
1742
		} else {
681 aurelien 1743
			observationMediateur.afficherFenetreCarto();
248 aurelien 1744
		}
1745
 
1746
	}
1747
 
1748
	private void obtenirInformationCommune() {
962 aurelien 1749
		observationMediateur.obtenirInformationCommune(getCommuneSansDepartement(), obtenirDepartementAPartirChampCommune());
248 aurelien 1750
	}
1751
 
391 aurelien 1752
	public double[] coordonneesValides() {
248 aurelien 1753
 
1754
		try {
1755
 
1756
			double lat = Double.parseDouble(latitude.getValueAsString().replaceAll(",", "."));
1757
			double lon = Double.parseDouble(longitude.getValueAsString().replaceAll(",", "."));
1758
 
1759
			double[] coord = {lat, lon};
1760
			return coord;
1761
 
1762
		} catch (NumberFormatException ne) {
1763
			return null;
1764
		}
1765
	}
1766
 
264 aurelien 1767
	private String[] getValeurCoordonnees() {
1768
		double[] coDouble = coordonneesValides();
1769
 
1770
		if(coDouble != null) {
1771
			String[] coord = {coDouble[0]+"",coDouble[1]+""};
1772
			return coord;
1773
		} else {
1774
			String[] coord = {"000null","000null" };
1775
			return coord;
1776
		}
1777
	}
1778
 
248 aurelien 1779
	private String obtenirDepartementAPartirChampCommune() {
264 aurelien 1780
 
1781
		String dep = "";
1782
 
656 aurelien 1783
		if(departement == null) {
1784
			departement = "";
1785
		}
1786
 
248 aurelien 1787
		if(departement.equals("000null") || departement.equals("")) {
264 aurelien 1788
 
248 aurelien 1789
			String[] depCom = commune.getText().split(" ");
1790
			if(depCom.length > 1) {
264 aurelien 1791
				dep = depCom[1].replace('(', ' ');
1792
			} else {
1793
				dep = "";
248 aurelien 1794
			}
264 aurelien 1795
		} else {
1796
			dep = departement;
248 aurelien 1797
		}
1798
 
264 aurelien 1799
		dep = dep.replace(')', ' ');
1800
		dep = dep.trim();
1801
		dep = dep.replace('\\',' ');
1802
		dep = dep.trim();
1803
 
1804
		try
1805
		{
1806
			int nDep = Integer.parseInt(dep);
1807
			if(nDep > 0 && nDep < 110) {
1808
				departement = dep ;
1809
			}
1810
 
962 aurelien 1811
			if(departement.length() == 4) {
264 aurelien 1812
				departement = "0"+departement;
1813
			}
962 aurelien 1814
 
1815
			departement = departement.substring(0,2);
264 aurelien 1816
		}
1817
		catch(NumberFormatException e)
1818
		{
1819
			departement = "" ;
1820
		}
1821
 
248 aurelien 1822
		return departement;
1823
	}
1824
 
268 aurelien 1825
	public String getCommune() {
656 aurelien 1826
 
1827
		String valeurCommune = "";
1828
 
1829
		if(commune.getValue() != null) {
1830
			valeurCommune = commune.getValue();
1831
		}
1832
		return valeurCommune;
268 aurelien 1833
	}
1834
 
1835
	public String getDepartement() {
1836
		return obtenirDepartementAPartirChampCommune();
1837
	}
681 aurelien 1838
 
656 aurelien 1839
	public String getCommuneSansDepartement() {
1840
		return Util.supprimerNumDepartementChaineLocalite(getCommune());
1841
	}
268 aurelien 1842
 
1843
	public boolean communeInitialisee() {
1844
		return communeModifiee;
1845
	}
318 aurelien 1846
 
1847
	public void redimensionnerFormulaire() {
681 aurelien 1848
		//htmlCommunePanel.setWidth(panneauPremierColonne.getWidth() - 10);
1849
		afficherFormulaireLatLon.setWidth(panneauIntermediaire.getWidth()+"px");
1850
		panneauPremierColonne.doLayout();
1851
		panneauSecondeColonne.doLayout();
1852
		panneauIntermediaire.doLayout();
708 aurelien 1853
 
1854
		/*if(panneauPremierColonne.getWidth() < 450 ) {
1855
			basculerverscarto.setHTML("<a id=\"lien_carto\" href=\"#\" tabindex=\"2\">Localiser</a>");
1856
			commune.setWidth(180);
1857
			basculerverscarto.setWidth("60px");
1858
			htmlCommunePanel.doLayout();
1859
		} else {
1860
			basculerverscarto.setHTML("<a id=\"lien_carto\" href=\"#\" tabindex=\"2\">Localiser la commune</a>");
1861
			commune.setWidth(290);
1862
			basculerverscarto.setWidth("160px");
1863
			htmlCommunePanel.doLayout();
1864
		}*/
1865
 
1866
		doLayout();
318 aurelien 1867
	}
12 david 1868
}