Subversion Repositories eFlore/Applications.cel

Rev

Rev 2602 | 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
 
2603 aurelien 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();
2603 aurelien 755
				formChamp.redimensionner(popUpAjoutChampEtendu.getOffsetWidth() - 13);
1940 aurelien 756
			}
757
		});
758
	}
759
 
1945 aurelien 760
	private void ajouterChampEtenduAuFormulaire(ChampSaisieEtendu nChamp, boolean fermerPopup) {
2602 aurelien 761
		ChampEtendu chet = new ChampEtendu(nChamp.getCle(), nChamp.getLabel(), "");
1940 aurelien 762
		Map<String, ChampEtendu> champsEt = getValeursChampsEtendus();
1945 aurelien 763
		if(!champsEt.containsKey(chet.getCle())) {
764
			champsEt.put(chet.getCle(), chet);
765
			afficherChampsEtendus = true;
766
			if(fermerPopup) {
767
				afficherChampsEtendus(champsEt, chet);
768
				popUpAjoutChampEtendu.clear();
769
				popUpAjoutChampEtendu.hide();
770
			} else {
771
				afficherChampsEtendus(champsEt, null);
772
			}
773
		} else {
774
			Window.alert("Le champ "+chet.getLabel()+" est déjà présent dans le formulaire");
775
		}
1940 aurelien 776
	}
777
 
1641 aurelien 778
	private void ajouterToolTipsBoutons() {
779
		boutonOK.setTitle("Crée une nouvelle observation à partir des champs saisis dans le formulaire");
780
		boutonModifier.setTitle("Modifie la ou les observations sélectionnées");
781
		boutonSupprimer.setTitle("Supprime la ou les observations sélectionnées");
1858 raphael 782
		boutonAnnuler.setTitle("Vide tous les champs du formulaire");
1641 aurelien 783
	}
1858 raphael 784
 
1542 aurelien 785
	private void surPremierAffichageCoordPanel(final double largeur) {
786
		ExtElement lienCoord = Ext.get("lien_coord");
787
		lienCoord.removeAllListeners();
788
		lienCoord.addListener("click", new EventCallback() {
789
			@Override
790
			public void execute(EventObject e) {
1858 raphael 791
 
1542 aurelien 792
				coordPanel.setVisible(!coordPanel.isVisible());
1858 raphael 793
 
1542 aurelien 794
				if(Ext.isIE()) {
795
					latitude.focus();
120 aurelien 796
				}
1858 raphael 797
 
1542 aurelien 798
				CarnetEnLigneMediateur.fireResize();
799
			}
800
		}) ;
1858 raphael 801
 
1542 aurelien 802
		ExtElement lienCartoCoord = Ext.get("lien_carto_coord");
803
		lienCartoCoord.removeAllListeners();
804
		lienCartoCoord.addListener("click", new EventCallback() {
805
			@Override
806
			public void execute(EventObject e) {
807
				obtenirInformationCoord();
808
			}
809
		}) ;
1858 raphael 810
 
1542 aurelien 811
		ExtElement lienCarto = Ext.get("lien_carto");
812
		lienCarto.removeAllListeners();
813
		lienCarto.addListener("click", new EventCallback() {
20 david 814
 
1542 aurelien 815
			@Override
816
			public void execute(EventObject e) {
1858 raphael 817
 
2568 aurelien 818
				if(localite.getValue() != null && !localite.getValue().equals("")) {
819
					obtenirInformationLocalite();
1542 aurelien 820
					longlatAjoutee = true;
821
				} else {
2589 aurelien 822
					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 823
				}
1542 aurelien 824
			}
825
		});
1858 raphael 826
 
1542 aurelien 827
		if(!Ext.isIE() && Window.getClientWidth() < 1200) {
1858 raphael 828
 
1542 aurelien 829
			int largeurN = (int)largeur;
1858 raphael 830
 
1542 aurelien 831
			latitude.setWidth(largeurN+"px");
832
			longitude.setWidth(largeurN+"px");
2568 aurelien 833
			lienSelectionlocalite.setWidth(largeurN+"px");
1542 aurelien 834
		}
835
	}
1858 raphael 836
 
1542 aurelien 837
	private void ajouterListeners()
1858 raphael 838
	{
839
		// Listener completion communne
1542 aurelien 840
		final Rafraichissable r = this;
1858 raphael 841
 
2568 aurelien 842
		ListenerConfig listenerConfiglocalite=new ListenerConfig();
843
		listenerConfiglocalite.setDelay(200);
844
		listenerConfiglocalite.setStopPropagation(false);
845
		listenerConfiglocalite.setStopEvent(false);
1488 aurelien 846
 
1542 aurelien 847
	    date.addListener(new DatePickerListenerAdapter() {
1488 aurelien 848
 
1542 aurelien 849
			@Override
850
			public void onSelect(DatePicker dataPicker, Date date) {
851
				dateModifiee = true;
852
			}
853
	    });
1858 raphael 854
 
1542 aurelien 855
	    ListenerConfig listenerConfigAutocompletion=new ListenerConfig();
856
	    listenerConfigAutocompletion.setDelay(200);
857
	    listenerConfigAutocompletion.setStopPropagation(false);
858
	    listenerConfigAutocompletion.setStopEvent(false);
1858 raphael 859
 
1542 aurelien 860
		ListenerConfig listenerConfigEspece=new ListenerConfig();
861
		listenerConfigEspece.setDelay(10);
862
		listenerConfigEspece.setStopPropagation(false);
863
		listenerConfigEspece.setStopEvent(false);
1858 raphael 864
 
1542 aurelien 865
		tCoord = new Timer() {
1488 aurelien 866
 
1542 aurelien 867
			@Override
868
			public void run() {
869
	        	double[] coord = coordonneesValides();
2568 aurelien 870
	        	if(!recherchelocaliteEnCours && coord != null && (longModifiee || latModifiee)) {
871
	        		recherchelocaliteEnCours = true;
872
	        		Ext.get(lienSelectionlocalite.getElement()).mask("recherche");
1958 aurelien 873
	        		observationMediateur.obtenirInformationCoord(r,coord[0], coord[1]);
1542 aurelien 874
	        	}
875
			}
1858 raphael 876
 
1542 aurelien 877
		};
1858 raphael 878
 
2568 aurelien 879
		ajouterListenerChampEvenementsClavier(localite, listenerConfiglocalite);
1542 aurelien 880
	    ajouterListenerChampEvenementsClavier(date);
881
		ajouterListenerChampEvenementsClavier(selecteurReferentielTaxo);
882
		ajouterListenerChampEvenementsClavier(espece, listenerConfigEspece);
883
		ajouterListenerChampEvenementsClavier(comment);
884
		ajouterListenerChampEvenementsClavier(latitude);
885
		ajouterListenerChampEvenementsClavier(longitude);
1572 aurelien 886
		ajouterListenerChampEvenementsClavier(altitude);
1858 raphael 887
		ajouterListenerChampEvenementsClavier(selecteurAbondance);
888
		ajouterListenerChampEvenementsClavier(selecteurCertitude);
1542 aurelien 889
		ajouterListenerChampEvenementsClavier(selecteurStadePheno);
890
		ajouterListenerChampsCombobox();
1858 raphael 891
 
20 david 892
		boutonOK.addListener(new ButtonListenerAdapter() {
1292 aurelien 893
			@Override
1858 raphael 894
			public void onClick(Button button, EventObject e) {
1641 aurelien 895
				ajouterObservation();
1858 raphael 896
			}
1641 aurelien 897
		});
1858 raphael 898
 
1641 aurelien 899
		boutonModifier.addListener(new ButtonListenerAdapter() {
900
			@Override
1858 raphael 901
			public void onClick(Button button, EventObject e) {
1641 aurelien 902
				if(selectionMultiple) {
2602 aurelien 903
					modifierObservationEnMasse(null);
1641 aurelien 904
				} else {
905
					modifierObservation() ;
71 jpm 906
				}
1858 raphael 907
			}
1641 aurelien 908
		});
1858 raphael 909
 
1641 aurelien 910
		boutonSupprimer.addListener(new ButtonListenerAdapter() {
911
			@Override
1858 raphael 912
			public void onClick(Button button, EventObject e) {
1641 aurelien 913
				if(!selectionMultiple) {
914
					supprimerObservation();
915
				} else {
916
					observationMediateur.supprimerObservations();
71 jpm 917
				}
1858 raphael 918
			}
20 david 919
		});
1858 raphael 920
 
921
		boutonAnnuler.addListener(new ButtonListenerAdapter() {
1292 aurelien 922
			@Override
1858 raphael 923
			public void onClick(Button button, EventObject e) {
1641 aurelien 924
					setSelectionMultiple(false);
104 jpm 925
					raz();
1858 raphael 926
			}
12 david 927
		});
1858 raphael 928
 
132 aurelien 929
		this.addListener(new ContainerListenerAdapter() {
1292 aurelien 930
			@Override
132 aurelien 931
			public void onAfterLayout(Container self) {
2568 aurelien 932
				localite.focus();
132 aurelien 933
			}
1858 raphael 934
		});
12 david 935
	}
1858 raphael 936
 
1542 aurelien 937
	private void ajouterListenerChampsCombobox() {
2568 aurelien 938
		localite.addListener(new ComboBoxListenerAdapter() {
1542 aurelien 939
            @Override
1858 raphael 940
			public void onSelect(ComboBox comboBox, Record record, int index) {
2568 aurelien 941
                localite.setValue(record.getAsString("localite"));
942
                codeLocalite=record.getAsString("departement");
943
                selectionlocalite=true;
944
                localite.collapse();
1858 raphael 945
            }
946
 
1542 aurelien 947
            @Override
948
			public void onExpand(ComboBox comboBox) {
949
           	 comboBox.focus();
950
            }
1858 raphael 951
        });
952
 
953
		selecteurReferentielTaxo.addListener(new ComboBoxListenerAdapter() {
1542 aurelien 954
             @Override
1672 aurelien 955
			public void onSelect(ComboBox comboBox, Record record, int index) {
1542 aurelien 956
            	 referentielTaxo = record.getAsString("valeur");
957
                 observationMediateur.setRefTaxSelectionne(index);
958
                 referentielTaxoModifie = true;
1858 raphael 959
             }
960
         });
961
 
962
		espece.addListener(new ComboBoxListenerAdapter() {
1542 aurelien 963
             @Override
1858 raphael 964
			public void onSelect(ComboBox comboBox, Record record, int index) {
1542 aurelien 965
            	 espece.setValue(record.getAsString("nom"));
966
            	 numeroNom=record.getAsString("numeroNom");
967
                 selectionEspece=true;
968
                 observationMediateur.obtenirImageInformationExternes(referentielTaxo, numeroNom);
1858 raphael 969
             }
970
         });
971
 
972
		selecteurAbondance.addListener(new ComboBoxListenerAdapter() {
1542 aurelien 973
			@Override
1858 raphael 974
			public void onSelect(ComboBox comboBox, Record record, int index) {
1542 aurelien 975
                 selectionAbondance=true;
976
                 abondanceModifiee = true;
977
             }
978
         });
708 aurelien 979
 
1858 raphael 980
		selecteurCertitude.addListener(new ComboBoxListenerAdapter() {
981
 
1542 aurelien 982
			@Override
1858 raphael 983
			public void onSelect(ComboBox comboBox, Record record, int index) {
1542 aurelien 984
                 selectionCertitude=true;
985
                 certitudeModifiee = true;
986
             }
1858 raphael 987
         });
988
 
989
		selecteurStadePheno.addListener(new ComboBoxListenerAdapter() {
1542 aurelien 990
			@Override
1858 raphael 991
			public void onSelect(ComboBox comboBox, Record record, int index) {
1542 aurelien 992
                 selectionPhenologie=true;
993
                 phenologieModifiee = true;
994
             }
1858 raphael 995
         });
1542 aurelien 996
	}
1858 raphael 997
 
1542 aurelien 998
	private void ajouterListenerChampEvenementsClavier(final TextField champ) {
999
		champ.addKeyPressListener(new EventCallback() {
1000
			@Override
1001
			public void execute(EventObject e) {
1002
				surEvenementClavier(e, champ);
1003
			}
1004
	    });
1005
	}
1858 raphael 1006
 
1542 aurelien 1007
	private void ajouterListenerChampEvenementsClavier(final TextField champ, final ListenerConfig config) {
1008
		champ.addKeyPressListener(new EventCallback() {
1009
			@Override
1010
			public void execute(EventObject e) {
1011
				surEvenementClavier(e, champ);
1012
			}
1013
	    }, config);
1014
	}
1858 raphael 1015
 
1542 aurelien 1016
	private void surEvenementClavier(EventObject e, TextField champ) {
1858 raphael 1017
		switch(e.getKey()) {
1542 aurelien 1018
			case KEY_ALT:
1019
			case KEY_CTRL:
1020
			case KEY_DOWN:
1021
			case KEY_END:
1022
			case KEY_ESCAPE:
1023
			case KEY_HOME:
1024
			case KEY_LEFT:
1025
			case KEY_PAGEDOWN:
1026
			case KEY_PAGEUP:
1027
			case KEY_RIGHT:
1028
			case KEY_SHIFT:
1029
			case KEY_TAB:
1030
			case KEY_UP:
1031
	        break;
1858 raphael 1032
 
1542 aurelien 1033
		    case KEY_ENTER:
1034
		    	surEvenementClavierToucheEntree(champ);
1035
		    	break;
1858 raphael 1036
 
1542 aurelien 1037
	        default:
1038
	        	gererEvenementClavierDefaut(champ);
1039
	        break;
1040
		}
1041
	}
1858 raphael 1042
 
1542 aurelien 1043
	private void surEvenementClavierToucheEntree(TextField champ) {
1044
		//TODO: faire un switch ou une enum
1045
		if(champ.equals(selecteurStadePheno)) {
1858 raphael 1046
			if(!selectionPhenologie) {
1047
  	    		validerSaisie(Champs.PHENOLOGIE);
1542 aurelien 1048
	    	} else {
1049
	    		selectionPhenologie = false;
1050
	    	}
1051
		}
1858 raphael 1052
 
1542 aurelien 1053
		if(champ.equals(selecteurCertitude)) {
1858 raphael 1054
			if(!selectionCertitude) {
1055
		    		validerSaisie(Champs.CERTITUDE);
1542 aurelien 1056
	    	} else {
1057
	    		selectionCertitude = false;
1058
	    	}
1059
		}
1858 raphael 1060
 
1542 aurelien 1061
		if(champ.equals(selecteurAbondance)) {
1858 raphael 1062
			if(!selectionAbondance) {
1063
		    	validerSaisie(Champs.ABONDANCE);
1542 aurelien 1064
	    	} else {
1065
	    		selectionAbondance = false;
1066
	    	}
1067
		}
1858 raphael 1068
 
1542 aurelien 1069
		if(champ.equals(longitude)) {
1070
			validerSaisie(Champs.LONGITUDE);
1071
		}
1858 raphael 1072
 
1073
		if(champ.equals(latitude)) {
1074
	    	validerSaisie(Champs.LATITUDE);
1542 aurelien 1075
		}
1858 raphael 1076
 
1077
		if(champ.equals(altitude)) {
1078
	    	validerSaisie(Champs.ALTITUDE);
1572 aurelien 1079
		}
1858 raphael 1080
 
1542 aurelien 1081
		if(champ.equals(espece)) {
1082
			if(selectionEspece) {
1083
	    		especeModifiee = true;
1084
	    		selectionEspece=false;
1085
	    	}
1086
	    	else {
1858 raphael 1087
	    		validerSaisie(Champs.ESPECE);
1542 aurelien 1088
	    	}
1089
		}
1858 raphael 1090
 
1542 aurelien 1091
		if(champ.equals(selecteurReferentielTaxo)) {
1858 raphael 1092
			validerSaisie(Champs.REFERENTIELTAXO);
1542 aurelien 1093
		}
1858 raphael 1094
 
1542 aurelien 1095
		if(champ.equals(date)) {
1858 raphael 1096
			validerSaisie(Champs.DATE);
1542 aurelien 1097
		}
1858 raphael 1098
 
2568 aurelien 1099
		if(champ.equals(localite)) {
1100
			if(champ.equals(localite)) {
1101
				if (selectionlocalite) {
1102
		    		 localiteModifiee= true;
1103
		    		 selectionlocalite=false;
1542 aurelien 1104
		    	 }
1105
		    	else {
2568 aurelien 1106
		    		validerSaisie(Champs.LOCALITE);
1542 aurelien 1107
		    	 }
1108
			}
1109
		}
1110
	}
1858 raphael 1111
 
1542 aurelien 1112
	private void gererEvenementClavierDefaut(TextField champ) {
1113
		//TODO: faire un switch ou une enum
1114
		if(champ.equals(selecteurStadePheno)) {
1115
			selecteurStadePheno.setRawValue(selecteurStadePheno.getRawValue());
1116
			selecteurStadePheno.setValue(selecteurStadePheno.getRawValue());
1117
			phenologieModifiee = true;
1118
			selectionPhenologie = false;
1119
		}
1858 raphael 1120
 
1542 aurelien 1121
		if(champ.equals(selecteurCertitude)) {
1122
			selecteurCertitude.setRawValue(selecteurCertitude.getRawValue());
1123
	    	selecteurCertitude.setValue(selecteurCertitude.getRawValue());
1124
	    	certitudeModifiee = true;
1125
	    	selectionCertitude = false;
1126
		}
1858 raphael 1127
 
1542 aurelien 1128
		if(champ.equals(selecteurAbondance)) {
1129
			selecteurAbondance.setRawValue(selecteurAbondance.getRawValue());
1130
	    	selecteurAbondance.setValue(selecteurAbondance.getRawValue());
1131
	    	abondanceModifiee = true;
1132
	    	selectionAbondance = false;
1133
		}
1858 raphael 1134
 
1542 aurelien 1135
		if(champ.equals(longitude)) {
1136
			longModifiee = true;
1137
        	tCoord.cancel();
1138
        	tCoord.schedule(250);
1139
		}
1858 raphael 1140
 
1141
		if(champ.equals(latitude)) {
1542 aurelien 1142
			latModifiee = true;
1143
	      	tCoord.cancel();
1144
	      	tCoord.schedule(250);
1145
		}
1858 raphael 1146
 
1147
		if(champ.equals(altitude)) {
1148
			altModifiee = true;
1572 aurelien 1149
		}
1858 raphael 1150
 
1542 aurelien 1151
		if(champ.equals(comment)) {
1152
			commModifie = true;
1153
		}
1858 raphael 1154
 
1542 aurelien 1155
		if(champ.equals(espece)) {
1156
			numeroNom="";
1157
	    	obtenirListeReferentielNom();
1158
	    	especeModifiee = true;
1159
		}
1858 raphael 1160
 
1542 aurelien 1161
		if(champ.equals(selecteurReferentielTaxo)) {
1162
			referentielTaxoModifie = true;
1163
		}
1858 raphael 1164
 
1542 aurelien 1165
		if(champ.equals(date)) {
1166
			dateModifiee = true;
1167
		}
1858 raphael 1168
 
2568 aurelien 1169
		if(champ.equals(localite)) {
1170
			codeLocalite="";
1171
	    	localite.collapse();
1172
	    	obtenirListeReferentiellocalite();
1173
	    	localiteModifiee= true;
1542 aurelien 1174
		}
1175
	}
1176
 
12 david 1177
	/**
1858 raphael 1178
	 * Validation de la saisie
118 david 1179
	 */
1858 raphael 1180
 
118 david 1181
	private void validerSaisie(Champs champs) {
1641 aurelien 1182
		if(!selectionMultiple) {
118 david 1183
			ajouterObservation();
1184
			raz(champs);
1641 aurelien 1185
		} else {
1186
			modifierObservationEnMasse(champs);
118 david 1187
		}
1188
	}
1858 raphael 1189
 
118 david 1190
	/**
12 david 1191
	 * Desactive visuellement ce panneau
1192
	 */
1193
	public void desactiverPanneau()
1194
	{
1195
		this.setDisabled(true) ;
1196
	}
1858 raphael 1197
 
12 david 1198
	/**
1199
	 * Active visuellement ce panneau
1200
	 */
1201
	public void activerPanneau()
1202
	{
1203
		this.setDisabled(false) ;
1204
	}
13 david 1205
 
1292 aurelien 1206
	@Override
13 david 1207
	public void rafraichir(Object nouvelleDonnees, boolean repandreRaffraichissement) {
1858 raphael 1208
 
2568 aurelien 1209
		// si l'on a reçu une liste du referentiel localite (completion referentiel localite)
1210
		if(nouvelleDonnees instanceof ListeReferentielLocalite)
1672 aurelien 1211
		{
2568 aurelien 1212
			ListeReferentielLocalite data = (ListeReferentielLocalite) nouvelleDonnees ;
1213
			Object[][] localiteData = new Object[data.size()][3];
1672 aurelien 1214
			int i = 0 ;
1858 raphael 1215
 
1672 aurelien 1216
			// on la parse et on récupère les informations quiç nous interessent
1858 raphael 1217
			for (Iterator it = data.keySet().iterator(); it.hasNext();)
1218
			{
2568 aurelien 1219
				ReferentielLocalite ref=data.get(it.next());
1858 raphael 1220
 
2568 aurelien 1221
				localiteData[i][0]= ref.getLocalite();
1222
				localiteData[i][1]= ref.getCodeLocalite();
1223
				localiteData[i][2]= ref.getCodeInsee();
1672 aurelien 1224
				i++ ;
13 david 1225
			}
1858 raphael 1226
 
1672 aurelien 1227
			// creation du store
2568 aurelien 1228
			FieldDef deflocalite = new StringFieldDef("localite");
1672 aurelien 1229
			FieldDef defDepartement = new StringFieldDef("departement");
1230
			FieldDef defCodeInsee = new StringFieldDef("codeInsee");
1858 raphael 1231
 
2568 aurelien 1232
			FieldDef[] defTab = { deflocalite, defDepartement, defCodeInsee};
1858 raphael 1233
 
1672 aurelien 1234
			RecordDef rd = new RecordDef(defTab);
1858 raphael 1235
 
2568 aurelien 1236
			final MemoryProxy dataProxy = new MemoryProxy(localiteData);
1858 raphael 1237
			final ArrayReader reader = new ArrayReader(rd);
1238
 
1239
			Store store=new Store(dataProxy,reader);
2568 aurelien 1240
			localite.setStore(store);
1672 aurelien 1241
			store.load();
1858 raphael 1242
 
1672 aurelien 1243
		}
1858 raphael 1244
 
1672 aurelien 1245
		// si l'on a reçu une liste du référentiel nom (complétion referentiel nom)
1246
		if(nouvelleDonnees instanceof ListeReferentielNom)
1247
		{
1248
			ListeReferentielNom data = (ListeReferentielNom) nouvelleDonnees ;
1249
			Object[][] nomData = new Object[data.size()][3];
1250
			int i = 0 ;
1251
 
1252
			// on la parse et on récupère les informations qui nous interessent
1858 raphael 1253
			for (Iterator it = data.keySet().iterator(); it.hasNext();)
71 jpm 1254
			{
1858 raphael 1255
 
1672 aurelien 1256
				ReferentielNom ref=data.get(it.next());
1858 raphael 1257
 
1672 aurelien 1258
				nomData[i][0]= ref.getNom();
1259
				nomData[i][1]= ref.getNumeroNom();
1260
				if (ref.getStatut().equals("3")) {
1261
					nomData[i][2]="nom_retenu";
1262
				}
1263
				else {
1264
					nomData[i][2]="";
1858 raphael 1265
				}
1672 aurelien 1266
				i++ ;
216 aurelien 1267
			}
1672 aurelien 1268
 
1269
			FieldDef defNom = new StringFieldDef("nom");
1270
			FieldDef defNumeroNom = new StringFieldDef("numeroNom");
1271
			FieldDef indicateurNomRetenu = new StringFieldDef("indicateurNomRetenu");
1858 raphael 1272
 
1672 aurelien 1273
			FieldDef[] defTab = { defNom, defNumeroNom, indicateurNomRetenu};
1858 raphael 1274
 
1672 aurelien 1275
			RecordDef rd = new RecordDef(defTab);
1858 raphael 1276
 
1672 aurelien 1277
			final MemoryProxy dataProxy = new MemoryProxy(nomData);
1858 raphael 1278
			final ArrayReader reader = new ArrayReader(rd);
1279
 
1280
			Store store=new Store(dataProxy,reader);
1672 aurelien 1281
			espece.setStore(store);
1282
			store.load() ;
1283
		}
1858 raphael 1284
 
1285
		// On recoit une observation dont on veut afficher le detail
1286
 
1672 aurelien 1287
		if(nouvelleDonnees instanceof Observation)
1288
		{
1289
			Observation obs = (Observation)nouvelleDonnees ;
1290
			setSelectionMultiple(false);
1291
			afficherDetailsObservation(obs) ;
1292
		}
1858 raphael 1293
 
1672 aurelien 1294
		if(nouvelleDonnees instanceof ListeObservation) {
1858 raphael 1295
 
1672 aurelien 1296
			ListeObservation listeObs = (ListeObservation)nouvelleDonnees;
1297
			setSelectionMultiple(true);
1298
			calculerAfficherDifferences(listeObs);
1299
		}
1858 raphael 1300
 
1672 aurelien 1301
		if(nouvelleDonnees instanceof String)
1302
		{
1303
			String str = (String)nouvelleDonnees ;
1304
			observationMediateur.obtenirNombreObservation() ;
1305
		}
1858 raphael 1306
 
1672 aurelien 1307
		if(nouvelleDonnees instanceof String[]) {
1308
			String[] anumNom = (String[])nouvelleDonnees ;
1309
			numeroNom = anumNom[1];
1310
			espece.setValue(anumNom[0]);
1311
		}
1858 raphael 1312
 
1672 aurelien 1313
		if(nouvelleDonnees instanceof EntiteGeographiqueObservation)
1314
		{
1315
			EntiteGeographiqueObservation infosComm = (EntiteGeographiqueObservation)nouvelleDonnees ;
2568 aurelien 1316
			if(recherchelocaliteEnCours) {
1317
				afficherIndicationlocalite(infosComm);
1672 aurelien 1318
			} else {
2568 aurelien 1319
				rafraichirlocaliteEtCoord(infosComm);
248 aurelien 1320
			}
1672 aurelien 1321
		}
13 david 1322
	}
1858 raphael 1323
 
2568 aurelien 1324
	private void afficherIndicationlocalite(
268 aurelien 1325
			final EntiteGeographiqueObservation infosCom) {
1858 raphael 1326
 
2568 aurelien 1327
		String nlocalite = "";
2589 aurelien 1328
		if(infosCom != null && infosCom.getZoneGeo() != null && !infosCom.getZoneGeo().trim().isEmpty()) {
2568 aurelien 1329
			nlocalite += infosCom.getZoneGeo();
2589 aurelien 1330
			if(infosCom.getIdZoneGeo() != null && !infosCom.getIdZoneGeo().trim().isEmpty()) {
2558 aurelien 1331
				if(Util.estUnNombre(infosCom.getIdZoneGeo())) {
2568 aurelien 1332
					nlocalite += " ("+Util.convertirChaineZoneGeoVersDepartement(infosCom.getIdZoneGeo())+")";
2589 aurelien 1333
				} else if(infosCom.getPays() != null && !infosCom.getPays().trim().isEmpty()) {
1334
					nlocalite += " ("+infosCom.getPays()+")";
2558 aurelien 1335
				}
2568 aurelien 1336
			} else if(infosCom.getPays() != null && !infosCom.getPays().trim().isEmpty()) {
1337
				nlocalite += " ("+infosCom.getPays()+")";
2558 aurelien 1338
			}
1858 raphael 1339
 
2568 aurelien 1340
			lienSelectionlocalite.setHtml("<a id=\"lien_selection_localite\" tabindex=\"9\">"+nlocalite+"</a>");
1341
			lienSelectionlocalite.setStyleName("img-curseur-depl");
1858 raphael 1342
 
2568 aurelien 1343
			Ext.get("lien_selection_localite").addListener("click",new EventCallback() {
1292 aurelien 1344
				@Override
681 aurelien 1345
				public void execute(EventObject e) {
2568 aurelien 1346
					rafraichirlocalite(infosCom);
1858 raphael 1347
				}
681 aurelien 1348
			});
1858 raphael 1349
 
2568 aurelien 1350
			Ext.get("lien_selection_localite").addListener("keypress",new EventCallback() {
1292 aurelien 1351
				@Override
681 aurelien 1352
				public void execute(EventObject e) {
1353
					if(e.getCharCode() == KEY_ENTER) {
2568 aurelien 1354
						rafraichirlocalite(infosCom);
681 aurelien 1355
					}
1858 raphael 1356
				}
681 aurelien 1357
			});
1858 raphael 1358
 
2568 aurelien 1359
			Ext.get("lien_selection_localite").addListener("focus",new EventCallback() {
1292 aurelien 1360
				@Override
681 aurelien 1361
				public void execute(EventObject e) {
2568 aurelien 1362
					Ext.get("lien_selection_localite").toggleClass("lien_sel");
1858 raphael 1363
				}
681 aurelien 1364
			});
1858 raphael 1365
 
2568 aurelien 1366
			Ext.get("lien_selection_localite").addListener("blur",new EventCallback() {
1292 aurelien 1367
				@Override
681 aurelien 1368
				public void execute(EventObject e) {
2568 aurelien 1369
					Ext.get("lien_selection_localite").toggleClass("lien_sel");
1858 raphael 1370
				}
681 aurelien 1371
			});
1858 raphael 1372
 
681 aurelien 1373
		} else {
2568 aurelien 1374
			if(recherchelocaliteEnCours) {
1375
				lienSelectionlocalite.setHtml("<span id=\"aucune_selection_localite\"> Erreur de localisation </span>");
681 aurelien 1376
			} else {
2568 aurelien 1377
				lienSelectionlocalite.setHtml("<span id=\"aucune_selection_localite\"> </span>");
681 aurelien 1378
			}
268 aurelien 1379
		}
248 aurelien 1380
 
2568 aurelien 1381
		Ext.get(lienSelectionlocalite.getElement()).unmask();
1382
		recherchelocaliteEnCours = false;
268 aurelien 1383
	}
1858 raphael 1384
 
2568 aurelien 1385
	private void rafraichirlocalite(EntiteGeographiqueObservation infosCom) {
1386
		String nlocalite = "";
1858 raphael 1387
 
962 aurelien 1388
		if(infosCom.getZoneGeo() != null && !infosCom.getZoneGeo().equals("")) {
2568 aurelien 1389
			nlocalite += infosCom.getZoneGeo();
248 aurelien 1390
		}
2558 aurelien 1391
 
2589 aurelien 1392
		if(infosCom.getIdZoneGeo() != null && Util.estUnNombre(infosCom.getIdZoneGeo())) {
1332 aurelien 1393
			String codeGeoFormate = Util.convertirChaineZoneGeoVersDepartement(infosCom.getIdZoneGeo());
2568 aurelien 1394
			nlocalite += " ("+codeGeoFormate+")";
1395
			codeLocalite = Util.convertirChaineZoneGeoVersDepartement(infosCom.getIdZoneGeo());
1396
		} else if(infosCom.getPays() != null && !infosCom.getPays().trim().isEmpty()) {
1397
			nlocalite += " ("+infosCom.getPays()+")";
248 aurelien 1398
		}
2558 aurelien 1399
 
2589 aurelien 1400
		if (!nlocalite.isEmpty()) {
1401
			// Vide ou null, on remplace !
1402
			if(localite.getValue() == null || localite.getValue().trim().isEmpty()) {
2568 aurelien 1403
				localite.setValue(nlocalite);
2589 aurelien 1404
			} else {
1405
				// Afin de pas effacer un pays précédemment saisi, si on a déjà saisi une localité
1406
				// avec le même nom mais avec un pays, on ne remplace rien
1407
				if(localite.getValue() != null && !localite.getValue().contains(nlocalite)) {
1408
					localite.setValue(nlocalite);
1409
				}
2568 aurelien 1410
			}
2589 aurelien 1411
 
2568 aurelien 1412
			localiteModifiee = true;
2270 mathias 1413
		}
268 aurelien 1414
	}
248 aurelien 1415
 
2276 mathias 1416
	// Se déclenche au retour de la "localisation sur la carte"
2568 aurelien 1417
	private void rafraichirlocaliteEtCoord(EntiteGeographiqueObservation infosCom) {
2558 aurelien 1418
 
2568 aurelien 1419
		rafraichirlocalite(infosCom);
248 aurelien 1420
		if(infosCom.getLat() != null && !infosCom.getLat().equals("")) {
2276 mathias 1421
			latitude.setValue(Util.tronquerNombrePourAffichage("" + infosCom.getLat(), 5));
248 aurelien 1422
		}
1423
 
1424
		if(infosCom.getLon() != null && !infosCom.getLon().equals("")) {
2276 mathias 1425
			longitude.setValue(Util.tronquerNombrePourAffichage("" + infosCom.getLon(), 5));
248 aurelien 1426
		}
1858 raphael 1427
 
357 aurelien 1428
		latModifiee = true;
1429
		longModifiee = true;
1858 raphael 1430
 
264 aurelien 1431
		coordPanel.setVisible(true);
248 aurelien 1432
	}
1433
 
2568 aurelien 1434
	public void obtenirListeReferentiellocalite() {
1858 raphael 1435
 
2568 aurelien 1436
	 String com=localite.getText();
20 david 1437
	 com=com.replaceAll("%","");
1858 raphael 1438
 
2568 aurelien 1439
	 observationMediateur.obtenirListeReferentielLocalite(this,com);
1858 raphael 1440
 
13 david 1441
	}
1858 raphael 1442
 
1443
	public void obtenirListeReferentielNom() {
1940 aurelien 1444
		String esp=espece.getText().replaceAll(" ","/*");
1445
		esp=esp.replaceAll("%","");
1446
		String referentiel = this.referentielTaxo;
1447
 
1448
		observationMediateur.obtenirListeReferentielNom(this,referentiel ,esp);
20 david 1449
	}
1858 raphael 1450
 
708 aurelien 1451
	protected void obtenirListeReferentielMilieu() {
1452
		observationMediateur.obtenirListeReferentielPerso(this,TypesReferentiels.REFERENTIEL_MILIEU,milieu.getText());
1453
	}
1454
 
1455
	protected void obtenirReferentielLieuDit() {
1456
		observationMediateur.obtenirListeReferentielPerso(this,TypesReferentiels.REFERENTIEL_LIEU_DIT,lieudit.getText());
1457
	}
1858 raphael 1458
 
39 david 1459
	public void ajouterObservation() {
1858 raphael 1460
 
1672 aurelien 1461
		if(date.getRawValue() != null && !date.getRawValue().equals("") && !Util.verifierDateFormatCel(date.getRawValue())) {
681 aurelien 1462
			Window.alert("Attention la date saisie est invalide, la date doit être au format jj/mm/aaaa");
1463
			date.setInvalidText("Date invalide");
1464
			return;
1465
		}
1858 raphael 1466
 
2568 aurelien 1467
		affecterCodeLocaliteOuPays();
1858 raphael 1468
 
681 aurelien 1469
		String dateObs = Util.remplacerSeparateursDateFormatCel(date.getRawValue());
39 david 1470
 
2568 aurelien 1471
		Observation obs=new Observation(espece.getText(),numeroNom,localite.getText(),codeLocalite,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),dateObs);
1858 raphael 1472
 
264 aurelien 1473
		String[] coords = getValeurCoordonnees();
2568 aurelien 1474
		obs.setPays(pays);
971 aurelien 1475
		obs.setLatitude(coords[0]);
1476
		obs.setLongitude(coords[1]);
1572 aurelien 1477
		obs.setAltitude(altitude.getText());
1542 aurelien 1478
 
1488 aurelien 1479
		obs.setAbondance(getAbondance());
1480
		obs.setCertitude(getCertitude());
1542 aurelien 1481
		obs.setPhenologie(getPhenologie());
1858 raphael 1482
 
1542 aurelien 1483
		obs.setReferentielTaxo(Ontologies.getInfosReferentielNomParCode(referentielTaxo).getCodeVersionComplet());
1549 aurelien 1484
		obs.setChampsEtendus(getValeursChampsEtendus());
1858 raphael 1485
 
46 david 1486
		observationMediateur.ajouterObservation(obs);
39 david 1487
	}
1542 aurelien 1488
 
71 jpm 1489
	private void modifierObservation() {
1858 raphael 1490
 
1672 aurelien 1491
		if(!Window.confirm("Êtes-vous sur de vouloir modifier l'observation sélectionnée ?")) {
1492
			return;
1493
		}
1858 raphael 1494
 
1672 aurelien 1495
		if(date.getRawValue() != null && !date.getRawValue().equals("") && !Util.verifierDateFormatCel(date.getRawValue())) {
681 aurelien 1496
			Window.alert("Attention la date saisie est invalide, la date doit être au format jj/mm/aaaa");
1497
			date.setInvalidText("Date invalide");
1498
			return;
1499
		}
1858 raphael 1500
 
2568 aurelien 1501
		affecterCodeLocaliteOuPays();
1502
 
681 aurelien 1503
		String dateObs = Util.remplacerSeparateursDateFormatCel(date.getRawValue());
1858 raphael 1504
 
2568 aurelien 1505
		Observation obs=new Observation(espece.getText(),numeroNom,localite.getText(),codeLocalite,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),dateObs);
79 david 1506
		obs.setNumeroOrdre(numeroOrdre);
1858 raphael 1507
 
264 aurelien 1508
		String[] coords = getValeurCoordonnees();
1858 raphael 1509
 
2568 aurelien 1510
		obs.setPays(pays);
971 aurelien 1511
		obs.setLatitude(coords[0]);
1512
		obs.setLongitude(coords[1]);
1572 aurelien 1513
		obs.setAltitude(altitude.getText());
1858 raphael 1514
 
1488 aurelien 1515
		obs.setAbondance(getAbondance());
1516
		obs.setCertitude(getCertitude());
1542 aurelien 1517
		obs.setPhenologie(getPhenologie());
1518
		obs.setReferentielTaxo(getReferentielTaxo());
1549 aurelien 1519
		obs.setChampsEtendus(getValeursChampsEtendus());
1858 raphael 1520
 
79 david 1521
		observationMediateur.modifierObservation(obs);
71 jpm 1522
	}
1858 raphael 1523
 
2568 aurelien 1524
	private void affecterCodeLocaliteOuPays() {
1525
 
1526
		codeLocalite = "";
1527
		pays = "";
1528
 
1529
		// Soit un numéro de département, soit un code de pays à deux lettres
1530
		String[] codeCom = localite.getText().split(" ");
2595 aurelien 1531
		if(codeCom.length > 1 && ressembleAUnCodePaysOuDepartement(codeCom[codeCom.length - 1])) {
1532
			String codeLoc = codeCom[codeCom.length - 1].replace('(', ' ');
2568 aurelien 1533
			codeLoc = codeLoc.replace(')', ' ').trim().replace('\\',' ').trim();
1534
 
1535
			if(Util.estUnNombre(codeLoc)) {
1536
				codeLocalite = codeLoc ;
1537
			} else {
2595 aurelien 1538
				pays = codeLoc.toUpperCase();
2568 aurelien 1539
			}
1540
		}
1541
	}
2595 aurelien 1542
 
1543
	private boolean ressembleAUnCodePaysOuDepartement(String s) {
1544
		String sP = s.replace("(", "").replace(")", "").trim();
1545
 
1546
		boolean contientDesParentheses = s.contains("(") && s.contains(")");
1547
		boolean estUnCodePays = !Util.estUnNombre(sP) && (sP.length() == 2);
1548
		boolean estUnCodeDepartement = Util.estUnNombre(sP) && (sP.length() >= 1 && sP.length() <= 5);
1549
 
1550
		return contientDesParentheses && (estUnCodePays || estUnCodeDepartement);
1551
	}
2568 aurelien 1552
 
216 aurelien 1553
	private void modifierObservationEnMasse(Champs champModifie) {
1858 raphael 1554
 
1542 aurelien 1555
		//TODO: factoriser
2568 aurelien 1556
		String paysM = null;
1557
		String localiteM = null;
1558
		String codeLocaliteM = null;
221 aurelien 1559
		String numNomSelM = null;
216 aurelien 1560
		String lieuDitM = null;
1561
		String stationM = null;
1562
		String milieuM = null;
1563
		String dateM = null;
1564
		String especeM = null;
1858 raphael 1565
		String commM = null;
264 aurelien 1566
		String latM = null;
1567
		String longM = null;
1572 aurelien 1568
		String altM = null;
1488 aurelien 1569
		String abondanceM = null;
1570
		String certitudeM = null;
1542 aurelien 1571
		String referentielTaxoM = null;
1572
		String phenologieM = null;
1858 raphael 1573
 
216 aurelien 1574
		String champs = modeleMessageModif;
1858 raphael 1575
 
2568 aurelien 1576
		if(localiteModifiee && ! localite.getRawValue().equals(VALEURS_MULTIPLES)) {
1577
 
1578
			localiteM = localite.getText();
1579
 
1580
			// Soit un numéro de département, soit un code de pays à deux lettres
1581
			String[] codeCom = localite.getText().split(" ");
1582
			if(codeCom.length > 1) {
1583
				String codeLoc = codeCom[1].replace('(', ' ');
1584
				codeLoc = codeLoc.replace(')', ' ').trim().replace('\\',' ').trim();
1858 raphael 1585
 
2568 aurelien 1586
				if(Util.estUnNombre(codeLoc)) {
1587
					codeLocaliteM = codeLoc ;
1588
				} else {
1589
					paysM = codeLoc;
221 aurelien 1590
				}
1591
			}
1858 raphael 1592
		}
1593
		else {
2568 aurelien 1594
			champs = champs.replaceAll("localite", "");
216 aurelien 1595
		}
1858 raphael 1596
 
1597
		if(lieuDitModifie && ! lieudit.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1598
			lieuDitM = lieudit.getText();
1858 raphael 1599
		} else {
221 aurelien 1600
			champs = champs.replaceAll(":lieu-dit", "");
216 aurelien 1601
		}
1858 raphael 1602
 
1603
		if(stationModifiee && ! station.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1604
			stationM = station.getText();
1858 raphael 1605
		} else {
221 aurelien 1606
			champs = champs.replaceAll(":station", "");
216 aurelien 1607
		}
1608
 
1858 raphael 1609
		if(milieuModifie && ! milieu.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1610
			milieuM = milieu.getText();
1858 raphael 1611
		} else {
221 aurelien 1612
			champs = champs.replaceAll(":milieu", "");
216 aurelien 1613
		}
1614
 
1858 raphael 1615
		if(dateModifiee && ! date.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1616
			dateM = date.getRawValue();
681 aurelien 1617
			dateM = Util.remplacerSeparateursDateFormatCel(dateM);
1858 raphael 1618
		} else {
221 aurelien 1619
			champs = champs.replaceAll(":date", "");
216 aurelien 1620
		}
1621
 
1858 raphael 1622
		if(especeModifiee && ! espece.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1623
			especeM = espece.getText();
221 aurelien 1624
			numNomSelM = numeroNom;
1858 raphael 1625
		} else {
221 aurelien 1626
			champs = champs.replaceAll(":espece", "");
216 aurelien 1627
		}
1628
 
1858 raphael 1629
		if(commModifie && ! comment.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1630
			commM = comment.getText();
1858 raphael 1631
		} else {
221 aurelien 1632
			champs = champs.replaceAll(":commentaire", "");
216 aurelien 1633
		}
1858 raphael 1634
 
1635
		if(latModifiee && ! latitude.getRawValue().equals(VALEURS_MULTIPLES)) {
264 aurelien 1636
			latM = latitude.getText();
1858 raphael 1637
		} else {
264 aurelien 1638
			champs = champs.replaceAll(":latitude", "");
1639
		}
1858 raphael 1640
 
1641
		if(altModifiee && ! altitude.getRawValue().equals(VALEURS_MULTIPLES)) {
1572 aurelien 1642
			altM = altitude.getText();
1858 raphael 1643
		} else {
1572 aurelien 1644
			champs = champs.replaceAll(":altitude", "");
1645
		}
1858 raphael 1646
 
1647
		if(longModifiee && ! longitude.getRawValue().equals(VALEURS_MULTIPLES)) {
264 aurelien 1648
			longM = longitude.getText();
1858 raphael 1649
		} else {
264 aurelien 1650
			champs = champs.replaceAll(":longitude", "");
1651
		}
1858 raphael 1652
 
1488 aurelien 1653
		if(abondanceModifiee && !selecteurAbondance.getRawValue().equals(VALEURS_MULTIPLES)) {
1654
			abondanceM = getAbondance();
1655
		} else {
1656
			champs = champs.replaceAll(":abondance", "");
1657
		}
1858 raphael 1658
 
1488 aurelien 1659
		if(certitudeModifiee && !selecteurCertitude.getRawValue().equals(VALEURS_MULTIPLES)) {
1660
			certitudeM = getCertitude();
1661
		} else {
1489 aurelien 1662
			champs = champs.replaceAll(":identification", "");
1488 aurelien 1663
		}
1858 raphael 1664
 
1542 aurelien 1665
		if(referentielTaxoModifie && !selecteurReferentielTaxo.getRawValue().equals(VALEURS_MULTIPLES)) {
1666
			referentielTaxoM = getReferentielTaxo();
1667
		} else {
1668
			champs = champs.replaceAll(":referentiel", "");
1669
		}
1858 raphael 1670
 
1542 aurelien 1671
		if(phenologieModifiee && !selecteurStadePheno.getRawValue().equals(VALEURS_MULTIPLES)) {
1672
			phenologieM = getPhenologie();
1673
		} else {
1674
			champs = champs.replaceAll(":phenologie", "");
1675
		}
1858 raphael 1676
 
221 aurelien 1677
		champs = champs.replaceAll(":",", ");
1678
		if(champs.startsWith(",")) {
1679
			champs = champs.replaceFirst(",", "");
1680
		}
1858 raphael 1681
 
221 aurelien 1682
		String message = "Voulez vous modifier le(s) champ(s) suivant(s) : "+champs+"   pour les observations selectionnées ?" ;
1858 raphael 1683
 
216 aurelien 1684
		if(champs.trim().equals("")) {
1685
			Window.alert("Aucun champ n'a été modifié");
1686
		} else {
2568 aurelien 1687
			Observation obs = new Observation(especeM,numNomSelM,localiteM,codeLocaliteM,lieuDitM,stationM,milieuM, commM,dateM);
1688
			obs.setPays(paysM);
216 aurelien 1689
			obs.setNumeroOrdre(numeroOrdre);
971 aurelien 1690
			obs.setLatitude(latM);
1691
			obs.setLongitude(longM);
1572 aurelien 1692
			obs.setAltitude(altM);
1488 aurelien 1693
			obs.setAbondance(abondanceM);
1694
			obs.setCertitude(certitudeM);
1542 aurelien 1695
			obs.setReferentielTaxo(referentielTaxoM);
1696
			obs.setPhenologie(phenologieM);
216 aurelien 1697
			if(Window.confirm(message)) {
1698
				observationMediateur.modifierObservationEnMasse(obs);
221 aurelien 1699
				reinitialiserValeurModifiees();
216 aurelien 1700
			}
1701
		}
1702
	}
1858 raphael 1703
 
1704
	private void supprimerObservation() {
216 aurelien 1705
		observationMediateur.supprimerObservation(this, numeroOrdre);
77 jpm 1706
	}
1858 raphael 1707
 
71 jpm 1708
	public void afficherDetailsObservation(Observation obs)
1709
	{
104 jpm 1710
		raz() ;
216 aurelien 1711
		String idLoc ;
1712
		if(obs.getIdentifiantLocalite() != VALEURS_MULTIPLES) {
1332 aurelien 1713
			idLoc = obs.getIdentifiantLocalite().replaceAll(" ","/");
216 aurelien 1714
			idLoc = idLoc.replaceAll("%","");
1715
			idLoc = idLoc.replaceAll("\"","");
1716
			idLoc = idLoc.replace('\\',' ');
1717
			idLoc = idLoc.trim();
1332 aurelien 1718
			if(idLoc.length() == 5) {
1719
				idLoc = idLoc.substring(0,2);
1720
			}
216 aurelien 1721
		} else {
1722
			idLoc = obs.getIdentifiantLocalite();
1332 aurelien 1723
			if(idLoc.length() == 5) {
1724
				idLoc = idLoc.substring(0,2);
1725
			}
216 aurelien 1726
		}
2568 aurelien 1727
 
1728
		if(obs.getIdentifiantLocalite().isEmpty() && !obs.getPays().isEmpty()) {
1729
			idLoc = obs.getPays();
1730
		}
1858 raphael 1731
 
221 aurelien 1732
		if(!obs.getDate().equals("null") && !obs.getDate().equals("000null") && !obs.getDate().equals(VALEURS_MULTIPLES)) {
71 jpm 1733
			String[] dateEtHeure = obs.getDate().split(" ", 2);
110 aurelien 1734
			if(verifierFormatDate(dateEtHeure[0])) {
1735
				date.setValue(dateEtHeure[0]) ;
1736
			}
1737
			else
1738
			{
1858 raphael 1739
				date.setRawValue("");
110 aurelien 1740
			}
221 aurelien 1741
		} else {
1742
			date.setRawValue(VALEURS_MULTIPLES);
1743
			date.clearInvalid();
71 jpm 1744
		}
1745
		if(!obs.getLieudit().equals("null") && !obs.getLieudit().equals("000null")) {
1746
			lieudit.setValue(obs.getLieudit()) ;
1747
		}
1748
		if(!obs.getStation().equals("null") && !obs.getStation().equals("000null")) {
1749
			station.setValue(obs.getStation()) ;
1750
		}
1751
		if(!obs.getMilieu().equals("null") && !obs.getMilieu().equals("000null")) {
1752
			milieu.setValue(obs.getMilieu()) ;
1753
		}
1754
		if(!obs.getCommentaire().equals("null") && !obs.getCommentaire().equals("000null")) {
461 aurelien 1755
 
681 aurelien 1756
			comment.setRawValue(Util.remplacerSautsDeligneMalEncodes(obs.getCommentaire()));
1858 raphael 1757
 
71 jpm 1758
		}
1759
		if(!obs.getLocalite().equals("null") && !obs.getLocalite().equals("000null")) {
962 aurelien 1760
			if(!idLoc.equals("000null") && !idLoc.equals("")) {
221 aurelien 1761
				if(!idLoc.equals(VALEURS_MULTIPLES)) {
2568 aurelien 1762
					localite.setValue(obs.getLocalite()+" ("+idLoc+")") ;
221 aurelien 1763
				} else {
2568 aurelien 1764
					localite.setValue(VALEURS_MULTIPLES);
221 aurelien 1765
				}
140 aurelien 1766
			}
1767
			else
1768
			{
2568 aurelien 1769
				localite.setValue(obs.getLocalite());
140 aurelien 1770
			}
71 jpm 1771
		}
1772
		if(!obs.getIdentifiantLocalite().equals("null") && !obs.getIdentifiantLocalite().equals("000null")) {
2568 aurelien 1773
			codeLocalite = idLoc;
71 jpm 1774
		}
1775
		if(!obs.getNomSaisi().equals("null") && !obs.getNomSaisi().equals("000null")) {
1776
			espece.setValue(obs.getNomSaisi()) ;
1777
		}
1778
		if(!obs.getNumeroNomenclaturalSaisi().equals("null") && !obs.getNumeroNomenclaturalSaisi().equals("000null")) {
1779
			numeroNom = obs.getNumeroNomenclaturalSaisi() ;
1780
		}
1332 aurelien 1781
		if(!obs.getNumeroOrdre().equals("null") && !obs.getNumeroOrdre().equals("000null")) {
74 david 1782
			numeroOrdre = obs.getNumeroOrdre() ;
1783
		}
1858 raphael 1784
 
1572 aurelien 1785
		if(doitAfficherLatLon(obs)) {
1786
			latitude.setValue(Util.formaterNombre(obs.getLatitude())) ;
1787
			longitude.setValue(Util.formaterNombre(obs.getLongitude())) ;
391 aurelien 1788
		}
1858 raphael 1789
 
1572 aurelien 1790
		if(!obs.getAltitude().isEmpty() && !obs.getAltitude().equals("null") && !obs.getAltitude().equals("000null")) {
1791
			altitude.setValue(Util.formaterNombre(obs.getAltitude())) ;
1792
		}
1858 raphael 1793
 
1488 aurelien 1794
		selecteurAbondance.getStore().load();
1795
		selecteurAbondance.setValue(obs.getAbondance());
1858 raphael 1796
 
1488 aurelien 1797
		selecteurCertitude.getStore().load();
1798
		selecteurCertitude.setValue(obs.getCertitude());
1858 raphael 1799
 
1542 aurelien 1800
		selecteurStadePheno.getStore().load();
1801
		selecteurStadePheno.setValue(obs.getPhenologie());
1858 raphael 1802
 
1542 aurelien 1803
		selecteurReferentielTaxo.getStore().load();
1804
		if(obs.getReferentielTaxo() != VALEURS_MULTIPLES) {
1805
			referentielTaxo = obs.getCodeCourtReferentielTaxo();
1559 aurelien 1806
			if(referentielTaxo == null || referentielTaxo.isEmpty()) {
1807
			    referentielTaxo = Configuration.getReferentielsDispos().get(0).getCode();
1808
			}
1542 aurelien 1809
			selecteurReferentielTaxo.setValue(referentielTaxo);
1810
		} else {
1811
			referentielTaxo = "";
1812
			selecteurReferentielTaxo.setRawValue(VALEURS_MULTIPLES);
1813
		}
1858 raphael 1814
 
1940 aurelien 1815
		afficherChampsEtendus(obs.getChampsEtendus(), null);
71 jpm 1816
	}
1858 raphael 1817
 
1572 aurelien 1818
	private boolean doitAfficherLatLon(Observation obs) {
1819
		return !obs.getLatitude().isEmpty() &&
1858 raphael 1820
				!obs.getLatitude().equals("null") &&
1572 aurelien 1821
				!obs.getLatitude().equals("000null") &&
1858 raphael 1822
				!Util.estZero(obs.getLatitude()) &&
1823
				!obs.getLongitude().isEmpty() &&
1824
				!obs.getLongitude().equals("null") &&
1572 aurelien 1825
				!obs.getLongitude().equals("000null") &&
1826
				!Util.estZero(obs.getLongitude());
1827
	}
1858 raphael 1828
 
1549 aurelien 1829
	private void viderChampsEtendus() {
1830
		if(listeChampsEtendus != null) {
1831
			for (Iterator<String> it = listeChampsEtendus.keySet().iterator(); it.hasNext();) {
2602 aurelien 1832
				ChampSaisieEtendu champEtendu = listeChampsEtendus.get(it.next());
1549 aurelien 1833
				champEtendu.destroy();
1834
			}
1597 aurelien 1835
			if(conteneurChampEtenduGauche != null && conteneurChampEtenduDroite != null) {
1836
				conteneurChampEtenduGauche.clear();
1837
				conteneurChampEtenduDroite.clear();
1838
				panneauPremierColonne.remove(conteneurChampEtenduGauche);
1839
				panneauSecondeColonne.remove(conteneurChampEtenduDroite);
1840
			}
1549 aurelien 1841
			listeChampsEtendus = null;
1842
		}
1843
	}
1858 raphael 1844
 
1940 aurelien 1845
	private void afficherChampsEtendus(Map<String, ChampEtendu> champsEtendus, ChampEtendu champsAFocus) {
2392 aurelien 1846
		champsEtendus = Util.trierListeChampsEtendus(champsEtendus);
1549 aurelien 1847
		viderChampsEtendus();
1858 raphael 1848
 
1810 aurelien 1849
		FormLayout flmd = new FormLayout();
1850
		flmd.setLabelWidth(150);
1858 raphael 1851
 
1810 aurelien 1852
		FormLayout flmg = new FormLayout();
1853
		flmg.setLabelWidth(150);
1858 raphael 1854
 
1810 aurelien 1855
		conteneurChampEtenduGauche = new Panel();
1856
		conteneurChampEtenduGauche.setLayout(flmg);
1857
		conteneurChampEtenduDroite = new Panel();
1858
		conteneurChampEtenduDroite.setLayout(flmd);
1858 raphael 1859
 
1810 aurelien 1860
		conteneurChampEtenduGauche.setAutoWidth(true);
1861
		conteneurChampEtenduGauche.setStyle("conteneurChampsEtendus");
1862
		conteneurChampEtenduGauche.setBodyBorder(false);
1863
		conteneurChampEtenduDroite.setAutoWidth(true);
1864
		conteneurChampEtenduDroite.setStyle("conteneurChampsEtendus");
1865
		conteneurChampEtenduDroite.setBodyBorder(false);
1858 raphael 1866
 
1810 aurelien 1867
		// pour corriger le décalage sur le panneau induit par le lien d'affichage
1940 aurelien 1868
		conteneurChampEtenduDroite.setPaddings(42, 0, 0, 0);
1858 raphael 1869
 
1940 aurelien 1870
		if(champsEtendus != null && champsEtendus.size() > 0) {
1597 aurelien 1871
			lienAfficherChampsEtendus.setVisible(true);
1940 aurelien 1872
			listeChampsEtendus = new HashMap<String, ChampSaisieEtendu>(champsEtendus.size());
2392 aurelien 1873
			HashMap<String, String> correspondancesClesLabel = ListeReferentielChampsEtendusDAO.cacheClesLabels;
1810 aurelien 1874
			boolean gauche = true;
1940 aurelien 1875
			for (Iterator<String> iterator = champsEtendus.keySet().iterator(); iterator.hasNext();) {
2392 aurelien 1876
 
1810 aurelien 1877
				String id = iterator.next();
1940 aurelien 1878
				ChampEtendu champ = champsEtendus.get(id);
2392 aurelien 1879
 
1810 aurelien 1880
				String valeur = champ.getValeur();
2392 aurelien 1881
				String label = id;
1882
 
1883
				// Si le champ possède un clé déjà définie par le catalogue, elle lui sera affectée
1884
				// sinon on la formate en la "déchamotant" et en ajoutant des espaces
1885
				if(correspondancesClesLabel.containsKey(id)) {
1886
					label = correspondancesClesLabel.get(id);
1887
				} else {
1888
					label = Util.formaterCleChampsEtenduPourAffichage(label);
1889
				}
1858 raphael 1890
 
2602 aurelien 1891
				ChampSaisieEtendu champTexteEtendu = new ChampSaisieEtendu(label, id, ListeReferentielChampsEtendusDAO.getUrlRequeteValeursChampEtendu(id));
1940 aurelien 1892
				if(champ.equals(champsAFocus)) {
1893
					champTexteEtendu.focus();
1894
				}
2392 aurelien 1895
 
1810 aurelien 1896
				champTexteEtendu.setId(id);
1897
				champTexteEtendu.setValue(valeur);
1898
				if(gauche) {
1899
					conteneurChampEtenduGauche.add(champTexteEtendu);
1900
				} else {
1901
					conteneurChampEtenduDroite.add(champTexteEtendu);
1549 aurelien 1902
				}
1810 aurelien 1903
				listeChampsEtendus.put(id, champTexteEtendu);
1904
				gauche = !gauche;
1905
			}
1858 raphael 1906
 
1597 aurelien 1907
			panneauPremierColonne.add(conteneurChampEtenduGauche);
1908
			panneauSecondeColonne.add(conteneurChampEtenduDroite);
1858 raphael 1909
 
1597 aurelien 1910
			if(!afficherChampsEtendus) {
1911
				conteneurChampEtenduGauche.setVisible(false);
1912
				conteneurChampEtenduDroite.setVisible(false);
2602 aurelien 1913
			} else {
1914
				redimensionnerChampsEtendus();
1549 aurelien 1915
			}
1597 aurelien 1916
		} else {
1917
			lienAfficherChampsEtendus.setVisible(false);
1549 aurelien 1918
		}
1919
		doLayout();
1920
	}
2602 aurelien 1921
 
1922
	private void redimensionnerChampsEtendus() {
1923
		int largeur = conteneurChampEtenduGauche.getWidth();
1924
		if(largeur <= 0) {
1925
			Timer t = new Timer() {
1926
				@Override
1927
				public void run() {
1928
					redimensionnerChampsEtendus();
1929
				}
1930
			};
1931
			t.schedule(150);
1932
		} else {
1933
			for (Iterator<String> iterator = listeChampsEtendus.keySet().iterator(); iterator
1934
					.hasNext();) {
1935
				ChampSaisieEtendu ch = listeChampsEtendus.get(iterator.next());
2603 aurelien 1936
				ch.redimensionner(largeur - 15);
1937
				if(ch.getFieldWidth() < ch.getLabelWidth()) {
1938
					cel2.LogVersFirebug(ch.getLabelText()+" : "+ch.getFieldWidth()+" < "+ch.getLabelWidth());
1939
					ch.addClass("panneauModePetiteLargeur");
1940
					ch.agrandirChamp(largeur - 82);
1941
				} else {
1942
					//ch.removeClass("panneauModePetiteLargeur");
1943
				}
2602 aurelien 1944
			}
1945
		}
1946
	}
1858 raphael 1947
 
1572 aurelien 1948
	private Map<String, ChampEtendu> getValeursChampsEtendus() {
1949
		Map<String, ChampEtendu> valeursChampsEtendus = new HashMap<String, ChampEtendu>();
1549 aurelien 1950
		if(listeChampsEtendus != null) {
1951
			for (Iterator<String> it = listeChampsEtendus.keySet().iterator(); it.hasNext();) {
1572 aurelien 1952
				String cle = it.next();
2602 aurelien 1953
				ChampSaisieEtendu champTexteEtendu = listeChampsEtendus.get(cle);
1954
				String label = champTexteEtendu.getLabel();
1955
				String valeur = champTexteEtendu.getRawValue();
1572 aurelien 1956
				ChampEtendu champEtendu = new ChampEtendu(cle, label, valeur);
1957
				valeursChampsEtendus.put(cle, champEtendu);
1549 aurelien 1958
			}
1959
		}
1960
		return valeursChampsEtendus;
1961
	}
1858 raphael 1962
 
104 jpm 1963
	public void raz()
71 jpm 1964
	{
118 david 1965
		raz(Champs.TOUT);
1858 raphael 1966
 
118 david 1967
	}
1968
	public void raz(Champs champs)
1969
	{
1970
		switch (champs) {
1971
			case DATE:
1972
				date.reset() ;
1973
				break;
1858 raphael 1974
 
118 david 1975
			case LIEUDIT:
1976
				lieudit.reset() ;
1977
				break;
1858 raphael 1978
 
118 david 1979
			case STATION:
1980
				station.reset() ;
1981
				break;
1858 raphael 1982
 
118 david 1983
			case MILIEU:
1984
				milieu.reset() ;
1985
				break;
1858 raphael 1986
 
118 david 1987
			case COMMENT:
1988
				comment.reset() ;
1989
				break;
1990
 
2568 aurelien 1991
			case LOCALITE:
1992
				localite.reset() ;
1993
				codeLocalite ="";
1994
				pays="";
268 aurelien 1995
				latitude.reset();
1996
				longitude.reset();
118 david 1997
				break;
1858 raphael 1998
 
118 david 1999
			case ESPECE:
2000
				espece.reset();
2001
				numeroNom = "" ;
2002
				numeroOrdre = "";
2003
				break;
1858 raphael 2004
 
264 aurelien 2005
			case LATITUDE:
2006
				latitude.reset();
2568 aurelien 2007
				afficherIndicationlocalite(null);
264 aurelien 2008
				break;
1858 raphael 2009
 
264 aurelien 2010
			case LONGITUDE:
2011
				longitude.reset();
2568 aurelien 2012
				afficherIndicationlocalite(null);
264 aurelien 2013
				break;
1858 raphael 2014
 
1572 aurelien 2015
			case ALTITUDE:
2016
				altitude.reset();
2017
				break;
1858 raphael 2018
 
1488 aurelien 2019
			case ABONDANCE:
2020
				selecteurAbondance.setValue("");
2021
				break;
1858 raphael 2022
 
1488 aurelien 2023
			case CERTITUDE:
2024
				selecteurCertitude.setValue("");
2025
				break;
1858 raphael 2026
 
1542 aurelien 2027
			case REFERENTIELTAXO:
2028
				selecteurReferentielTaxo.setValue("");
2029
				break;
1858 raphael 2030
 
1542 aurelien 2031
			case PHENOLOGIE:
2032
				selecteurStadePheno.setValue("");
2033
				break;
1858 raphael 2034
 
118 david 2035
			case TOUT:
2568 aurelien 2036
				localite.reset();
118 david 2037
				date.reset() ;
2038
				lieudit.reset() ;
2039
				station.reset() ;
2040
				milieu.reset() ;
2041
				comment.reset() ;
2042
				milieu.reset() ;
248 aurelien 2043
				latitude.reset();
2044
				longitude.reset();
1572 aurelien 2045
				altitude.reset();
2568 aurelien 2046
				pays="";
2047
				codeLocalite ="";
118 david 2048
				espece.reset();
1488 aurelien 2049
				selecteurAbondance.clearValue();
2050
				selecteurCertitude.clearValue();
1542 aurelien 2051
				selecteurReferentielTaxo.clearValue();
2052
				selecteurStadePheno.clearValue();
2053
				referentielTaxo = "";
118 david 2054
				numeroNom = "" ;
2055
				numeroOrdre = "";
2568 aurelien 2056
				afficherIndicationlocalite(null);
118 david 2057
				break;
2058
 
2059
		}
1858 raphael 2060
 
71 jpm 2061
	}
1858 raphael 2062
 
110 aurelien 2063
	public boolean verifierFormatDate(String date) {
1858 raphael 2064
 
132 aurelien 2065
		String regex = "[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}" ;
110 aurelien 2066
		if(date.matches(regex) && !date.equals("0000-00-00")) {
2067
			return true ;
2068
		}
2069
		else {
2070
			return false;
2071
		}
2072
	}
216 aurelien 2073
 
1641 aurelien 2074
	public void setSelectionMultiple(boolean selectionMultiple) {
2075
		this.selectionMultiple = selectionMultiple;
2076
		if(!selectionMultiple) {
2077
			boutonAnnuler.enable();
2078
			boutonOK.enable();
2079
		} else {
2080
			boutonAnnuler.disable();
2081
			boutonOK.disable();
216 aurelien 2082
		}
2083
	}
1858 raphael 2084
 
1641 aurelien 2085
	public boolean getSelectionMultiple() {
2086
		return selectionMultiple;
2087
	}
1858 raphael 2088
 
216 aurelien 2089
	private void calculerAfficherDifferences(ListeObservation listeObs) {
1858 raphael 2090
 
2568 aurelien 2091
		String codeLocalite = null;
2092
		String pays = null;
2093
		String localite = null;
216 aurelien 2094
		String lieuDit = null;
2095
		String station = null;
2096
		String milieu = null;
2097
		String espece = null;
2098
		String date = null;
2099
		String notes = null;
264 aurelien 2100
		String lat = null;
2101
		String lon = null;
1572 aurelien 2102
		String alt = null;
1488 aurelien 2103
		String abondance = null;
2104
		String certitude = null;
1542 aurelien 2105
		String referentielTaxo = null;
2106
		String phenologie = null;
1858 raphael 2107
 
216 aurelien 2108
		String ordreObs = "";
1858 raphael 2109
 
216 aurelien 2110
		for(Iterator<String> it = listeObs.keySet().iterator();it.hasNext();) {
2111
			Observation obsEnCours = listeObs.get(it.next());
2568 aurelien 2112
			pays = comparerDifferencesChamps(pays, obsEnCours.getPays());
2113
			codeLocalite = comparerDifferencesChamps(codeLocalite, obsEnCours.getIdentifiantLocalite());
2114
			localite = comparerDifferencesChamps(localite, obsEnCours.getLocalite());
216 aurelien 2115
			lieuDit = comparerDifferencesChamps(lieuDit, obsEnCours.getLieudit());
2116
			station = comparerDifferencesChamps(station, obsEnCours.getStation());
2117
			milieu = comparerDifferencesChamps(milieu, obsEnCours.getMilieu());
1858 raphael 2118
			espece = comparerDifferencesChamps(espece, obsEnCours.getNomSaisi());
216 aurelien 2119
			date = comparerDifferencesChamps(date, obsEnCours.getDate());
2120
			notes = comparerDifferencesChamps(notes, obsEnCours.getCommentaire());
962 aurelien 2121
			lat = comparerDifferencesChamps(lat, obsEnCours.getLatitude());
2122
			lon = comparerDifferencesChamps(lon, obsEnCours.getLongitude());
1572 aurelien 2123
			alt = comparerDifferencesChamps(alt, obsEnCours.getAltitude());
1488 aurelien 2124
			abondance = comparerDifferencesChamps(abondance, obsEnCours.getAbondance());
2125
			certitude = comparerDifferencesChamps(certitude, obsEnCours.getCertitude());
1542 aurelien 2126
			referentielTaxo = comparerDifferencesChamps(referentielTaxo, obsEnCours.getReferentielTaxo());
2127
			phenologie = comparerDifferencesChamps(phenologie, obsEnCours.getPhenologie());
1858 raphael 2128
 
216 aurelien 2129
			ordreObs += obsEnCours.getNumeroOrdre()+",";
2130
		}
1858 raphael 2131
 
2568 aurelien 2132
		Observation obs=new Observation(espece,numeroNom,localite,codeLocalite,lieuDit,station,milieu, notes,date);
2133
		obs.setPays(pays);
216 aurelien 2134
		obs.setNumeroOrdre(ordreObs);
971 aurelien 2135
		obs.setLatitude(lat);
2136
		obs.setLongitude(lon);
1572 aurelien 2137
		obs.setAltitude(alt);
1488 aurelien 2138
		obs.setAbondance(abondance);
2139
		obs.setCertitude(certitude);
1542 aurelien 2140
		obs.setReferentielTaxo(referentielTaxo);
2141
		obs.setPhenologie(phenologie);
1858 raphael 2142
		afficherDetailsObservation(obs);
216 aurelien 2143
	}
1858 raphael 2144
 
216 aurelien 2145
	private String comparerDifferencesChamps(String valeurActuelle, String nouvelleValeur) {
1858 raphael 2146
 
2539 aurelien 2147
		String retour = "";
1858 raphael 2148
 
216 aurelien 2149
			if(valeurActuelle == null) {
2150
				retour = nouvelleValeur;
2151
			} else {
2152
				if(valeurActuelle.equals(nouvelleValeur)) {
2153
					retour = valeurActuelle;
2154
				} else {
2155
					retour = VALEURS_MULTIPLES;
2156
				}
2157
			}
2158
		return retour;
2159
	}
1858 raphael 2160
 
2161
	private void reinitialiserValeurModifiees() {
2568 aurelien 2162
		localiteModifiee = false;
221 aurelien 2163
		lieuDitModifie = false;
2164
		stationModifiee = false;
216 aurelien 2165
		milieuModifie = false;
2166
		dateModifiee = false;
2167
		especeModifiee = false;
2168
		commModifie = false;
264 aurelien 2169
		latModifiee = false;
2170
		longModifiee = false;
1572 aurelien 2171
		altModifiee = false;
1488 aurelien 2172
		abondanceModifiee = false;
2173
		certitudeModifiee = false;
1542 aurelien 2174
		referentielTaxoModifie = false;
2175
		phenologieModifiee = false;
216 aurelien 2176
	}
1858 raphael 2177
 
248 aurelien 2178
	public void saisieTabindex()
2179
	{
2568 aurelien 2180
		localite.setTabIndex(1);
268 aurelien 2181
		lieudit.setTabIndex(3);
2182
		station.setTabIndex(4);
2183
		milieu.setTabIndex(5);
248 aurelien 2184
		coordonnees.setTabIndex(-1);
2185
		coordonnees.addListener(new TextFieldListenerAdapter() {
2186
 
1292 aurelien 2187
			@Override
248 aurelien 2188
			public void onFocus(Field field) {
2189
				if(coordPanel.isVisible()) {
264 aurelien 2190
					latitude.focus();
248 aurelien 2191
				} else {
2192
					Ext.get("lien_carto").focus();
2193
				}
1858 raphael 2194
			}
248 aurelien 2195
		});
1858 raphael 2196
 
681 aurelien 2197
		latitude.setTabIndex(8);
2198
		longitude.setTabIndex(9);
1572 aurelien 2199
		altitude.setTabIndex(10);
2200
		comment.setTabIndex(11);
2201
		date.setTabIndex(12);
2202
		espece.setTabIndex(13);
2203
		selecteurCertitude.setTabIndex(14);
2204
		selecteurAbondance.setTabIndex(15);
2205
		selecteurStadePheno.setTabIndex(16);
2206
		boutonOK.setTabIndex(17);
2207
		boutonAnnuler.setTabIndex(18);
1858 raphael 2208
 
248 aurelien 2209
	}
1858 raphael 2210
 
248 aurelien 2211
	private void obtenirInformationCoord() {
2212
		if(coordonneesValides() != null) {
1958 aurelien 2213
			observationMediateur.obtenirInformationCoord(coordonneesValides()[0],coordonneesValides()[1]);
248 aurelien 2214
		} else {
2553 mathias 2215
			// Centrage de la carte sur une zone correspondant plus ou moins au référentiel.
2216
			// En dur car la config est tellement mal foutue que j'ai envie de me pendre.
2217
			String referentiel = this.getReferentielTaxo();
2218
			String referentielRacine = referentiel.substring(0, referentiel.indexOf(':'));
2219
			Double lat = null, lon = null;
2220
			int zoom = 6;
2221
			switch(referentielRacine) {
2594 aurelien 2222
				case "bdtre" :
2223
					lat = -21.10;
2224
					lon = 55.30;
2225
					zoom = 7;
2226
				break;
2553 mathias 2227
				case "isfan" :
2228
					lat = 29.28358;
2229
					lon = 10.21884;
2230
					zoom = 5;
2231
					break;
2232
				case "apd" :
2233
					lat = 8.75624;
2234
					lon = 1.80176;
2235
					zoom = 5;
2236
					break;
2237
				case "bdtxa" :
2238
					lat = 14.6;
2239
					lon = -61.08334;
2240
					zoom = 7;
2241
					break;
2558 aurelien 2242
				case "lbf" :
2243
					lat = 33.53;
2244
					lon = 35.30;
2245
					zoom = 7;
2246
					break;
2553 mathias 2247
				case "bdtfx" :
2248
				default:
2249
					lat = 47.0504;
2250
					lon = 2.2347;
2251
					zoom = 6;
2252
			}
2253
			if (lat != null && lon != null) {
2254
				// centrage sur la zone
2255
				EntiteGeographiqueObservation infos = new EntiteGeographiqueObservation();
2256
				infos.setLon("" + lon);
2257
				infos.setLat("" + lat);
2258
				infos.setZoom(zoom);
2259
				observationMediateur.rafraichirFenetreCartoSurPoint(infos);
2260
			} else {
2261
				// affichage par défaut au cas où on n'aurait pas trouvé de coordonnées pour centrer
2262
				observationMediateur.afficherFenetreCarto();
2263
			}
248 aurelien 2264
		}
2265
	}
1858 raphael 2266
 
2568 aurelien 2267
	private void obtenirInformationLocalite() {
2558 aurelien 2268
		String idLoc = "";
2568 aurelien 2269
		if(codeLocalite != null && !codeLocalite.isEmpty()) {
2270
			idLoc = codeLocalite;
2558 aurelien 2271
		} else {
2568 aurelien 2272
			idLoc = Util.obtenirIdLocAPartirChaineLocalite(localite.getText());
2558 aurelien 2273
			if(Util.estUnNombre(idLoc)) {
2274
				idLoc = Util.formaterDepartement(idLoc);
2275
			}
2276
		}
2568 aurelien 2277
		observationMediateur.obtenirInformationLocalite(getlocaliteSansIdLoc(), idLoc);
248 aurelien 2278
	}
1858 raphael 2279
 
391 aurelien 2280
	public double[] coordonneesValides() {
248 aurelien 2281
		try {
1858 raphael 2282
 
248 aurelien 2283
			double lat = Double.parseDouble(latitude.getValueAsString().replaceAll(",", "."));
2284
			double lon = Double.parseDouble(longitude.getValueAsString().replaceAll(",", "."));
1858 raphael 2285
 
248 aurelien 2286
			double[] coord = {lat, lon};
2287
			return coord;
1858 raphael 2288
 
248 aurelien 2289
		} catch (NumberFormatException ne) {
2290
			return null;
2291
		}
2292
	}
1858 raphael 2293
 
264 aurelien 2294
	private String[] getValeurCoordonnees() {
2295
		double[] coDouble = coordonneesValides();
1858 raphael 2296
 
264 aurelien 2297
		if(coDouble != null) {
2298
			String[] coord = {coDouble[0]+"",coDouble[1]+""};
2299
			return coord;
2300
		} else {
2539 aurelien 2301
			String[] coord = {"","" };
264 aurelien 2302
			return coord;
2303
		}
2304
	}
1858 raphael 2305
 
2568 aurelien 2306
	public String getlocalite() {
1858 raphael 2307
 
2568 aurelien 2308
		String valeurlocalite = "";
1858 raphael 2309
 
2568 aurelien 2310
		if(localite.getValue() != null) {
2311
			valeurlocalite = localite.getValue();
656 aurelien 2312
		}
2568 aurelien 2313
		return valeurlocalite;
268 aurelien 2314
	}
1858 raphael 2315
 
2568 aurelien 2316
	public String getlocaliteSansIdLoc() {
2317
		return Util.supprimerChaineIdLocalite(getlocalite());
268 aurelien 2318
	}
1858 raphael 2319
 
1542 aurelien 2320
	private String getValeurChampListeLibre(ComboBox champ) {
2321
		String valeurChamp = champ.getValue();
2322
		String valeurChampBrute = champ.getRawValue();
1858 raphael 2323
 
1488 aurelien 2324
		// Test idiot qui permet de savoir si l'on utilise la valeur saisie directement ou bien la valeur
1858 raphael 2325
		// selectionnee car lors du setValue sur le keypress, gwtext ne prends pas en compte le dernier
1488 aurelien 2326
		// caractère
1559 aurelien 2327
		if(valeurChampBrute.trim().length() == 0) {
2328
			valeurChamp = "";
2329
		} else {
2330
			if(valeurChamp != null && valeurChamp.length() > 0) {
2331
				if(valeurChamp.equals(valeurChampBrute.substring(0, valeurChampBrute.length() -1))) {
2332
					valeurChamp = champ.getRawValue();
2333
				}
1542 aurelien 2334
			}
1488 aurelien 2335
		}
1542 aurelien 2336
		return valeurChamp;
1488 aurelien 2337
	}
1542 aurelien 2338
 
2339
	public String getAbondance() {
2340
		return getValeurChampListeLibre(selecteurAbondance);
2341
	}
1858 raphael 2342
 
1488 aurelien 2343
	public String getCertitude() {
1542 aurelien 2344
		return getValeurChampListeLibre(selecteurCertitude);
1488 aurelien 2345
	}
1858 raphael 2346
 
1542 aurelien 2347
	public String getPhenologie() {
2348
		return getValeurChampListeLibre(selecteurStadePheno);
2349
	}
1858 raphael 2350
 
1542 aurelien 2351
	public String getReferentielTaxo() {
2352
		String codeCourt = getValeurChampListeLibre(selecteurReferentielTaxo);
2353
		return Ontologies.getInfosReferentielNomParCode(codeCourt).getCodeVersionComplet();
2354
	}
268 aurelien 2355
 
2568 aurelien 2356
	public boolean localiteInitialisee() {
2357
		return localiteModifiee;
268 aurelien 2358
	}
1858 raphael 2359
 
318 aurelien 2360
	public void redimensionnerFormulaire() {
681 aurelien 2361
		afficherFormulaireLatLon.setWidth(panneauIntermediaire.getWidth()+"px");
2362
		panneauPremierColonne.doLayout();
2363
		panneauSecondeColonne.doLayout();
2364
		panneauIntermediaire.doLayout();
1858 raphael 2365
 
708 aurelien 2366
		doLayout();
318 aurelien 2367
	}
12 david 2368
}