Subversion Repositories eFlore/Applications.cel

Rev

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