Subversion Repositories eFlore/Applications.cel

Rev

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