Subversion Repositories eFlore/Applications.cel

Rev

Rev 276 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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