Subversion Repositories eFlore/Applications.cel

Rev

Rev 2539 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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