Subversion Repositories eFlore/Applications.cel

Rev

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