Subversion Repositories eFlore/Applications.cel

Rev

Rev 2270 | 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
 
2276 mathias 1347
	// Se déclenche au retour de la "localisation sur la carte"
268 aurelien 1348
	private void rafraichirCommuneEtCoord(EntiteGeographiqueObservation infosCom) {
2276 mathias 1349
 
2073 aurelien 1350
		rafraichirCommune(infosCom);
248 aurelien 1351
		if(infosCom.getLat() != null && !infosCom.getLat().equals("")) {
2276 mathias 1352
			latitude.setValue(Util.tronquerNombrePourAffichage("" + infosCom.getLat(), 5));
248 aurelien 1353
		}
1354
 
1355
		if(infosCom.getLon() != null && !infosCom.getLon().equals("")) {
2276 mathias 1356
			longitude.setValue(Util.tronquerNombrePourAffichage("" + infosCom.getLon(), 5));
248 aurelien 1357
		}
1858 raphael 1358
 
357 aurelien 1359
		latModifiee = true;
1360
		longModifiee = true;
1858 raphael 1361
 
264 aurelien 1362
		coordPanel.setVisible(true);
248 aurelien 1363
	}
1364
 
13 david 1365
	public void obtenirListeReferentielCommune() {
1858 raphael 1366
 
268 aurelien 1367
	 String com=commune.getText();
20 david 1368
	 com=com.replaceAll("%","");
1858 raphael 1369
 
20 david 1370
	 observationMediateur.obtenirListeReferentielCommune(this,com);
1858 raphael 1371
 
13 david 1372
	}
1858 raphael 1373
 
1374
	public void obtenirListeReferentielNom() {
1940 aurelien 1375
		String esp=espece.getText().replaceAll(" ","/*");
1376
		esp=esp.replaceAll("%","");
1377
		String referentiel = this.referentielTaxo;
1378
 
1379
		observationMediateur.obtenirListeReferentielNom(this,referentiel ,esp);
20 david 1380
	}
1858 raphael 1381
 
1382
	protected void obtenirReferentielStation() {
708 aurelien 1383
		observationMediateur.obtenirListeReferentielPerso(this,TypesReferentiels.REFERENTIEL_STATION,station.getText());
1384
	}
1858 raphael 1385
 
708 aurelien 1386
	protected void obtenirListeReferentielMilieu() {
1387
		observationMediateur.obtenirListeReferentielPerso(this,TypesReferentiels.REFERENTIEL_MILIEU,milieu.getText());
1388
	}
1389
 
1390
	protected void obtenirReferentielLieuDit() {
1391
		observationMediateur.obtenirListeReferentielPerso(this,TypesReferentiels.REFERENTIEL_LIEU_DIT,lieudit.getText());
1392
	}
1858 raphael 1393
 
39 david 1394
	public void ajouterObservation() {
1858 raphael 1395
 
1672 aurelien 1396
		if(date.getRawValue() != null && !date.getRawValue().equals("") && !Util.verifierDateFormatCel(date.getRawValue())) {
681 aurelien 1397
			Window.alert("Attention la date saisie est invalide, la date doit être au format jj/mm/aaaa");
1398
			date.setInvalidText("Date invalide");
1399
			return;
1400
		}
1858 raphael 1401
 
1542 aurelien 1402
		if(departement != null) {
389 david 1403
			if(departement.equals("000null") || departement.equals("")) {
1404
				String[] depCom = commune.getText().split(" ");
1405
				if(depCom.length > 1) {
1406
					String dep = depCom[1].replace('(', ' ');
1407
					dep =dep.replace(')', ' ');
1408
					dep = dep.trim();
1409
					dep = dep.replace('\\',' ');
1410
					dep = dep.trim();
1858 raphael 1411
 
389 david 1412
					try
1413
					{
1414
						int nDep = Integer.parseInt(dep);
1415
						if(nDep > 0 && nDep < 110) {
1416
							departement = dep ;
1417
						}
140 aurelien 1418
					}
389 david 1419
					catch(NumberFormatException e)
1420
					{
1421
						departement = "" ;
1422
					}
140 aurelien 1423
				}
1424
			}
1425
		}
1542 aurelien 1426
 
681 aurelien 1427
		String dateObs = Util.remplacerSeparateursDateFormatCel(date.getRawValue());
39 david 1428
 
1858 raphael 1429
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),dateObs);
1430
 
264 aurelien 1431
		String[] coords = getValeurCoordonnees();
971 aurelien 1432
		obs.setLatitude(coords[0]);
1433
		obs.setLongitude(coords[1]);
1572 aurelien 1434
		obs.setAltitude(altitude.getText());
1542 aurelien 1435
 
1488 aurelien 1436
		obs.setAbondance(getAbondance());
1437
		obs.setCertitude(getCertitude());
1542 aurelien 1438
		obs.setPhenologie(getPhenologie());
1858 raphael 1439
 
1542 aurelien 1440
		obs.setReferentielTaxo(Ontologies.getInfosReferentielNomParCode(referentielTaxo).getCodeVersionComplet());
1549 aurelien 1441
		obs.setChampsEtendus(getValeursChampsEtendus());
1858 raphael 1442
 
46 david 1443
		observationMediateur.ajouterObservation(obs);
39 david 1444
	}
1542 aurelien 1445
 
71 jpm 1446
	private void modifierObservation() {
1858 raphael 1447
 
1672 aurelien 1448
		if(!Window.confirm("Êtes-vous sur de vouloir modifier l'observation sélectionnée ?")) {
1449
			return;
1450
		}
1858 raphael 1451
 
1672 aurelien 1452
		if(date.getRawValue() != null && !date.getRawValue().equals("") && !Util.verifierDateFormatCel(date.getRawValue())) {
681 aurelien 1453
			Window.alert("Attention la date saisie est invalide, la date doit être au format jj/mm/aaaa");
1454
			date.setInvalidText("Date invalide");
1455
			return;
1456
		}
1858 raphael 1457
 
229 aurelien 1458
		if(departement.equals("000null") || departement.equals("")) {
1459
			String[] depCom = commune.getText().split(" ");
1460
			if(depCom.length > 1) {
1461
				String dep = depCom[1].replace('(', ' ');
1462
				dep =dep.replace(')', ' ');
1463
				dep = dep.trim();
1464
				dep = dep.replace('\\',' ');
1465
				dep = dep.trim();
1858 raphael 1466
 
229 aurelien 1467
				try
1468
				{
1469
					int nDep = Integer.parseInt(dep);
1470
					if(nDep > 0 && nDep < 110) {
1471
						departement = dep ;
1472
					}
1473
				}
1474
				catch(NumberFormatException e)
1475
				{
1476
					departement = "" ;
1477
				}
1478
			}
1479
		}
1858 raphael 1480
 
681 aurelien 1481
		String dateObs = Util.remplacerSeparateursDateFormatCel(date.getRawValue());
1858 raphael 1482
 
681 aurelien 1483
		Observation obs=new Observation(espece.getText(),numeroNom,commune.getText(),departement,lieudit.getText(),station.getText(),milieu.getText(), comment.getText(),dateObs);
79 david 1484
		obs.setNumeroOrdre(numeroOrdre);
1858 raphael 1485
 
264 aurelien 1486
		String[] coords = getValeurCoordonnees();
1858 raphael 1487
 
971 aurelien 1488
		obs.setLatitude(coords[0]);
1489
		obs.setLongitude(coords[1]);
1572 aurelien 1490
		obs.setAltitude(altitude.getText());
1858 raphael 1491
 
1488 aurelien 1492
		obs.setAbondance(getAbondance());
1493
		obs.setCertitude(getCertitude());
1542 aurelien 1494
		obs.setPhenologie(getPhenologie());
1495
		obs.setReferentielTaxo(getReferentielTaxo());
1549 aurelien 1496
		obs.setChampsEtendus(getValeursChampsEtendus());
1858 raphael 1497
 
79 david 1498
		observationMediateur.modifierObservation(obs);
71 jpm 1499
	}
1858 raphael 1500
 
216 aurelien 1501
	private void modifierObservationEnMasse(Champs champModifie) {
1858 raphael 1502
 
1542 aurelien 1503
		//TODO: factoriser
216 aurelien 1504
		String communeM = null;
1505
		String departementM = null;
221 aurelien 1506
		String numNomSelM = null;
216 aurelien 1507
		String lieuDitM = null;
1508
		String stationM = null;
1509
		String milieuM = null;
1510
		String dateM = null;
1511
		String especeM = null;
1858 raphael 1512
		String commM = null;
264 aurelien 1513
		String latM = null;
1514
		String longM = null;
1572 aurelien 1515
		String altM = null;
1488 aurelien 1516
		String abondanceM = null;
1517
		String certitudeM = null;
1542 aurelien 1518
		String referentielTaxoM = null;
1519
		String phenologieM = null;
1858 raphael 1520
 
216 aurelien 1521
		String champs = modeleMessageModif;
1858 raphael 1522
 
1523
		if(communeModifiee && ! commune.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1524
			communeM = commune.getText();
1858 raphael 1525
 
221 aurelien 1526
			if(departement.equals("000null") || departement.equals("")) {
1527
				String[] depCom = commune.getText().split(" ");
1528
				if(depCom.length > 1) {
1529
					String dep = depCom[1].replace('(', ' ');
1530
					dep =dep.replace(')', ' ');
1531
					dep = dep.trim();
1532
					dep = dep.replace('\\',' ');
1533
					dep = dep.trim();
1858 raphael 1534
 
1535
					try {
221 aurelien 1536
						int nDep = Integer.parseInt(dep);
1537
						if(nDep > 0 && nDep < 110) {
1538
							departement = dep ;
1539
						}
1540
					}
1858 raphael 1541
					catch(NumberFormatException e) {
221 aurelien 1542
						departement = "" ;
1543
					}
1544
				}
1545
			}
1546
			departementM = departement;
1858 raphael 1547
		}
1548
		else {
221 aurelien 1549
			champs = champs.replaceAll("commune", "");
216 aurelien 1550
		}
1858 raphael 1551
 
1552
		if(lieuDitModifie && ! lieudit.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1553
			lieuDitM = lieudit.getText();
1858 raphael 1554
		} else {
221 aurelien 1555
			champs = champs.replaceAll(":lieu-dit", "");
216 aurelien 1556
		}
1858 raphael 1557
 
1558
		if(stationModifiee && ! station.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1559
			stationM = station.getText();
1858 raphael 1560
		} else {
221 aurelien 1561
			champs = champs.replaceAll(":station", "");
216 aurelien 1562
		}
1563
 
1858 raphael 1564
		if(milieuModifie && ! milieu.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1565
			milieuM = milieu.getText();
1858 raphael 1566
		} else {
221 aurelien 1567
			champs = champs.replaceAll(":milieu", "");
216 aurelien 1568
		}
1569
 
1858 raphael 1570
		if(dateModifiee && ! date.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1571
			dateM = date.getRawValue();
681 aurelien 1572
			dateM = Util.remplacerSeparateursDateFormatCel(dateM);
1858 raphael 1573
		} else {
221 aurelien 1574
			champs = champs.replaceAll(":date", "");
216 aurelien 1575
		}
1576
 
1858 raphael 1577
		if(especeModifiee && ! espece.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1578
			especeM = espece.getText();
221 aurelien 1579
			numNomSelM = numeroNom;
1858 raphael 1580
		} else {
221 aurelien 1581
			champs = champs.replaceAll(":espece", "");
216 aurelien 1582
		}
1583
 
1858 raphael 1584
		if(commModifie && ! comment.getRawValue().equals(VALEURS_MULTIPLES)) {
216 aurelien 1585
			commM = comment.getText();
1858 raphael 1586
		} else {
221 aurelien 1587
			champs = champs.replaceAll(":commentaire", "");
216 aurelien 1588
		}
1858 raphael 1589
 
1590
		if(latModifiee && ! latitude.getRawValue().equals(VALEURS_MULTIPLES)) {
264 aurelien 1591
			latM = latitude.getText();
1858 raphael 1592
		} else {
264 aurelien 1593
			champs = champs.replaceAll(":latitude", "");
1594
		}
1858 raphael 1595
 
1596
		if(altModifiee && ! altitude.getRawValue().equals(VALEURS_MULTIPLES)) {
1572 aurelien 1597
			altM = altitude.getText();
1858 raphael 1598
		} else {
1572 aurelien 1599
			champs = champs.replaceAll(":altitude", "");
1600
		}
1858 raphael 1601
 
1602
		if(longModifiee && ! longitude.getRawValue().equals(VALEURS_MULTIPLES)) {
264 aurelien 1603
			longM = longitude.getText();
1858 raphael 1604
		} else {
264 aurelien 1605
			champs = champs.replaceAll(":longitude", "");
1606
		}
1858 raphael 1607
 
1488 aurelien 1608
		if(abondanceModifiee && !selecteurAbondance.getRawValue().equals(VALEURS_MULTIPLES)) {
1609
			abondanceM = getAbondance();
1610
		} else {
1611
			champs = champs.replaceAll(":abondance", "");
1612
		}
1858 raphael 1613
 
1488 aurelien 1614
		if(certitudeModifiee && !selecteurCertitude.getRawValue().equals(VALEURS_MULTIPLES)) {
1615
			certitudeM = getCertitude();
1616
		} else {
1489 aurelien 1617
			champs = champs.replaceAll(":identification", "");
1488 aurelien 1618
		}
1858 raphael 1619
 
1542 aurelien 1620
		if(referentielTaxoModifie && !selecteurReferentielTaxo.getRawValue().equals(VALEURS_MULTIPLES)) {
1621
			referentielTaxoM = getReferentielTaxo();
1622
		} else {
1623
			champs = champs.replaceAll(":referentiel", "");
1624
		}
1858 raphael 1625
 
1542 aurelien 1626
		if(phenologieModifiee && !selecteurStadePheno.getRawValue().equals(VALEURS_MULTIPLES)) {
1627
			phenologieM = getPhenologie();
1628
		} else {
1629
			champs = champs.replaceAll(":phenologie", "");
1630
		}
1858 raphael 1631
 
221 aurelien 1632
		champs = champs.replaceAll(":",", ");
1633
		if(champs.startsWith(",")) {
1634
			champs = champs.replaceFirst(",", "");
1635
		}
1858 raphael 1636
 
221 aurelien 1637
		String message = "Voulez vous modifier le(s) champ(s) suivant(s) : "+champs+"   pour les observations selectionnées ?" ;
1858 raphael 1638
 
216 aurelien 1639
		if(champs.trim().equals("")) {
1640
			Window.alert("Aucun champ n'a été modifié");
1641
		} else {
221 aurelien 1642
			Observation obs = new Observation(especeM,numNomSelM,communeM,departementM,lieuDitM,stationM,milieuM, commM,dateM);
216 aurelien 1643
			obs.setNumeroOrdre(numeroOrdre);
971 aurelien 1644
			obs.setLatitude(latM);
1645
			obs.setLongitude(longM);
1572 aurelien 1646
			obs.setAltitude(altM);
1488 aurelien 1647
			obs.setAbondance(abondanceM);
1648
			obs.setCertitude(certitudeM);
1542 aurelien 1649
			obs.setReferentielTaxo(referentielTaxoM);
1650
			obs.setPhenologie(phenologieM);
216 aurelien 1651
			if(Window.confirm(message)) {
1652
				observationMediateur.modifierObservationEnMasse(obs);
221 aurelien 1653
				reinitialiserValeurModifiees();
216 aurelien 1654
			}
1655
		}
1656
	}
1858 raphael 1657
 
1658
	private void supprimerObservation() {
216 aurelien 1659
		observationMediateur.supprimerObservation(this, numeroOrdre);
77 jpm 1660
	}
1858 raphael 1661
 
71 jpm 1662
	public void afficherDetailsObservation(Observation obs)
1663
	{
104 jpm 1664
		raz() ;
216 aurelien 1665
		String idLoc ;
1666
		if(obs.getIdentifiantLocalite() != VALEURS_MULTIPLES) {
1332 aurelien 1667
			idLoc = obs.getIdentifiantLocalite().replaceAll(" ","/");
216 aurelien 1668
			idLoc = idLoc.replaceAll("%","");
1669
			idLoc = idLoc.replaceAll("\"","");
1670
			idLoc = idLoc.replace('\\',' ');
1671
			idLoc = idLoc.trim();
1332 aurelien 1672
			if(idLoc.length() == 5) {
1673
				idLoc = idLoc.substring(0,2);
1674
			}
216 aurelien 1675
		} else {
1676
			idLoc = obs.getIdentifiantLocalite();
1332 aurelien 1677
			if(idLoc.length() == 5) {
1678
				idLoc = idLoc.substring(0,2);
1679
			}
216 aurelien 1680
		}
1858 raphael 1681
 
221 aurelien 1682
		if(!obs.getDate().equals("null") && !obs.getDate().equals("000null") && !obs.getDate().equals(VALEURS_MULTIPLES)) {
71 jpm 1683
			String[] dateEtHeure = obs.getDate().split(" ", 2);
110 aurelien 1684
			if(verifierFormatDate(dateEtHeure[0])) {
1685
				date.setValue(dateEtHeure[0]) ;
1686
			}
1687
			else
1688
			{
1858 raphael 1689
				date.setRawValue("");
110 aurelien 1690
			}
221 aurelien 1691
		} else {
1692
			date.setRawValue(VALEURS_MULTIPLES);
1693
			date.clearInvalid();
71 jpm 1694
		}
1695
		if(!obs.getLieudit().equals("null") && !obs.getLieudit().equals("000null")) {
1696
			lieudit.setValue(obs.getLieudit()) ;
1697
		}
1698
		if(!obs.getStation().equals("null") && !obs.getStation().equals("000null")) {
1699
			station.setValue(obs.getStation()) ;
1700
		}
1701
		if(!obs.getMilieu().equals("null") && !obs.getMilieu().equals("000null")) {
1702
			milieu.setValue(obs.getMilieu()) ;
1703
		}
1704
		if(!obs.getCommentaire().equals("null") && !obs.getCommentaire().equals("000null")) {
461 aurelien 1705
 
681 aurelien 1706
			comment.setRawValue(Util.remplacerSautsDeligneMalEncodes(obs.getCommentaire()));
1858 raphael 1707
 
71 jpm 1708
		}
1709
		if(!obs.getLocalite().equals("null") && !obs.getLocalite().equals("000null")) {
962 aurelien 1710
			if(!idLoc.equals("000null") && !idLoc.equals("")) {
221 aurelien 1711
				if(!idLoc.equals(VALEURS_MULTIPLES)) {
1712
					commune.setValue(obs.getLocalite()+" ("+idLoc+")") ;
1713
				} else {
1714
					commune.setValue(VALEURS_MULTIPLES);
1715
				}
140 aurelien 1716
			}
1717
			else
1718
			{
1719
				commune.setValue(obs.getLocalite());
1720
			}
71 jpm 1721
		}
1722
		if(!obs.getIdentifiantLocalite().equals("null") && !obs.getIdentifiantLocalite().equals("000null")) {
140 aurelien 1723
			departement = idLoc;
71 jpm 1724
		}
1725
		if(!obs.getNomSaisi().equals("null") && !obs.getNomSaisi().equals("000null")) {
1726
			espece.setValue(obs.getNomSaisi()) ;
1727
		}
1728
		if(!obs.getNumeroNomenclaturalSaisi().equals("null") && !obs.getNumeroNomenclaturalSaisi().equals("000null")) {
1729
			numeroNom = obs.getNumeroNomenclaturalSaisi() ;
1730
		}
1332 aurelien 1731
		if(!obs.getNumeroOrdre().equals("null") && !obs.getNumeroOrdre().equals("000null")) {
74 david 1732
			numeroOrdre = obs.getNumeroOrdre() ;
1733
		}
1858 raphael 1734
 
1572 aurelien 1735
		if(doitAfficherLatLon(obs)) {
1736
			latitude.setValue(Util.formaterNombre(obs.getLatitude())) ;
1737
			longitude.setValue(Util.formaterNombre(obs.getLongitude())) ;
391 aurelien 1738
		}
1858 raphael 1739
 
1572 aurelien 1740
		if(!obs.getAltitude().isEmpty() && !obs.getAltitude().equals("null") && !obs.getAltitude().equals("000null")) {
1741
			altitude.setValue(Util.formaterNombre(obs.getAltitude())) ;
1742
		}
1858 raphael 1743
 
1488 aurelien 1744
		selecteurAbondance.getStore().load();
1745
		selecteurAbondance.setValue(obs.getAbondance());
1858 raphael 1746
 
1488 aurelien 1747
		selecteurCertitude.getStore().load();
1748
		selecteurCertitude.setValue(obs.getCertitude());
1858 raphael 1749
 
1542 aurelien 1750
		selecteurStadePheno.getStore().load();
1751
		selecteurStadePheno.setValue(obs.getPhenologie());
1858 raphael 1752
 
1542 aurelien 1753
		selecteurReferentielTaxo.getStore().load();
1754
		if(obs.getReferentielTaxo() != VALEURS_MULTIPLES) {
1755
			referentielTaxo = obs.getCodeCourtReferentielTaxo();
1559 aurelien 1756
			if(referentielTaxo == null || referentielTaxo.isEmpty()) {
1757
			    referentielTaxo = Configuration.getReferentielsDispos().get(0).getCode();
1758
			}
1542 aurelien 1759
			selecteurReferentielTaxo.setValue(referentielTaxo);
1760
		} else {
1761
			referentielTaxo = "";
1762
			selecteurReferentielTaxo.setRawValue(VALEURS_MULTIPLES);
1763
		}
1858 raphael 1764
 
1940 aurelien 1765
		afficherChampsEtendus(obs.getChampsEtendus(), null);
71 jpm 1766
	}
1858 raphael 1767
 
1572 aurelien 1768
	private boolean doitAfficherLatLon(Observation obs) {
1769
		return !obs.getLatitude().isEmpty() &&
1858 raphael 1770
				!obs.getLatitude().equals("null") &&
1572 aurelien 1771
				!obs.getLatitude().equals("000null") &&
1858 raphael 1772
				!Util.estZero(obs.getLatitude()) &&
1773
				!obs.getLongitude().isEmpty() &&
1774
				!obs.getLongitude().equals("null") &&
1572 aurelien 1775
				!obs.getLongitude().equals("000null") &&
1776
				!Util.estZero(obs.getLongitude());
1777
	}
1858 raphael 1778
 
1549 aurelien 1779
	private void viderChampsEtendus() {
1780
		if(listeChampsEtendus != null) {
1781
			for (Iterator<String> it = listeChampsEtendus.keySet().iterator(); it.hasNext();) {
1782
				TextField champEtendu = listeChampsEtendus.get(it.next());
1783
				champEtendu.destroy();
1784
			}
1597 aurelien 1785
			if(conteneurChampEtenduGauche != null && conteneurChampEtenduDroite != null) {
1786
				conteneurChampEtenduGauche.clear();
1787
				conteneurChampEtenduDroite.clear();
1788
				panneauPremierColonne.remove(conteneurChampEtenduGauche);
1789
				panneauSecondeColonne.remove(conteneurChampEtenduDroite);
1790
			}
1549 aurelien 1791
			listeChampsEtendus = null;
1792
		}
1793
	}
1858 raphael 1794
 
1940 aurelien 1795
	private void afficherChampsEtendus(Map<String, ChampEtendu> champsEtendus, ChampEtendu champsAFocus) {
1549 aurelien 1796
		viderChampsEtendus();
1858 raphael 1797
 
1810 aurelien 1798
		FormLayout flmd = new FormLayout();
1799
		flmd.setLabelWidth(150);
1858 raphael 1800
 
1810 aurelien 1801
		FormLayout flmg = new FormLayout();
1802
		flmg.setLabelWidth(150);
1858 raphael 1803
 
1810 aurelien 1804
		conteneurChampEtenduGauche = new Panel();
1805
		conteneurChampEtenduGauche.setLayout(flmg);
1806
		conteneurChampEtenduDroite = new Panel();
1807
		conteneurChampEtenduDroite.setLayout(flmd);
1858 raphael 1808
 
1810 aurelien 1809
		conteneurChampEtenduGauche.setAutoWidth(true);
1810
		conteneurChampEtenduGauche.setStyle("conteneurChampsEtendus");
1811
		conteneurChampEtenduGauche.setBodyBorder(false);
1812
		conteneurChampEtenduDroite.setAutoWidth(true);
1813
		conteneurChampEtenduDroite.setStyle("conteneurChampsEtendus");
1814
		conteneurChampEtenduDroite.setBodyBorder(false);
1858 raphael 1815
 
1810 aurelien 1816
		// pour corriger le décalage sur le panneau induit par le lien d'affichage
1940 aurelien 1817
		conteneurChampEtenduDroite.setPaddings(42, 0, 0, 0);
1858 raphael 1818
 
1940 aurelien 1819
		if(champsEtendus != null && champsEtendus.size() > 0) {
1597 aurelien 1820
			lienAfficherChampsEtendus.setVisible(true);
1940 aurelien 1821
			listeChampsEtendus = new HashMap<String, ChampSaisieEtendu>(champsEtendus.size());
1810 aurelien 1822
			boolean gauche = true;
1940 aurelien 1823
			for (Iterator<String> iterator = champsEtendus.keySet().iterator(); iterator.hasNext();) {
1810 aurelien 1824
				String id = iterator.next();
1940 aurelien 1825
				ChampEtendu champ = champsEtendus.get(id);
1810 aurelien 1826
				String valeur = champ.getValeur();
1827
				String label = champ.getLabel();
1858 raphael 1828
 
1940 aurelien 1829
				ChampSaisieEtendu champTexteEtendu = new ChampSaisieEtendu(label, id);
1830
				if(champ.equals(champsAFocus)) {
1831
					champTexteEtendu.focus();
1832
				}
1810 aurelien 1833
				champTexteEtendu.setLabel(label);
1834
				champTexteEtendu.setId(id);
1835
				champTexteEtendu.setValue(valeur);
1836
				if(gauche) {
1837
					conteneurChampEtenduGauche.add(champTexteEtendu);
1838
				} else {
1839
					conteneurChampEtenduDroite.add(champTexteEtendu);
1549 aurelien 1840
				}
1810 aurelien 1841
				listeChampsEtendus.put(id, champTexteEtendu);
1842
				gauche = !gauche;
1843
			}
1858 raphael 1844
 
1597 aurelien 1845
			panneauPremierColonne.add(conteneurChampEtenduGauche);
1846
			panneauSecondeColonne.add(conteneurChampEtenduDroite);
1858 raphael 1847
 
1597 aurelien 1848
			if(!afficherChampsEtendus) {
1849
				conteneurChampEtenduGauche.setVisible(false);
1850
				conteneurChampEtenduDroite.setVisible(false);
1549 aurelien 1851
			}
1597 aurelien 1852
		} else {
1853
			lienAfficherChampsEtendus.setVisible(false);
1549 aurelien 1854
		}
1855
		doLayout();
1856
	}
1858 raphael 1857
 
1572 aurelien 1858
	private Map<String, ChampEtendu> getValeursChampsEtendus() {
1859
		Map<String, ChampEtendu> valeursChampsEtendus = new HashMap<String, ChampEtendu>();
1549 aurelien 1860
		if(listeChampsEtendus != null) {
1861
			for (Iterator<String> it = listeChampsEtendus.keySet().iterator(); it.hasNext();) {
1572 aurelien 1862
				String cle = it.next();
1863
				TextField champTexteEtendu = listeChampsEtendus.get(cle);
1864
				String label = champTexteEtendu.getFieldLabel();
1865
				String valeur = champTexteEtendu.getValueAsString();
1866
				ChampEtendu champEtendu = new ChampEtendu(cle, label, valeur);
1867
				valeursChampsEtendus.put(cle, champEtendu);
1549 aurelien 1868
			}
1869
		}
1870
		return valeursChampsEtendus;
1871
	}
1858 raphael 1872
 
104 jpm 1873
	public void raz()
71 jpm 1874
	{
118 david 1875
		raz(Champs.TOUT);
1858 raphael 1876
 
118 david 1877
	}
1878
	public void raz(Champs champs)
1879
	{
1880
		switch (champs) {
1881
			case DATE:
1882
				date.reset() ;
1883
				break;
1858 raphael 1884
 
118 david 1885
			case LIEUDIT:
1886
				lieudit.reset() ;
1887
				break;
1858 raphael 1888
 
118 david 1889
			case STATION:
1890
				station.reset() ;
1891
				break;
1858 raphael 1892
 
118 david 1893
			case MILIEU:
1894
				milieu.reset() ;
1895
				break;
1858 raphael 1896
 
118 david 1897
			case COMMENT:
1898
				comment.reset() ;
1899
				break;
1900
 
1901
			case COMMUNE:
172 aurelien 1902
				commune.reset() ;
118 david 1903
				departement ="";
268 aurelien 1904
				latitude.reset();
1905
				longitude.reset();
118 david 1906
				break;
1858 raphael 1907
 
118 david 1908
			case ESPECE:
1909
				espece.reset();
1910
				numeroNom = "" ;
1911
				numeroOrdre = "";
1912
				break;
1858 raphael 1913
 
264 aurelien 1914
			case LATITUDE:
1915
				latitude.reset();
268 aurelien 1916
				afficherIndicationCommune(null);
264 aurelien 1917
				break;
1858 raphael 1918
 
264 aurelien 1919
			case LONGITUDE:
1920
				longitude.reset();
268 aurelien 1921
				afficherIndicationCommune(null);
264 aurelien 1922
				break;
1858 raphael 1923
 
1572 aurelien 1924
			case ALTITUDE:
1925
				altitude.reset();
1926
				break;
1858 raphael 1927
 
1488 aurelien 1928
			case ABONDANCE:
1929
				selecteurAbondance.setValue("");
1930
				break;
1858 raphael 1931
 
1488 aurelien 1932
			case CERTITUDE:
1933
				selecteurCertitude.setValue("");
1934
				break;
1858 raphael 1935
 
1542 aurelien 1936
			case REFERENTIELTAXO:
1937
				selecteurReferentielTaxo.setValue("");
1938
				break;
1858 raphael 1939
 
1542 aurelien 1940
			case PHENOLOGIE:
1941
				selecteurStadePheno.setValue("");
1942
				break;
1858 raphael 1943
 
118 david 1944
			case TOUT:
132 aurelien 1945
				commune.reset();
118 david 1946
				date.reset() ;
1947
				lieudit.reset() ;
1948
				station.reset() ;
1949
				milieu.reset() ;
1950
				comment.reset() ;
1951
				milieu.reset() ;
248 aurelien 1952
				latitude.reset();
1953
				longitude.reset();
1572 aurelien 1954
				altitude.reset();
118 david 1955
				departement ="";
1956
				espece.reset();
1488 aurelien 1957
				selecteurAbondance.clearValue();
1958
				selecteurCertitude.clearValue();
1542 aurelien 1959
				selecteurReferentielTaxo.clearValue();
1960
				selecteurStadePheno.clearValue();
1961
				referentielTaxo = "";
118 david 1962
				numeroNom = "" ;
1963
				numeroOrdre = "";
268 aurelien 1964
				afficherIndicationCommune(null);
118 david 1965
				break;
1966
 
1967
		}
1858 raphael 1968
 
71 jpm 1969
	}
1858 raphael 1970
 
110 aurelien 1971
	public boolean verifierFormatDate(String date) {
1858 raphael 1972
 
132 aurelien 1973
		String regex = "[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}" ;
110 aurelien 1974
		if(date.matches(regex) && !date.equals("0000-00-00")) {
1975
			return true ;
1976
		}
1977
		else {
1978
			return false;
1979
		}
1980
	}
216 aurelien 1981
 
1641 aurelien 1982
	public void setSelectionMultiple(boolean selectionMultiple) {
1983
		this.selectionMultiple = selectionMultiple;
1984
		if(!selectionMultiple) {
1985
			boutonAnnuler.enable();
1986
			boutonOK.enable();
1987
		} else {
1988
			boutonAnnuler.disable();
1989
			boutonOK.disable();
216 aurelien 1990
		}
1991
	}
1858 raphael 1992
 
1641 aurelien 1993
	public boolean getSelectionMultiple() {
1994
		return selectionMultiple;
1995
	}
1858 raphael 1996
 
216 aurelien 1997
	private void calculerAfficherDifferences(ListeObservation listeObs) {
1858 raphael 1998
 
216 aurelien 1999
		String departement = null;
2000
		String commune = null;
2001
		String lieuDit = null;
2002
		String station = null;
2003
		String milieu = null;
2004
		String espece = null;
2005
		String date = null;
2006
		String notes = null;
264 aurelien 2007
		String lat = null;
2008
		String lon = null;
1572 aurelien 2009
		String alt = null;
1488 aurelien 2010
		String abondance = null;
2011
		String certitude = null;
1542 aurelien 2012
		String referentielTaxo = null;
2013
		String phenologie = null;
1858 raphael 2014
 
216 aurelien 2015
		String ordreObs = "";
1858 raphael 2016
 
216 aurelien 2017
		for(Iterator<String> it = listeObs.keySet().iterator();it.hasNext();) {
2018
			Observation obsEnCours = listeObs.get(it.next());
2019
			departement = comparerDifferencesChamps(departement, obsEnCours.getIdentifiantLocalite());
2020
			commune = comparerDifferencesChamps(commune, obsEnCours.getLocalite());
2021
			lieuDit = comparerDifferencesChamps(lieuDit, obsEnCours.getLieudit());
2022
			station = comparerDifferencesChamps(station, obsEnCours.getStation());
2023
			milieu = comparerDifferencesChamps(milieu, obsEnCours.getMilieu());
1858 raphael 2024
			espece = comparerDifferencesChamps(espece, obsEnCours.getNomSaisi());
216 aurelien 2025
			date = comparerDifferencesChamps(date, obsEnCours.getDate());
2026
			notes = comparerDifferencesChamps(notes, obsEnCours.getCommentaire());
962 aurelien 2027
			lat = comparerDifferencesChamps(lat, obsEnCours.getLatitude());
2028
			lon = comparerDifferencesChamps(lon, obsEnCours.getLongitude());
1572 aurelien 2029
			alt = comparerDifferencesChamps(alt, obsEnCours.getAltitude());
1488 aurelien 2030
			abondance = comparerDifferencesChamps(abondance, obsEnCours.getAbondance());
2031
			certitude = comparerDifferencesChamps(certitude, obsEnCours.getCertitude());
1542 aurelien 2032
			referentielTaxo = comparerDifferencesChamps(referentielTaxo, obsEnCours.getReferentielTaxo());
2033
			phenologie = comparerDifferencesChamps(phenologie, obsEnCours.getPhenologie());
1858 raphael 2034
 
216 aurelien 2035
			ordreObs += obsEnCours.getNumeroOrdre()+",";
2036
		}
1858 raphael 2037
 
216 aurelien 2038
		Observation obs=new Observation(espece,numeroNom,commune,departement,lieuDit,station,milieu, notes,date);
2039
		obs.setNumeroOrdre(ordreObs);
971 aurelien 2040
		obs.setLatitude(lat);
2041
		obs.setLongitude(lon);
1572 aurelien 2042
		obs.setAltitude(alt);
1488 aurelien 2043
		obs.setAbondance(abondance);
2044
		obs.setCertitude(certitude);
1542 aurelien 2045
		obs.setReferentielTaxo(referentielTaxo);
2046
		obs.setPhenologie(phenologie);
1858 raphael 2047
		afficherDetailsObservation(obs);
216 aurelien 2048
	}
1858 raphael 2049
 
216 aurelien 2050
	private String comparerDifferencesChamps(String valeurActuelle, String nouvelleValeur) {
1858 raphael 2051
 
216 aurelien 2052
		String retour = "000null";
1858 raphael 2053
 
216 aurelien 2054
			if(valeurActuelle == null) {
2055
				retour = nouvelleValeur;
2056
			} else {
2057
				if(valeurActuelle.equals(nouvelleValeur)) {
2058
					retour = valeurActuelle;
2059
				} else {
2060
					retour = VALEURS_MULTIPLES;
2061
				}
2062
			}
2063
		return retour;
2064
	}
1858 raphael 2065
 
2066
	private void reinitialiserValeurModifiees() {
216 aurelien 2067
		communeModifiee = false;
221 aurelien 2068
		lieuDitModifie = false;
2069
		stationModifiee = false;
216 aurelien 2070
		milieuModifie = false;
2071
		dateModifiee = false;
2072
		especeModifiee = false;
2073
		commModifie = false;
264 aurelien 2074
		latModifiee = false;
2075
		longModifiee = false;
1572 aurelien 2076
		altModifiee = false;
1488 aurelien 2077
		abondanceModifiee = false;
2078
		certitudeModifiee = false;
1542 aurelien 2079
		referentielTaxoModifie = false;
2080
		phenologieModifiee = false;
216 aurelien 2081
	}
1858 raphael 2082
 
248 aurelien 2083
	public void saisieTabindex()
2084
	{
2085
		commune.setTabIndex(1);
268 aurelien 2086
		lieudit.setTabIndex(3);
2087
		station.setTabIndex(4);
2088
		milieu.setTabIndex(5);
248 aurelien 2089
		coordonnees.setTabIndex(-1);
2090
		coordonnees.addListener(new TextFieldListenerAdapter() {
2091
 
1292 aurelien 2092
			@Override
248 aurelien 2093
			public void onFocus(Field field) {
2094
				if(coordPanel.isVisible()) {
264 aurelien 2095
					latitude.focus();
248 aurelien 2096
				} else {
2097
					Ext.get("lien_carto").focus();
2098
				}
1858 raphael 2099
			}
248 aurelien 2100
		});
1858 raphael 2101
 
681 aurelien 2102
		latitude.setTabIndex(8);
2103
		longitude.setTabIndex(9);
1572 aurelien 2104
		altitude.setTabIndex(10);
2105
		comment.setTabIndex(11);
2106
		date.setTabIndex(12);
2107
		espece.setTabIndex(13);
2108
		selecteurCertitude.setTabIndex(14);
2109
		selecteurAbondance.setTabIndex(15);
2110
		selecteurStadePheno.setTabIndex(16);
2111
		boutonOK.setTabIndex(17);
2112
		boutonAnnuler.setTabIndex(18);
1858 raphael 2113
 
248 aurelien 2114
	}
1858 raphael 2115
 
248 aurelien 2116
	private void obtenirInformationCoord() {
2117
		if(coordonneesValides() != null) {
1958 aurelien 2118
			observationMediateur.obtenirInformationCoord(coordonneesValides()[0],coordonneesValides()[1]);
248 aurelien 2119
		} else {
681 aurelien 2120
			observationMediateur.afficherFenetreCarto();
248 aurelien 2121
		}
2122
	}
1858 raphael 2123
 
248 aurelien 2124
	private void obtenirInformationCommune() {
1542 aurelien 2125
		observationMediateur.obtenirInformationCommune(getCommuneSansDepartement(), Util.obtenirDepartementAPartirChaineCommune(departement, commune.getText()));
248 aurelien 2126
	}
1858 raphael 2127
 
391 aurelien 2128
	public double[] coordonneesValides() {
1858 raphael 2129
 
248 aurelien 2130
		try {
1858 raphael 2131
 
248 aurelien 2132
			double lat = Double.parseDouble(latitude.getValueAsString().replaceAll(",", "."));
2133
			double lon = Double.parseDouble(longitude.getValueAsString().replaceAll(",", "."));
1858 raphael 2134
 
248 aurelien 2135
			double[] coord = {lat, lon};
2136
			return coord;
1858 raphael 2137
 
248 aurelien 2138
		} catch (NumberFormatException ne) {
2139
			return null;
2140
		}
2141
	}
1858 raphael 2142
 
264 aurelien 2143
	private String[] getValeurCoordonnees() {
2144
		double[] coDouble = coordonneesValides();
1858 raphael 2145
 
264 aurelien 2146
		if(coDouble != null) {
2147
			String[] coord = {coDouble[0]+"",coDouble[1]+""};
2148
			return coord;
2149
		} else {
2150
			String[] coord = {"000null","000null" };
2151
			return coord;
2152
		}
2153
	}
1858 raphael 2154
 
268 aurelien 2155
	public String getCommune() {
1858 raphael 2156
 
656 aurelien 2157
		String valeurCommune = "";
1858 raphael 2158
 
656 aurelien 2159
		if(commune.getValue() != null) {
1858 raphael 2160
			valeurCommune = commune.getValue();
656 aurelien 2161
		}
2162
		return valeurCommune;
268 aurelien 2163
	}
1858 raphael 2164
 
268 aurelien 2165
	public String getDepartement() {
1542 aurelien 2166
		return Util.obtenirDepartementAPartirChaineCommune(departement, commune.getText());
268 aurelien 2167
	}
1858 raphael 2168
 
656 aurelien 2169
	public String getCommuneSansDepartement() {
2170
		return Util.supprimerNumDepartementChaineLocalite(getCommune());
2171
	}
1858 raphael 2172
 
1542 aurelien 2173
	private String getValeurChampListeLibre(ComboBox champ) {
2174
		String valeurChamp = champ.getValue();
2175
		String valeurChampBrute = champ.getRawValue();
1858 raphael 2176
 
1488 aurelien 2177
		// Test idiot qui permet de savoir si l'on utilise la valeur saisie directement ou bien la valeur
1858 raphael 2178
		// selectionnee car lors du setValue sur le keypress, gwtext ne prends pas en compte le dernier
1488 aurelien 2179
		// caractère
1858 raphael 2180
 
1559 aurelien 2181
		if(valeurChampBrute.trim().length() == 0) {
2182
			valeurChamp = "";
2183
		} else {
2184
			if(valeurChamp != null && valeurChamp.length() > 0) {
2185
				if(valeurChamp.equals(valeurChampBrute.substring(0, valeurChampBrute.length() -1))) {
2186
					valeurChamp = champ.getRawValue();
2187
				}
1542 aurelien 2188
			}
1488 aurelien 2189
		}
1542 aurelien 2190
		return valeurChamp;
1488 aurelien 2191
	}
1542 aurelien 2192
 
2193
	public String getAbondance() {
2194
		return getValeurChampListeLibre(selecteurAbondance);
2195
	}
1858 raphael 2196
 
1488 aurelien 2197
	public String getCertitude() {
1542 aurelien 2198
		return getValeurChampListeLibre(selecteurCertitude);
1488 aurelien 2199
	}
1858 raphael 2200
 
1542 aurelien 2201
	public String getPhenologie() {
2202
		return getValeurChampListeLibre(selecteurStadePheno);
2203
	}
1858 raphael 2204
 
1542 aurelien 2205
	public String getReferentielTaxo() {
2206
		String codeCourt = getValeurChampListeLibre(selecteurReferentielTaxo);
2207
		return Ontologies.getInfosReferentielNomParCode(codeCourt).getCodeVersionComplet();
2208
	}
268 aurelien 2209
 
2210
	public boolean communeInitialisee() {
2211
		return communeModifiee;
2212
	}
1858 raphael 2213
 
318 aurelien 2214
	public void redimensionnerFormulaire() {
681 aurelien 2215
		afficherFormulaireLatLon.setWidth(panneauIntermediaire.getWidth()+"px");
2216
		panneauPremierColonne.doLayout();
2217
		panneauSecondeColonne.doLayout();
2218
		panneauIntermediaire.doLayout();
1858 raphael 2219
 
708 aurelien 2220
		doLayout();
318 aurelien 2221
	}
12 david 2222
}