Subversion Repositories eFlore/Applications.cel

Rev

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