Subversion Repositories eFlore/Applications.cel

Rev

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