Subversion Repositories eFlore/Applications.cel

Rev

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