Subversion Repositories eFlore/Applications.cel

Rev

Rev 1542 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1542 Rev 1572
1
package org.tela_botanica.client.vues.observation;
1
package org.tela_botanica.client.vues.observation;
2
 
2
 
3
 
3
 
4
import java.util.Iterator;
4
import java.util.Iterator;
5
 
5
 
6
import org.tela_botanica.client.modeles.objets.ListeObservation;
6
import org.tela_botanica.client.modeles.objets.ListeObservation;
7
import org.tela_botanica.client.modeles.objets.Observation;
7
import org.tela_botanica.client.modeles.objets.Observation;
8
import org.tela_botanica.client.modeles.objets.Ontologies;
8
import org.tela_botanica.client.modeles.objets.Ontologies;
9
import org.tela_botanica.client.observation.ObservationMediateur;
9
import org.tela_botanica.client.observation.ObservationMediateur;
10
import org.tela_botanica.client.util.Util;
10
import org.tela_botanica.client.util.Util;
11
import org.tela_botanica.client.vues.BarrePaginationVue;
11
import org.tela_botanica.client.vues.BarrePaginationVue;
12
import org.tela_botanica.client.interfaces.ListePaginable;
12
import org.tela_botanica.client.interfaces.ListePaginable;
13
import org.tela_botanica.client.interfaces.Rafraichissable;
13
import org.tela_botanica.client.interfaces.Rafraichissable;
14
import org.tela_botanica.client.interfaces.VueListable;
14
import org.tela_botanica.client.interfaces.VueListable;
15
 
15
 
16
import com.gwtext.client.core.EventCallback;
16
import com.gwtext.client.core.EventCallback;
17
import com.gwtext.client.core.EventObject;
17
import com.gwtext.client.core.EventObject;
18
import com.gwtext.client.core.Ext;
18
import com.gwtext.client.core.Ext;
19
import com.gwtext.client.core.ExtElement;
19
import com.gwtext.client.core.ExtElement;
20
import com.gwtext.client.data.ArrayReader;
20
import com.gwtext.client.data.ArrayReader;
21
import com.gwtext.client.data.FieldDef;
21
import com.gwtext.client.data.FieldDef;
22
import com.gwtext.client.data.IntegerFieldDef;
22
import com.gwtext.client.data.IntegerFieldDef;
23
import com.gwtext.client.data.MemoryProxy;
23
import com.gwtext.client.data.MemoryProxy;
24
import com.gwtext.client.data.Record;
24
import com.gwtext.client.data.Record;
25
import com.gwtext.client.data.RecordDef;
25
import com.gwtext.client.data.RecordDef;
26
import com.gwtext.client.data.Store;
26
import com.gwtext.client.data.Store;
27
import com.gwtext.client.data.StringFieldDef;
27
import com.gwtext.client.data.StringFieldDef;
28
import com.gwtext.client.dd.DragData;
28
import com.gwtext.client.dd.DragData;
29
import com.gwtext.client.dd.DragDropConfig;
29
import com.gwtext.client.dd.DragDropConfig;
30
import com.gwtext.client.dd.DragSource;
30
import com.gwtext.client.dd.DragSource;
31
import com.gwtext.client.dd.DropTarget;
31
import com.gwtext.client.dd.DropTarget;
32
import com.gwtext.client.dd.DropTargetConfig;
32
import com.gwtext.client.dd.DropTargetConfig;
33
import com.gwtext.client.widgets.Button;
33
import com.gwtext.client.widgets.Button;
34
import com.gwtext.client.widgets.Component;
34
import com.gwtext.client.widgets.Component;
35
import com.gwtext.client.widgets.Panel;
35
import com.gwtext.client.widgets.Panel;
36
import com.gwtext.client.widgets.Tool;
36
import com.gwtext.client.widgets.Tool;
37
import com.gwtext.client.widgets.Toolbar;
37
import com.gwtext.client.widgets.Toolbar;
38
import com.gwtext.client.widgets.ToolbarButton;
38
import com.gwtext.client.widgets.ToolbarButton;
39
import com.gwtext.client.widgets.ToolbarTextItem;
39
import com.gwtext.client.widgets.ToolbarTextItem;
40
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
40
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
41
import com.gwtext.client.widgets.event.PanelListenerAdapter;
41
import com.gwtext.client.widgets.event.PanelListenerAdapter;
42
import com.gwtext.client.widgets.grid.CellMetadata;
42
import com.gwtext.client.widgets.grid.CellMetadata;
43
import com.gwtext.client.widgets.grid.ColumnConfig;
43
import com.gwtext.client.widgets.grid.ColumnConfig;
44
import com.gwtext.client.widgets.grid.ColumnModel;
44
import com.gwtext.client.widgets.grid.ColumnModel;
45
import com.gwtext.client.widgets.grid.GridPanel;
45
import com.gwtext.client.widgets.grid.GridPanel;
46
import com.gwtext.client.widgets.grid.Renderer;
46
import com.gwtext.client.widgets.grid.Renderer;
47
import com.gwtext.client.widgets.grid.event.GridListenerAdapter;
47
import com.gwtext.client.widgets.grid.event.GridListenerAdapter;
48
import com.gwtext.client.widgets.grid.event.GridRowListenerAdapter;
48
import com.gwtext.client.widgets.grid.event.GridRowListenerAdapter;
49
import com.gwtext.client.widgets.tree.TreeDragData;
49
import com.gwtext.client.widgets.tree.TreeDragData;
50
import com.gwtext.client.widgets.tree.TreeNode;
50
import com.gwtext.client.widgets.tree.TreeNode;
51
 
51
 
52
/**
52
/**
53
 * Liste d'observation composée de ligne d'observation
53
 * Liste d'observation composée de ligne d'observation
54
 * l'interface rafraichissable et l'interface vueListable
54
 * l'interface rafraichissable et l'interface vueListable
55
 * 
55
 * 
56
 * @author David Delon 2008
56
 * @author David Delon 2008
57
 */
57
 */
58
public class ListeObservationVue extends GridPanel implements Rafraichissable,
58
public class ListeObservationVue extends GridPanel implements Rafraichissable,
59
		VueListable, ListePaginable {
59
		VueListable, ListePaginable {
60
 
60
 
61
	/**
61
	/**
62
	 * Le médiateur associé à la vue
62
	 * Le médiateur associé à la vue
63
	 */
63
	 */
64
	private ObservationMediateur	observationMediateur		= null;
64
	private ObservationMediateur	observationMediateur		= null;
65
 
65
 
66
	/**
66
	/**
67
	 * Config de colonne
67
	 * Config de colonne
68
	 */
68
	 */
69
	private ColumnConfig	etatObservation;
69
	private ColumnConfig	etatObservation;
70
	private ColumnConfig	referentielTaxoObservation;
70
	private ColumnConfig	referentielTaxoObservation;
71
	private ColumnConfig	nomSaisiObservation;
71
	private ColumnConfig	nomSaisiObservation;
72
	private ColumnConfig	nomRetenuObservation;
72
	private ColumnConfig	nomRetenuObservation;
73
	private ColumnConfig	lieuObservation;
73
	private ColumnConfig	lieuObservation;
-
 
74
	private ColumnConfig	altitudeObservation;
74
	private ColumnConfig	dateObservation;
75
	private ColumnConfig	dateObservation;
75
	private ColumnConfig	ordreObservation;
76
	private ColumnConfig	ordreObservation;
76
	private ColumnConfig 	abondanceObservation;
77
	private ColumnConfig 	abondanceObservation;
77
	private ColumnConfig 	certitudeObservation;
78
	private ColumnConfig 	certitudeObservation;
78
	private ColumnModel		modeleColonnes;
79
	private ColumnModel		modeleColonnes;
79
 
80
 
80
	/**
81
	/**
81
	 * Store qui contient les données à afficher
82
	 * Store qui contient les données à afficher
82
	 */
83
	 */
83
	private Store			st				= null;
84
	private Store			st				= null;
84
	/**
85
	/**
85
	 * Barre de pagination
86
	 * Barre de pagination
86
	 */
87
	 */
87
	private BarrePaginationVue bt = null ;
88
	private BarrePaginationVue bt = null ;
88
	/**
89
	/**
89
	 * Numéro de page en cours
90
	 * Numéro de page en cours
90
	 */
91
	 */
91
	private int pageEncours = 0 ;
92
	private int pageEncours = 0 ;
92
	/**
93
	/**
93
	 * Nombre de pages totales
94
	 * Nombre de pages totales
94
	 */
95
	 */
95
	private int pageMax = 1 ;
96
	private int pageMax = 1 ;
96
	/**
97
	/**
97
	 * Taille de page (par défaut 20)
98
	 * Taille de page (par défaut 20)
98
	 */
99
	 */
99
	private int taillePage = 20 ;
100
	private int taillePage = 20 ;
100
	/**
101
	/**
101
	 * Nombre d'éléments total correspondant à la requete
102
	 * Nombre d'éléments total correspondant à la requete
102
	 */
103
	 */
103
	private int nbElements = 0 ;
104
	private int nbElements = 0 ;
104
	
105
	
105
	private ListeObservation cacheListeObservation = null;
106
	private ListeObservation cacheListeObservation = null;
106
	
107
	
107
	private Tool exporterObservations = null ;
108
	private Tool exporterObservations = null ;
108
	
109
	
109
	private final int KEY_ENTER = 13;
110
	private final int KEY_ENTER = 13;
110
	
111
	
111
	private String modeleLieu = "IDLOCCOMMUNE, LIEUDIT, STATION";
112
	private String modeleLieu = "IDLOCCOMMUNE, LIEUDIT, STATION";
112
 
113
 
113
 
114
 
114
	private boolean tailleInitialisee = false ;
115
	private boolean tailleInitialisee = false ;
115
 
116
 
116
	private ColumnConfig phenologieObservation;
117
	private ColumnConfig phenologieObservation;
117
	
118
	
118
	/**
119
	/**
119
	 * Constructeur sans arguments (privé car ne doit pas être utilisé)
120
	 * Constructeur sans arguments (privé car ne doit pas être utilisé)
120
	 */
121
	 */
121
	@SuppressWarnings("unused")
122
	@SuppressWarnings("unused")
122
	private ListeObservationVue()
123
	private ListeObservationVue()
123
	{
124
	{
124
		super() ;
125
		super() ;
125
	}
126
	}
126
	
127
	
127
	/**
128
	/**
128
	 * Constructeur avec argument
129
	 * Constructeur avec argument
129
	 * @param im le médiateur à associer
130
	 * @param im le médiateur à associer
130
	 */
131
	 */
131
	public ListeObservationVue(ObservationMediateur obs) {		
132
	public ListeObservationVue(ObservationMediateur obs) {		
132
		
133
		
133
		this.observationMediateur = obs;
134
		this.observationMediateur = obs;
134
		
135
		
135
		setId("x-list-obs");
136
		setId("x-list-obs");
136
		
137
		
137
		setHeader(true);  
138
		setHeader(true);  
138
		// on place la barre de pagination
139
		// on place la barre de pagination
139
		bt = new BarrePaginationVue(this);		
140
		bt = new BarrePaginationVue(this);		
140
		bt.setLabelElement("Observations");
141
		bt.setLabelElement("Observations");
141
		bt.setTaillePageParDefaut(20);
142
		bt.setTaillePageParDefaut(20);
142
		bt.setIntervallesPages(new String[] {"1000","400","200","100","50","20","10"}) ;
143
		bt.setIntervallesPages(new String[] {"1000","400","200","100","50","20","10"}) ;
143
		
144
		
144
		Toolbar barreActions = new Toolbar();
145
		Toolbar barreActions = new Toolbar();
145
		ToolbarButton publier = new ToolbarButton("Rendre publiques");
146
		ToolbarButton publier = new ToolbarButton("Rendre publiques");
146
		publier.addListener(new ButtonListenerAdapter() {
147
		publier.addListener(new ButtonListenerAdapter() {
147
			@Override
148
			@Override
148
			public void onClick(Button b, EventObject e) {
149
			public void onClick(Button b, EventObject e) {
149
				observationMediateur.transmettreObservations(true);
150
				observationMediateur.transmettreObservations(true);
150
			}
151
			}
151
		});
152
		});
152
		
153
		
153
		ToolbarButton privatiser = new ToolbarButton("Rendre privées");
154
		ToolbarButton privatiser = new ToolbarButton("Rendre privées");
154
		privatiser.addListener(new ButtonListenerAdapter() {
155
		privatiser.addListener(new ButtonListenerAdapter() {
155
			@Override
156
			@Override
156
			public void onClick(Button b, EventObject e) {
157
			public void onClick(Button b, EventObject e) {
157
				observationMediateur.transmettreObservations(false);
158
				observationMediateur.transmettreObservations(false);
158
			}
159
			}
159
		});
160
		});
160
		
161
		
161
		ToolbarButton supprimer = new ToolbarButton("Supprimer");
162
		ToolbarButton supprimer = new ToolbarButton("Supprimer");
162
		supprimer.addListener(new ButtonListenerAdapter() {
163
		supprimer.addListener(new ButtonListenerAdapter() {
163
			@Override
164
			@Override
164
			public void onClick(Button b, EventObject e) {
165
			public void onClick(Button b, EventObject e) {
165
				observationMediateur.supprimerObservations();
166
				observationMediateur.supprimerObservations();
166
			}
167
			}
167
		});
168
		});
168
		
169
		
169
		ToolbarButton importer = new ToolbarButton("Importer");
170
		ToolbarButton importer = new ToolbarButton("Importer");
170
		importer.addListener(new ButtonListenerAdapter() {
171
		importer.addListener(new ButtonListenerAdapter() {
171
			@Override
172
			@Override
172
			public void onClick(Button b, EventObject e) {
173
			public void onClick(Button b, EventObject e) {
173
				observationMediateur.afficherFormulaireImportObservation();
174
				observationMediateur.afficherFormulaireImportObservation();
174
			}
175
			}
175
		});
176
		});
176
		
177
		
177
		ToolbarTextItem exporter = new ToolbarTextItem("<a href=\"#\" id=\"lienExport\"> Exporter </a>");
178
		ToolbarTextItem exporter = new ToolbarTextItem("<a href=\"#\" id=\"lienExport\"> Exporter </a>");
178
		
179
		
179
		barreActions.addButton(publier);
180
		barreActions.addButton(publier);
180
		barreActions.addButton(privatiser);
181
		barreActions.addButton(privatiser);
181
		barreActions.addSpacer();
182
		barreActions.addSpacer();
182
		barreActions.addButton(supprimer);
183
		barreActions.addButton(supprimer);
183
		barreActions.addSpacer();
184
		barreActions.addSpacer();
184
		barreActions.addButton(importer);
185
		barreActions.addButton(importer);
185
		barreActions.addSpacer();
186
		barreActions.addSpacer();
186
		barreActions.addItem(exporter);
187
		barreActions.addItem(exporter);
187
		
188
		
188
		this.setTopToolbar(barreActions) ;
189
		this.setTopToolbar(barreActions) ;
189
		this.setBottomToolbar(bt);
190
		this.setBottomToolbar(bt);
190
		
191
		
191
		this.setCollapsible(true);
192
		this.setCollapsible(true);
192
		this.setTitleCollapse(true);
193
		this.setTitleCollapse(true);
193
 
194
 
194
		this.setTitle("Observations") ;
195
		this.setTitle("Observations") ;
195
		
196
		
196
		modeleColonnes = new ColumnModel(getConfigColonnes());
197
		modeleColonnes = new ColumnModel(getConfigColonnes());
197
		
198
		
198
		this.setColumnModel(modeleColonnes);
199
		this.setColumnModel(modeleColonnes);
199
		
200
		
200
		this.setAutoScroll(true);
201
		this.setAutoScroll(true);
201
		this.setEnableColumnResize(true);
202
		this.setEnableColumnResize(true);
202
		
203
		
203
		// creation du store		
204
		// creation du store		
204
		RecordDef rd = new RecordDef(getDefinitionChamps());
205
		RecordDef rd = new RecordDef(getDefinitionChamps());
205
		st = new Store(rd);
206
		st = new Store(rd);
206
		
207
		
207
		// on associe le store
208
		// on associe le store
208
		
209
		
209
		this.setStore(st);
210
		this.setStore(st);
210
		this.getView().setAutoFill(true);
211
		this.getView().setAutoFill(true);
211
		this.getView().setForceFit(true) ;
212
		this.getView().setForceFit(true) ;
212
				
213
				
213
		// on crée un masque de chargement qui s'affichera lors des mises à jour
214
		// on crée un masque de chargement qui s'affichera lors des mises à jour
214
		this.setLoadMask("Chargement");
215
		this.setLoadMask("Chargement");
215
	
216
	
216
		// on ajoute les listeners
217
		// on ajoute les listeners
217
		ajouterListeners();
218
		ajouterListeners();
218
		
219
		
219
		configDragAndDrop();
220
		configDragAndDrop();
220
 
221
 
221
	}
222
	}
222
	
223
	
223
	private ColumnConfig[] getConfigColonnes() {
224
	private ColumnConfig[] getConfigColonnes() {
224
		// on construit le modèle de colonnes
225
		// on construit le modèle de colonnes
225
		// Le store suivant est ensuite remplacé par le store contenant les données obtenus depuis le serveur (cf rafraichir) 
226
		// Le store suivant est ensuite remplacé par le store contenant les données obtenus depuis le serveur (cf rafraichir) 
226
		Renderer colRend = new Renderer() {
227
		Renderer colRend = new Renderer() {
227
 
228
 
228
			@Override
229
			@Override
229
			public String render(Object value, CellMetadata cellMetadata,
230
			public String render(Object value, CellMetadata cellMetadata,
230
					Record record, int rowIndex, int colNum, Store store) {
231
					Record record, int rowIndex, int colNum, Store store) {
231
				
232
				
232
				String valeur = "";
233
				String valeur = "";
233
				if(value != null && !value.equals("null") && !value.equals("000null") && !value.equals("0000-00-00 00:00:00")) {			
234
				if(value != null && !value.equals("null") && !value.equals("000null") && !value.equals("0000-00-00 00:00:00")) {			
234
					valeur = value.toString() ;
235
					valeur = value.toString() ;
235
				}
236
				}
236
				return valeur;
237
				return valeur;
237
			}
238
			}
238
		} ;
239
		} ;
239
		
240
		
240
		Renderer dateRend = new Renderer() {
241
		Renderer dateRend = new Renderer() {
241
 
242
 
242
			@Override
243
			@Override
243
			public String render(Object value, CellMetadata cellMetadata,
244
			public String render(Object value, CellMetadata cellMetadata,
244
					Record record, int rowIndex, int colNum, Store store) {
245
					Record record, int rowIndex, int colNum, Store store) {
245
				
246
				
246
				if(value == null || value.equals("null") || value.equals("000null") || value.equals("0000-00-00 00:00:00")) {
247
				if(value == null || value.equals("null") || value.equals("000null") || value.equals("0000-00-00 00:00:00")) {
247
				
248
				
248
					return "" ;
249
					return "" ;
249
				}	
250
				}	
250
				else
251
				else
251
				{
252
				{
252
					String dateEntiere = value.toString() ;
253
					String dateEntiere = value.toString() ;
253
					String[] dateEtHeure = dateEntiere.split(" ", 2);
254
					String[] dateEtHeure = dateEntiere.split(" ", 2);
254
					if(verifierFormatDate(dateEtHeure[0])) {
255
					if(verifierFormatDate(dateEtHeure[0])) {
255
						String[] dateFormateeTab = dateEtHeure[0].split("-",3);
256
						String[] dateFormateeTab = dateEtHeure[0].split("-",3);
256
						return dateFormateeTab[2]+"/"+dateFormateeTab[1]+"/"+dateFormateeTab[0] ;
257
						return dateFormateeTab[2]+"/"+dateFormateeTab[1]+"/"+dateFormateeTab[0] ;
257
					}
258
					}
258
				}
259
				}
259
				
260
				
260
				return value.toString() ;
261
				return value.toString() ;
261
			}
262
			}
262
			
263
			
263
		} ;
264
		} ;
264
		
265
		
265
		etatObservation = new ColumnConfig("Transmis", "etat_observation", 20, true, new Renderer() {
266
		etatObservation = new ColumnConfig("Transmis", "etat_observation", 20, true, new Renderer() {
266
 
267
 
267
			@Override
268
			@Override
268
			public String render(Object value, CellMetadata cellMetadata,
269
			public String render(Object value, CellMetadata cellMetadata,
269
					Record record, int rowIndex, int colNum, Store store) {
270
					Record record, int rowIndex, int colNum, Store store) {
270
				if(value.equals("1"))
271
				if(value.equals("1"))
271
				{
272
				{
272
					return "<img src=\"tela.png\"/></img>" ;
273
					return "<img src=\"tela.png\"/></img>" ;
273
				}
274
				}
274
				else
275
				else
275
				{
276
				{
276
					return "" ;
277
					return "" ;
277
				}
278
				}
278
			}
279
			}
279
			
280
			
280
		});		
281
		});		
-
 
282
		
281
		referentielTaxoObservation = new ColumnConfig("Référentiel", "referentiel_taxo_observation", 15, true, colRend);
283
		referentielTaxoObservation = new ColumnConfig("Référentiel", "referentiel_taxo_observation", 15, true, colRend);
282
		nomSaisiObservation = new ColumnConfig("Nom saisi", "nomSaisi_observation", 130, true, colRend);
284
		nomSaisiObservation = new ColumnConfig("Nom saisi", "nomSaisi_observation", 130, true, colRend);
283
		nomRetenuObservation = new ColumnConfig("Nom retenu", "nomRetenu_observation", 130, true, colRend);
285
		nomRetenuObservation = new ColumnConfig("Nom retenu", "nomRetenu_observation", 130, true, colRend);
284
		lieuObservation = new ColumnConfig("Lieu", "lieu_observation", 130, true, colRend);
286
		lieuObservation = new ColumnConfig("Lieu", "lieu_observation", 130, true, colRend);
-
 
287
		altitudeObservation = new ColumnConfig("Alt", "altitude_observation", 10, true, colRend);
285
		dateObservation = new ColumnConfig("Date", "date_observation", 70, true, dateRend);
288
		dateObservation = new ColumnConfig("Date", "date_observation", 70, true, dateRend);
286
		abondanceObservation = new ColumnConfig("Abondance", "abondance", 50, true, colRend);
289
		abondanceObservation = new ColumnConfig("Abondance", "abondance", 50, true, colRend);
287
		certitudeObservation = new ColumnConfig("Identification", "certitude", 50, true, new Renderer() {
290
		certitudeObservation = new ColumnConfig("Identification", "certitude", 50, true, new Renderer() {
288
			@Override
291
			@Override
289
			public String render(Object value, CellMetadata cellMetadata,
292
			public String render(Object value, CellMetadata cellMetadata,
290
					Record record, int rowIndex, int colNum, Store store) {
293
					Record record, int rowIndex, int colNum, Store store) {
291
				return Ontologies.getCorrespondanceCertitude(record.getAsString("certitude"));
294
				return Ontologies.getCorrespondanceCertitude(record.getAsString("certitude"));
292
			}
295
			}
293
			
296
			
294
		});
297
		});
295
		phenologieObservation = new ColumnConfig("Phénologie", "phenologie", 40, true, colRend);	
298
		phenologieObservation = new ColumnConfig("Phénologie", "phenologie", 40, true, colRend);	
296
		ordreObservation = new ColumnConfig("Ordre", "ordre_observation", 70, true, colRend);		
299
		ordreObservation = new ColumnConfig("Ordre", "ordre_observation", 70, true, colRend);		
297
		ColumnConfig[] cm = {etatObservation, referentielTaxoObservation, nomSaisiObservation, certitudeObservation, nomRetenuObservation, abondanceObservation, phenologieObservation, lieuObservation, dateObservation, ordreObservation};
300
		ColumnConfig[] cm = {etatObservation, referentielTaxoObservation, 
-
 
301
							nomSaisiObservation, certitudeObservation, 
-
 
302
							nomRetenuObservation, abondanceObservation, 
-
 
303
							phenologieObservation, lieuObservation, 
-
 
304
							altitudeObservation, dateObservation, 
-
 
305
							ordreObservation};
298
	
306
	
299
		return cm;
307
		return cm;
300
	}
308
	}
301
 
309
 
302
 
310
 
303
	/**
311
	/**
304
	 * Ajoute les listeners pour la gestion des évènements
312
	 * Ajoute les listeners pour la gestion des évènements
305
	 */
313
	 */
306
	private void ajouterListeners() {
314
	private void ajouterListeners() {
307
		
315
		
308
		this.addGridRowListener(new GridRowListenerAdapter() {
316
		this.addGridRowListener(new GridRowListenerAdapter() {
309
			
317
			
310
			// gestion du clic sur une ligne
318
			// gestion du clic sur une ligne
311
			@Override
319
			@Override
312
			public void onRowClick(GridPanel grid, int rowIndex,
320
			public void onRowClick(GridPanel grid, int rowIndex,
313
					EventObject e) {
321
					EventObject e) {
314
				// on notifie le médiateur et on lui passe le numéro de ligne
322
				// on notifie le médiateur et on lui passe le numéro de ligne
315
				
323
				
316
			
324
			
317
				Record rd = st.getAt(rowIndex);
325
				Record rd = st.getAt(rowIndex);
318
				
326
				
319
				String ordreObservation = rd.getAsString("ordre_observation") ;
327
				String ordreObservation = rd.getAsString("ordre_observation") ;
320
				
328
				
321
				observationMediateur.onClicListeObservation(rowIndex,ordreObservation);
329
				observationMediateur.onClicListeObservation(rowIndex,ordreObservation);
322
				
330
				
323
			}
331
			}
324
 
332
 
325
			// gestion du clic droit
333
			// gestion du clic droit
326
			@Override
334
			@Override
327
			public void onRowContextMenu(GridPanel grid, int rowIndex,
335
			public void onRowContextMenu(GridPanel grid, int rowIndex,
328
					EventObject e) {
336
					EventObject e) {
329
				// on stoppe l'évenement pour empecher le navigateur d'afficher son propre menu
337
				// on stoppe l'évenement pour empecher le navigateur d'afficher son propre menu
330
				e.stopEvent() ;
338
				e.stopEvent() ;
331
				// on notifie le médiateur en lui passant l'évenement
339
				// on notifie le médiateur en lui passant l'évenement
332
				observationMediateur.montrerContextMenu(e);
340
				observationMediateur.montrerContextMenu(e);
333
			}
341
			}
334
 
342
 
335
			// gestion du double clic
343
			// gestion du double clic
336
			@Override
344
			@Override
337
			public void onRowDblClick(GridPanel grid, int rowIndex,
345
			public void onRowDblClick(GridPanel grid, int rowIndex,
338
					EventObject e) {
346
					EventObject e) {
339
				// on notifie le médiateur en lui passant le numéro de ligne
347
				// on notifie le médiateur en lui passant le numéro de ligne
340
				observationMediateur.doubleClicListeObservation(rowIndex);
348
				observationMediateur.doubleClicListeObservation(rowIndex);
341
			}
349
			}
342
			
350
			
343
		});
351
		});
344
		
352
		
345
		this.addGridListener(new GridListenerAdapter() {
353
		this.addGridListener(new GridListenerAdapter() {
346
			@Override
354
			@Override
347
			public void onKeyPress(EventObject e) {
355
			public void onKeyPress(EventObject e) {
348
				if(e.getKey() == KEY_ENTER) {
356
				if(e.getKey() == KEY_ENTER) {
349
					Record rd = getSelectionModel().getSelected();
357
					Record rd = getSelectionModel().getSelected();
350
					int rowIndex = st.indexOf(rd);
358
					int rowIndex = st.indexOf(rd);
351
					String ordreObservation = rd.getAsString("ordre_observation") ;
359
					String ordreObservation = rd.getAsString("ordre_observation") ;
352
					observationMediateur.onClicListeObservation(rowIndex, ordreObservation);
360
					observationMediateur.onClicListeObservation(rowIndex, ordreObservation);
353
				}
361
				}
354
			}
362
			}
355
		});
363
		});
356
		
364
		
357
		this.addListener(new PanelListenerAdapter() {
365
		this.addListener(new PanelListenerAdapter() {
358
			@Override
366
			@Override
359
			public void onRender(Component c) {
367
			public void onRender(Component c) {
360
				
368
				
361
				ExtElement lienExport = Ext.get("lienExport") ;
369
				ExtElement lienExport = Ext.get("lienExport") ;
362
				lienExport.addListener("click", new EventCallback() {
370
				lienExport.addListener("click", new EventCallback() {
363
 
371
 
364
					@Override
372
					@Override
365
					public void execute(EventObject e) {
373
					public void execute(EventObject e) {
366
						
374
						
367
						observationMediateur.exporterObservations();
375
						observationMediateur.exporterObservations();
368
					}
376
					}
369
					
377
					
370
				});
378
				});
371
			}
379
			}
372
		});
380
		});
373
		
381
		
374
		this.addListener(new PanelListenerAdapter() {
382
		this.addListener(new PanelListenerAdapter() {
375
			@Override
383
			@Override
376
			public void onBodyResize(Panel panel, java.lang.String width, java.lang.String height) {
384
			public void onBodyResize(Panel panel, java.lang.String width, java.lang.String height) {
377
				doLayout();
385
				doLayout();
378
			}
386
			}
379
		});
387
		});
380
	}
388
	}
381
	
389
	
382
	/**
390
	/**
383
	 * Configure le drag 'n drop pour la liste
391
	 * Configure le drag 'n drop pour la liste
384
	 */
392
	 */
385
	private void configDragAndDrop()
393
	private void configDragAndDrop()
386
	{
394
	{
387
 
395
 
388
		setDdGroup("ObsMotsClesGroup");
396
		setDdGroup("ObsMotsClesGroup");
389
		setEnableDragDrop(true);
397
		setEnableDragDrop(true);
390
		setDragDropText("Glissez les observations sélectionnées sur un projet pour les lier");
398
		setDragDropText("Glissez les observations sélectionnées sur un projet pour les lier");
391
		// on fabrique la nouvelle configuration
399
		// on fabrique la nouvelle configuration
392
		// les éléments sur lesquels on fait du drag 'n drop doivent tous avoir le même ddGroup
400
		// les éléments sur lesquels on fait du drag 'n drop doivent tous avoir le même ddGroup
393
		DropTargetConfig dtc = new DropTargetConfig();
401
		DropTargetConfig dtc = new DropTargetConfig();
394
		dtc.setdDdGroup("ObsMotsClesGroup");
402
		dtc.setdDdGroup("ObsMotsClesGroup");
395
		dtc.setTarget(true);
403
		dtc.setTarget(true);
396
		
404
		
397
		DragDropConfig ddc = new DragDropConfig();
405
		DragDropConfig ddc = new DragDropConfig();
398
 
406
 
399
		//La drop target permet de gérer l'évenement onDrop sur l'élement courant
407
		//La drop target permet de gérer l'évenement onDrop sur l'élement courant
400
		@SuppressWarnings("unused")
408
		@SuppressWarnings("unused")
401
		DropTarget tg = new DropTarget(this, dtc)
409
		DropTarget tg = new DropTarget(this, dtc)
402
		{
410
		{
403
			@Override
411
			@Override
404
			public boolean notifyDrop(DragSource source, EventObject e, DragData data){	
412
			public boolean notifyDrop(DragSource source, EventObject e, DragData data){	
405
				
413
				
406
				// si on reçoit des données provenant d'un arbre
414
				// si on reçoit des données provenant d'un arbre
407
				// on les convertit 
415
				// on les convertit 
408
				if(data instanceof TreeDragData)  {
416
				if(data instanceof TreeDragData)  {
409
			    	TreeDragData tdd = (TreeDragData)data ;
417
			    	TreeDragData tdd = (TreeDragData)data ;
410
			    	
418
			    	
411
			    	TreeNode treeNode = tdd.getTreeNode();  
419
			    	TreeNode treeNode = tdd.getTreeNode();  
412
			    	String idMc = treeNode.getId();  
420
			    	String idMc = treeNode.getId();  
413
			    	
421
			    	
414
			    	int index = getView().findRowIndex(e);
422
			    	int index = getView().findRowIndex(e);
415
			    	if(index < 0) {
423
			    	if(index < 0) {
416
			    		return true;
424
			    		return true;
417
			    	}
425
			    	}
418
			    	
426
			    	
419
			    	Record obsRd = getStore().getRecordAt(index);
427
			    	Record obsRd = getStore().getRecordAt(index);
420
			    	if(obsRd == null) {
428
			    	if(obsRd == null) {
421
			    		return true;
429
			    		return true;
422
			    	}
430
			    	}
423
			    	
431
			    	
424
			    	String ordreObs = obsRd.getAsString("ordre_observation");
432
			    	String ordreObs = obsRd.getAsString("ordre_observation");
425
			    	
433
			    	
426
			    	if(ordreObs != null) {
434
			    	if(ordreObs != null) {
427
			    		observationMediateur.gererDDMotCleSurObs(ordreObs, idMc);
435
			    		observationMediateur.gererDDMotCleSurObs(ordreObs, idMc);
428
			    		return true ;
436
			    		return true ;
429
			    	} else {
437
			    	} else {
430
			    		return true;
438
			    		return true;
431
			    	}
439
			    	}
432
				}
440
				}
433
		    	return true;
441
		    	return true;
434
			}
442
			}
435
			
443
			
436
			@Override
444
			@Override
437
			public String notifyOver(DragSource source, EventObject e, DragData data){
445
			public String notifyOver(DragSource source, EventObject e, DragData data){
438
				
446
				
439
				if(data instanceof TreeDragData)  {
447
				if(data instanceof TreeDragData)  {
440
			    	TreeDragData tdd = (TreeDragData)data ;
448
			    	TreeDragData tdd = (TreeDragData)data ;
441
			    	
449
			    	
442
			    	TreeNode treeNode = tdd.getTreeNode();  
450
			    	TreeNode treeNode = tdd.getTreeNode();  
443
			    	String idMc = treeNode.getId();  
451
			    	String idMc = treeNode.getId();  
444
			    	
452
			    	
445
			    	int index = getView().findRowIndex(e);
453
			    	int index = getView().findRowIndex(e);
446
			    	if(index < 0) {
454
			    	if(index < 0) {
447
			    		return "x-dd-drop-nodrop";
455
			    		return "x-dd-drop-nodrop";
448
			    	}
456
			    	}
449
			    	
457
			    	
450
			    	Record obsRd = getStore().getRecordAt(index);
458
			    	Record obsRd = getStore().getRecordAt(index);
451
			    	
459
			    	
452
			    	if(obsRd == null) {
460
			    	if(obsRd == null) {
453
			    		return "x-dd-drop-nodrop";
461
			    		return "x-dd-drop-nodrop";
454
			    	}
462
			    	}
455
			    	
463
			    	
456
			    	String ordreObs = obsRd.getAsString("ordre_observation");
464
			    	String ordreObs = obsRd.getAsString("ordre_observation");
457
			    	
465
			    	
458
			    	if(ordreObs != null) {
466
			    	if(ordreObs != null) {
459
			    		return observationMediateur.gererOverDDMotCleSurObs(ordreObs, idMc);
467
			    		return observationMediateur.gererOverDDMotCleSurObs(ordreObs, idMc);
460
			    	}
468
			    	}
461
				}
469
				}
462
				
470
				
463
				return "x-dd-drop-nodrop";
471
				return "x-dd-drop-nodrop";
464
			}
472
			}
465
		};
473
		};
466
	}
474
	}
467
 
475
 
468
	/**
476
	/**
469
	 * Méthode héritée de l'interface VueListable
477
	 * Méthode héritée de l'interface VueListable
470
	 * Sélectionne les observations  dans la liste suivant les identifiants donnés en paramètres
478
	 * Sélectionne les observations  dans la liste suivant les identifiants donnés en paramètres
471
	 */
479
	 */
472
	@Override
480
	@Override
473
	public String[] getIdSelectionnees() {
481
	public String[] getIdSelectionnees() {
474
		
482
		
475
		Record[] selection = this.getSelectionModel().getSelections();
483
		Record[] selection = this.getSelectionModel().getSelections();
476
		int taille = selection.length;
484
		int taille = selection.length;
477
		String id_selection[] = new String[taille];
485
		String id_selection[] = new String[taille];
478
 
486
 
479
		for (int i = 0; i < selection.length; i++) {
487
		for (int i = 0; i < selection.length; i++) {
480
 
488
 
481
			id_selection[i] = selection[i].getAsString("ordre_observation");
489
			id_selection[i] = selection[i].getAsString("ordre_observation");
482
		}
490
		}
483
 
491
 
484
		return id_selection;
492
		return id_selection;
485
	}
493
	}
486
	
494
	
487
 
495
 
488
	
496
	
489
	/**
497
	/**
490
	 * Sélectionne des enregistrements donné 
498
	 * Sélectionne des enregistrements donné 
491
	 * @param sel un tableau d'enregistrement à selectionner
499
	 * @param sel un tableau d'enregistrement à selectionner
492
	 */
500
	 */
493
	public void selectionnerEnregistrements(Record[] sel) {
501
	public void selectionnerEnregistrements(Record[] sel) {
494
 
502
 
495
			getSelectionModel().clearSelections();
503
			getSelectionModel().clearSelections();
496
			getSelectionModel().selectRecords(sel);
504
			getSelectionModel().selectRecords(sel);
497
		
505
		
498
	}
506
	}
499
	
507
	
500
	/**
508
	/**
501
	 * Accesseur pour la toolbar de pagination
509
	 * Accesseur pour la toolbar de pagination
502
	 * @return la toolbar de pagination
510
	 * @return la toolbar de pagination
503
	 */
511
	 */
504
	public BarrePaginationVue getToolBarVue()
512
	public BarrePaginationVue getToolBarVue()
505
	{
513
	{
506
		return bt ;
514
		return bt ;
507
	}
515
	}
508
 
516
 
509
 
517
 
510
	/**
518
	/**
511
	 * Recherche l'élement actuellement affiché et affiche son message de chargement
519
	 * Recherche l'élement actuellement affiché et affiche son message de chargement
512
	 */
520
	 */
513
	public void masquerChargement()
521
	public void masquerChargement()
514
	{
522
	{
515
		ExtElement masked = Ext.get(getId()) ;
523
		ExtElement masked = Ext.get(getId()) ;
516
 
524
 
517
		if (masked!=null) {
525
		if (masked!=null) {
518
			masked.mask("Chargement") ;
526
			masked.mask("Chargement") ;
519
		}
527
		}
520
	}
528
	}
521
	
529
	
522
	/**
530
	/**
523
	 * Recherche l'élement actuellement affiché et retire son message de chargement si l'était affiché
531
	 * Recherche l'élement actuellement affiché et retire son message de chargement si l'était affiché
524
	 */
532
	 */
525
	public void demasquerChargement()
533
	public void demasquerChargement()
526
	{
534
	{
527
		ExtElement masked = Ext.get(getId()) ;
535
		ExtElement masked = Ext.get(getId()) ;
528
		
536
		
529
		if (masked!=null) {
537
		if (masked!=null) {
530
			masked.unmask() ;
538
			masked.unmask() ;
531
		}
539
		}
532
	}
540
	}
533
	
541
	
534
	/**
542
	/**
535
	 * Méthode héritée de l'interface rafraichissable
543
	 * Méthode héritée de l'interface rafraichissable
536
	 * @param nouvelleDonnees les nouvelles données
544
	 * @param nouvelleDonnees les nouvelles données
537
	 * @param repandreRafraichissement le booleen de notification du rafraichissement
545
	 * @param repandreRafraichissement le booleen de notification du rafraichissement
538
	 */
546
	 */
539
	@Override
547
	@Override
540
	public void rafraichir(Object nouvelleDonnees, boolean repandreRafraichissement) {
548
	public void rafraichir(Object nouvelleDonnees, boolean repandreRafraichissement) {
541
		// si l'on a reçu une liste d'observation
549
		// si l'on a reçu une liste d'observation
542
		if(nouvelleDonnees instanceof ListeObservation)
550
		if(nouvelleDonnees instanceof ListeObservation)
543
		{	
551
		{	
544
				ListeObservation data = (ListeObservation) nouvelleDonnees ;
552
				ListeObservation data = (ListeObservation) nouvelleDonnees ;
545
				Object[][] observationData = new Object[data.size()][11];
553
				Object[][] observationData = new Object[data.size()][12];
546
				int i = 0 ;
554
				int i = 0 ;
547
				
555
				
548
				if(data.size() == 0)
556
				if(data.size() == 0)
549
				{
557
				{
550
					pageEncours = 0 ;
558
					pageEncours = 0 ;
551
				}
559
				}
552
				
560
				
553
				// on la parse et on récupère les informations qui nous interessent
561
				// on la parse et on récupère les informations qui nous interessent
554
				for (Iterator it = data.keySet().iterator(); it.hasNext();) 
562
				for (Iterator it = data.keySet().iterator(); it.hasNext();) 
555
				{
563
				{
556
					
564
					
557
					Observation obs=data.get(it.next());
565
					Observation obs=data.get(it.next());
558
					
566
					
559
					observationData[i][0] = obs.getTransmis();
567
					observationData[i][0] = obs.getTransmis();
560
					observationData[i][1] = obs.getCodeCourtReferentielTaxo();
568
					observationData[i][1] = obs.getCodeCourtReferentielTaxo();
561
					observationData[i][2] = obs.getNomSaisi();
569
					observationData[i][2] = obs.getNomSaisi();
562
					observationData[i][3] = obs.getCertitude();
570
					observationData[i][3] = obs.getCertitude();
563
					observationData[i][4] = obs.getNomRetenu();
571
					observationData[i][4] = obs.getNomRetenu();
564
					observationData[i][5] = obs.getAbondance();
572
					observationData[i][5] = obs.getAbondance();
565
					observationData[i][6] = obs.getPhenologie();
573
					observationData[i][6] = obs.getPhenologie();
566
					observationData[i][7] = Util.formaterLieu(obs, modeleLieu);
574
					observationData[i][7] = Util.formaterLieu(obs, modeleLieu);
-
 
575
					observationData[i][8] = formaterAltitude(obs.getAltitude());
567
					observationData[i][8] = obs.getDate();
576
					observationData[i][9] = obs.getDate();
568
					observationData[i][9] = obs.getNumeroOrdre();		
577
					observationData[i][10] = obs.getNumeroOrdre();		
569
					observationData[i][10] = obs.getNumeroNomenclaturalSaisi();
578
					observationData[i][11] = obs.getNumeroNomenclaturalSaisi();
570
									
579
									
571
					i++ ;
580
					i++ ;
572
				}
581
				}
573
		
582
		
574
				RecordDef rd = new RecordDef(getDefinitionChamps());
583
				RecordDef rd = new RecordDef(getDefinitionChamps());
575
				
584
				
576
				final MemoryProxy dataProxy = new MemoryProxy(observationData);
585
				final MemoryProxy dataProxy = new MemoryProxy(observationData);
577
				final ArrayReader reader = new ArrayReader(rd);
586
				final ArrayReader reader = new ArrayReader(rd);
578
		
587
		
579
				final Store observationStore = new Store(dataProxy, reader);
588
				final Store observationStore = new Store(dataProxy, reader);
580
				
589
				
581
				
590
				
582
				st = observationStore ;
591
				st = observationStore ;
583
				st.load() ;
592
				st.load() ;
584
					
593
					
585
				// et on reconfigure et rafraichit la vue
594
				// et on reconfigure et rafraichit la vue
586
				this.reconfigure(st, this.getColumnModel());
595
				this.reconfigure(st, this.getColumnModel());
587
				demasquerChargement();
596
				demasquerChargement();
588
			    cacheListeObservation=data;
597
			    cacheListeObservation=data;
589
				observationMediateur.onRafraichissementListeObservations();	
598
				observationMediateur.onRafraichissementListeObservations();	
590
		}
599
		}
591
		
600
		
592
		// Si on reçoit un tableau d'entiers
601
		// Si on reçoit un tableau d'entiers
593
		// c'est un tableau d'un seul entier qui est le nombre d'observation correspondant aux critères
602
		// c'est un tableau d'un seul entier qui est le nombre d'observation correspondant aux critères
594
		if(nouvelleDonnees instanceof int[])
603
		if(nouvelleDonnees instanceof int[])
595
		{
604
		{
596
			int[] pages = (int[])nouvelleDonnees ;
605
			int[] pages = (int[])nouvelleDonnees ;
597
			
606
			
598
			// on calcule le nombre de pages nécessaires et on les met à jour dans le modèle
607
			// on calcule le nombre de pages nécessaires et on les met à jour dans le modèle
599
			pageMax  = calculerNbPages(pages[0]) ;
608
			pageMax  = calculerNbPages(pages[0]) ;
600
			nbElements = pages[0] ;
609
			nbElements = pages[0] ;
601
			
610
			
602
			
611
			
603
			// et on notifie de le mediateur du changement des valeurs
612
			// et on notifie de le mediateur du changement des valeurs
604
			changerPageMaxEtCourante(pageMax,pageEncours,taillePage,pages[0]) ;
613
			changerPageMaxEtCourante(pageMax,pageEncours,taillePage,pages[0]) ;
605
			
614
			
606
			if(nbElements > 0) {
615
			if(nbElements > 0) {
607
				masquerChargement();
616
				masquerChargement();
608
				observationMediateur.obtenirListeObservation(this);
617
				observationMediateur.obtenirListeObservation(this);
609
			} else {
618
			} else {
610
				this.rafraichir(new ListeObservation(0), false);
619
				this.rafraichir(new ListeObservation(0), false);
611
			}
620
			}
612
		}
621
		}
613
		
622
		
614
		
623
		
615
		// si l'on a reçu une Observation 
624
		// si l'on a reçu une Observation 
616
		if(nouvelleDonnees instanceof Observation) {
625
		if(nouvelleDonnees instanceof Observation) {
617
		
626
		
618
			Observation obs= (Observation) nouvelleDonnees;
627
			Observation obs= (Observation) nouvelleDonnees;
619
			if (obs.getNumeroOrdre()==null) { 
628
			if (obs.getNumeroOrdre()==null) { 
620
				
629
				
621
				// Nouvelle observation
630
				// Nouvelle observation
622
				// On affiche la dernière page
631
				// On affiche la dernière page
623
				pageEncours = pageMax ;
632
				pageEncours = pageMax ;
624
				masquerChargement();
633
				masquerChargement();
625
	
634
	
626
				observationMediateur.obtenirNombreObservation();
635
				observationMediateur.obtenirNombreObservation();
627
			
636
			
628
			}
637
			}
629
			else { // Modification d'une observation
638
			else { // Modification d'une observation
630
					
639
					
631
				masquerChargement();
640
				masquerChargement();
632
				observationMediateur.obtenirNombreObservation();		
641
				observationMediateur.obtenirNombreObservation();		
633
			}
642
			}
634
		}
643
		}
635
		
644
		
636
		// Si on a effectué une suppression
645
		// Si on a effectué une suppression
637
		if(nouvelleDonnees instanceof String)
646
		if(nouvelleDonnees instanceof String)
638
		{
647
		{
639
			observationMediateur.obtenirNombreObservation() ;
648
			observationMediateur.obtenirNombreObservation() ;
640
		}
649
		}
641
		
650
		
642
		if(!getTailleInitialisee()) {
651
		if(!getTailleInitialisee()) {
643
			if((int)Math.round(observationMediateur.getPanneauPrincipalObservation().getHeight() * 0.6) != 0) {
652
			if((int)Math.round(observationMediateur.getPanneauPrincipalObservation().getHeight() * 0.6) != 0) {
644
				doLayout();
653
				doLayout();
645
				setTailleInitialisee();
654
				setTailleInitialisee();
646
			}
655
			}
647
		}
656
		}
648
	}
657
	}
-
 
658
	
-
 
659
	private String formaterAltitude(String alt) {
-
 
660
		String alfFmt = Util.formaterNombre(alt);
-
 
661
		if(!alfFmt.isEmpty() && !Util.estZero(alfFmt)) {
-
 
662
			alfFmt = alfFmt+" m.";
-
 
663
		}
-
 
664
		return alfFmt;
-
 
665
	}
649
	
666
	
650
	private FieldDef[] getDefinitionChamps() {
667
	private FieldDef[] getDefinitionChamps() {
651
		// creation du store qui les contient
668
		// creation du store qui les contient
652
		FieldDef defEtatObservation = new StringFieldDef("etat_observation");
669
		FieldDef defEtatObservation = new StringFieldDef("etat_observation");
653
		FieldDef defRefTaxObservation = new StringFieldDef("referentiel_taxo_observation");
670
		FieldDef defRefTaxObservation = new StringFieldDef("referentiel_taxo_observation");
654
		FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
671
		FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
655
		FieldDef defCertitudeObservation = new StringFieldDef("certitude");
672
		FieldDef defCertitudeObservation = new StringFieldDef("certitude");
656
		FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
673
		FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
657
		FieldDef defAbondanceObservation = new StringFieldDef("abondance");
674
		FieldDef defAbondanceObservation = new StringFieldDef("abondance");
658
		FieldDef defPhenologieObservation = new StringFieldDef("phenologie");
675
		FieldDef defPhenologieObservation = new StringFieldDef("phenologie");
659
		FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
676
		FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
-
 
677
		FieldDef defAltObservation = new StringFieldDef("altitude_observation");
660
		FieldDef defDateObservation = new StringFieldDef("date_observation");
678
		FieldDef defDateObservation = new StringFieldDef("date_observation");
661
		FieldDef defOrdreObservation = new IntegerFieldDef("ordre_observation");
679
		FieldDef defOrdreObservation = new IntegerFieldDef("ordre_observation");
662
		
680
		
663
		// Non affiches :
681
		// Non affiches :
664
		FieldDef defNumeroNomenclaturalSaisiObservation = new StringFieldDef("numeroNomenclaturalSaisi_observation");
682
		FieldDef defNumeroNomenclaturalSaisiObservation = new StringFieldDef("numeroNomenclaturalSaisi_observation");
665
 
683
 
666
		FieldDef[] defTab = {defEtatObservation, defRefTaxObservation,defNomSaisiObservation, defCertitudeObservation, defNomRetenuObservation, defAbondanceObservation,
684
		FieldDef[] defTab = {defEtatObservation, defRefTaxObservation,defNomSaisiObservation, defCertitudeObservation, defNomRetenuObservation, defAbondanceObservation,
667
				defPhenologieObservation, defLieuObservation, defDateObservation, defOrdreObservation, defNumeroNomenclaturalSaisiObservation };
685
				defPhenologieObservation, defLieuObservation, defAltObservation, defDateObservation, defOrdreObservation, defNumeroNomenclaturalSaisiObservation };
668
		
686
		
669
		return defTab;
687
		return defTab;
670
	}
688
	}
671
	
689
	
672
	
690
	
673
	// GESTION DE LA PAGINATION
691
	// GESTION DE LA PAGINATION
674
	public ListeObservation getCacheListeObservation() {
692
	public ListeObservation getCacheListeObservation() {
675
		return cacheListeObservation;
693
		return cacheListeObservation;
676
	}
694
	}
677
 
695
 
678
	/**
696
	/**
679
	 * Calcule le nombre de pages nécessaires pour afficher un nombre d'élements donnés en fonction de la taille de page
697
	 * Calcule le nombre de pages nécessaires pour afficher un nombre d'élements donnés en fonction de la taille de page
680
	 * en cours
698
	 * en cours
681
	 * @param nbElements le nombre d'élements total
699
	 * @param nbElements le nombre d'élements total
682
	 * @return le nombre de pages 
700
	 * @return le nombre de pages 
683
	 */
701
	 */
684
	public int calculerNbPages(int nbElements)
702
	public int calculerNbPages(int nbElements)
685
	{
703
	{
686
		// A cause de la betise de java pour les conversion implicite on fait quelques conversions manuellement
704
		// A cause de la betise de java pour les conversion implicite on fait quelques conversions manuellement
687
		// pour eviter qu'il arrondisse mal la division
705
		// pour eviter qu'il arrondisse mal la division
688
		// nombre de pages = (nombre d'element / taille de la page) arrondi à l'entier superieur
706
		// nombre de pages = (nombre d'element / taille de la page) arrondi à l'entier superieur
689
		double nPage = (1.0*nbElements)/(1.0*taillePage) ; 
707
		double nPage = (1.0*nbElements)/(1.0*taillePage) ; 
690
		double nPageRound = Math.ceil(nPage) ;
708
		double nPageRound = Math.ceil(nPage) ;
691
		Double nPageInt = new Double(nPageRound) ;
709
		Double nPageInt = new Double(nPageRound) ;
692
		
710
		
693
		return nPageInt.intValue() ; 
711
		return nPageInt.intValue() ; 
694
	}
712
	}
695
 
713
 
696
	/**
714
	/**
697
	 * Recalcule la page en cours lors du changement du nombre d'élements
715
	 * Recalcule la page en cours lors du changement du nombre d'élements
698
	 * @param nbElements le nombre d'élements total
716
	 * @param nbElements le nombre d'élements total
699
	 * @return la nouvelle page encours
717
	 * @return la nouvelle page encours
700
	 */
718
	 */
701
	public int calculerPageCourante(int nbElements)
719
	public int calculerPageCourante(int nbElements)
702
	{
720
	{
703
		// on calcule le nombre de page
721
		// on calcule le nombre de page
704
		int nouvelNbPages = calculerNbPages(nbElements) ;
722
		int nouvelNbPages = calculerNbPages(nbElements) ;
705
		// la nouvelle page en cours
723
		// la nouvelle page en cours
706
		double nPageCourante = (1.0*pageEncours)/(1.0*pageMax) * (1.0*nouvelNbPages) ;
724
		double nPageCourante = (1.0*pageEncours)/(1.0*pageMax) * (1.0*nouvelNbPages) ;
707
		
725
		
708
		// on arrondit au supérieur
726
		// on arrondit au supérieur
709
		double nPageRound = Math.ceil(nPageCourante) ;
727
		double nPageRound = Math.ceil(nPageCourante) ;
710
		Double nPageInt = new Double(nPageRound) ;
728
		Double nPageInt = new Double(nPageRound) ;
711
		
729
		
712
		return Math.abs(nPageInt.intValue()) ; 
730
		return Math.abs(nPageInt.intValue()) ; 
713
	}
731
	}
714
	
732
	
715
	/**
733
	/**
716
	 * Appelle le modèle pour lui demander les données d'une page à afficher
734
	 * Appelle le modèle pour lui demander les données d'une page à afficher
717
	 * @param pageCourante le numéro de page à affciher
735
	 * @param pageCourante le numéro de page à affciher
718
	 */
736
	 */
719
	@Override
737
	@Override
720
	public void changerNumeroPage(int pageCourante) {
738
	public void changerNumeroPage(int pageCourante) {
721
		pageEncours = pageCourante ;
739
		pageEncours = pageCourante ;
722
		masquerChargement();
740
		masquerChargement();
723
		// On lance le chargerment des observations
741
		// On lance le chargerment des observations
724
		observationMediateur.obtenirNombreObservation();
742
		observationMediateur.obtenirNombreObservation();
725
		getToolBarVue().changerPageCourante(pageCourante);	
743
		getToolBarVue().changerPageCourante(pageCourante);	
726
	}
744
	}
727
	
745
	
728
	
746
	
729
	/**
747
	/**
730
	 * Appelle le modèle pour qu'il change la taille de page utilisée
748
	 * Appelle le modèle pour qu'il change la taille de page utilisée
731
	 * @param nouvelleTaillePage la nouvelle taille de page
749
	 * @param nouvelleTaillePage la nouvelle taille de page
732
	 */
750
	 */
733
	@Override
751
	@Override
734
	public void changerTaillePage(int nouvelleTaillePage) {
752
	public void changerTaillePage(int nouvelleTaillePage) {
735
	
753
	
736
		taillePage = nouvelleTaillePage ;
754
		taillePage = nouvelleTaillePage ;
737
		pageEncours = calculerPageCourante(nbElements) ;
755
		pageEncours = calculerPageCourante(nbElements) ;
738
 
756
 
739
		masquerChargement();
757
		masquerChargement();
740
 
758
 
741
		// 	On lance le chargement des observations
759
		// 	On lance le chargement des observations
742
		observationMediateur.obtenirNombreObservation();
760
		observationMediateur.obtenirNombreObservation();
743
		
761
		
744
		// et on met à jour la taille de page dans les barres d'outils
762
		// et on met à jour la taille de page dans les barres d'outils
745
		getToolBarVue().selectionnerTaillePage(nouvelleTaillePage);	
763
		getToolBarVue().selectionnerTaillePage(nouvelleTaillePage);	
746
	}
764
	}
747
 
765
 
748
	
766
	
749
	/**
767
	/**
750
	 * Met à jour les barre d'outils avec des nouvelles valeurs
768
	 * Met à jour les barre d'outils avec des nouvelles valeurs
751
	 * @param pageMax le nombre de pages
769
	 * @param pageMax le nombre de pages
752
	 * @param pageEncours la page en cours
770
	 * @param pageEncours la page en cours
753
	 * @param taillePage la taille de page
771
	 * @param taillePage la taille de page
754
	 * @param nbElement le nombre d'élements par page
772
	 * @param nbElement le nombre d'élements par page
755
	 */
773
	 */
756
	public void changerPageMaxEtCourante(int pageMax, int pageEncours, int taillePage, int nbElement) {			
774
	public void changerPageMaxEtCourante(int pageMax, int pageEncours, int taillePage, int nbElement) {			
757
		int[] pages = {pageMax,pageEncours, taillePage, nbElement} ;
775
		int[] pages = {pageMax,pageEncours, taillePage, nbElement} ;
758
		getToolBarVue().rafraichir(pages, false) ;
776
		getToolBarVue().rafraichir(pages, false) ;
759
	}
777
	}
760
	
778
	
761
	/**
779
	/**
762
	 * Renvoie la taille de page en cours d'utilisation
780
	 * Renvoie la taille de page en cours d'utilisation
763
	 * @return la taille de page
781
	 * @return la taille de page
764
	 */
782
	 */
765
	public int getTaillePage() {
783
	public int getTaillePage() {
766
		
784
		
767
		return taillePage;
785
		return taillePage;
768
	}
786
	}
769
	
787
	
770
	/**
788
	/**
771
	 * Renvoie le numéro de la page encours (attention on commence à 0)
789
	 * Renvoie le numéro de la page encours (attention on commence à 0)
772
	 * @return le numéro de la page en cours
790
	 * @return le numéro de la page en cours
773
	 */
791
	 */
774
	public int getPageEncours() {
792
	public int getPageEncours() {
775
		
793
		
776
		return pageEncours;
794
		return pageEncours;
777
	}
795
	}
778
	
796
	
779
	public void afficherFiltres(String[][] filtresEnCours) {
797
	public void afficherFiltres(String[][] filtresEnCours) {
780
		
798
		
781
		String texteFiltresEnCours = "";
799
		String texteFiltresEnCours = "";
782
		
800
		
783
		for(int i = 0; i < filtresEnCours.length; i++) {
801
		for(int i = 0; i < filtresEnCours.length; i++) {
784
			if(Util.filtreValide(filtresEnCours[i])) {
802
			if(Util.filtreValide(filtresEnCours[i])) {
785
				
803
				
786
				if(!texteFiltresEnCours.equals("")) {
804
				if(!texteFiltresEnCours.equals("")) {
787
					texteFiltresEnCours += " - ";
805
					texteFiltresEnCours += " - ";
788
				}
806
				}
789
				
807
				
790
				texteFiltresEnCours += "<span class=\"affichage_filtre\">"+
808
				texteFiltresEnCours += "<span class=\"affichage_filtre\">"+
791
											transformerNomFiltre(filtresEnCours[i][0])+": "+transformerValeurFiltre(filtresEnCours[i][0], filtresEnCours[i][1])+
809
											transformerNomFiltre(filtresEnCours[i][0])+": "+transformerValeurFiltre(filtresEnCours[i][0], filtresEnCours[i][1])+
792
									   " <input value=\"X\" type=\"button\" rel=\""+filtresEnCours[i][0]+"\" id=\"bouton_raz_filtres_obs_"+filtresEnCours[i][0]+"\" />"+
810
									   " <input value=\"X\" type=\"button\" rel=\""+filtresEnCours[i][0]+"\" id=\"bouton_raz_filtres_obs_"+filtresEnCours[i][0]+"\" />"+
793
										"</span>";
811
										"</span>";
794
			}
812
			}
795
		}
813
		}
796
		
814
		
797
		if(!texteFiltresEnCours.equals("")) {
815
		if(!texteFiltresEnCours.equals("")) {
798
			texteFiltresEnCours = "- <span class=\"indicateur_filtres\"> Filtres - "+texteFiltresEnCours+"</span>";
816
			texteFiltresEnCours = "- <span class=\"indicateur_filtres\"> Filtres - "+texteFiltresEnCours+"</span>";
799
		}
817
		}
800
		
818
		
801
		this.setTitle("Observations"+texteFiltresEnCours) ;
819
		this.setTitle("Observations"+texteFiltresEnCours) ;
802
		
820
		
803
		for(int i = 0; i < filtresEnCours.length; i++) {
821
		for(int i = 0; i < filtresEnCours.length; i++) {
804
			
822
			
805
			if(Util.filtreValide(filtresEnCours[i])) {
823
			if(Util.filtreValide(filtresEnCours[i])) {
806
				if(Ext.get("bouton_raz_filtres_obs_"+filtresEnCours[i][0]) != null) {
824
				if(Ext.get("bouton_raz_filtres_obs_"+filtresEnCours[i][0]) != null) {
807
					
825
					
808
					Ext.get("bouton_raz_filtres_obs_"+filtresEnCours[i][0]).addListener("click", new EventCallback() {
826
					Ext.get("bouton_raz_filtres_obs_"+filtresEnCours[i][0]).addListener("click", new EventCallback() {
809
						
827
						
810
						@Override
828
						@Override
811
						public void execute(EventObject e) {
829
						public void execute(EventObject e) {
812
							e.stopEvent();
830
							e.stopEvent();
813
							observationMediateur.viderFiltre(e.getTarget().getAttribute("rel"));
831
							observationMediateur.viderFiltre(e.getTarget().getAttribute("rel"));
814
						}
832
						}
815
						
833
						
816
					});
834
					});
817
				}
835
				}
818
			}
836
			}
819
		}
837
		}
820
	}
838
	}
821
	
839
	
822
	private String transformerNomFiltre(String nomFiltre) {
840
	private String transformerNomFiltre(String nomFiltre) {
823
		
841
		
824
		if(nomFiltre.equals("departement")) {
842
		if(nomFiltre.equals("departement")) {
825
			nomFiltre = "departement";
843
			nomFiltre = "departement";
826
		}
844
		}
827
		
845
		
828
		if(nomFiltre.equals("commune")) {
846
		if(nomFiltre.equals("commune")) {
829
			nomFiltre = "commune";
847
			nomFiltre = "commune";
830
		}
848
		}
831
		
849
		
832
		if(nomFiltre.equals("nom_taxon")) {
850
		if(nomFiltre.equals("nom_taxon")) {
833
			nomFiltre = "recherche";
851
			nomFiltre = "recherche";
834
		}
852
		}
835
		
853
		
836
		if(nomFiltre.equals("id_mots_cles")) {
854
		if(nomFiltre.equals("id_mots_cles")) {
837
			nomFiltre = "projets";
855
			nomFiltre = "projets";
838
		}
856
		}
839
		
857
		
840
		return nomFiltre;
858
		return nomFiltre;
841
		
859
		
842
	}
860
	}
843
	
861
	
844
	private String transformerValeurFiltre(String nomFiltre, String valeurFiltre) {
862
	private String transformerValeurFiltre(String nomFiltre, String valeurFiltre) {
845
		
863
		
846
		String valeurFiltreTransformee = valeurFiltre;
864
		String valeurFiltreTransformee = valeurFiltre;
847
		
865
		
848
		if(nomFiltre.equals("id_mots_cles")) {
866
		if(nomFiltre.equals("id_mots_cles")) {
849
			
867
			
850
			String[] tabMotsCles = valeurFiltre.split(";");
868
			String[] tabMotsCles = valeurFiltre.split(";");
851
			String[] tabMotsClesTexte = observationMediateur.obtenirTexteMotsCles(tabMotsCles);
869
			String[] tabMotsClesTexte = observationMediateur.obtenirTexteMotsCles(tabMotsCles);
852
			
870
			
853
			if(tabMotsClesTexte.length > 1) {
871
			if(tabMotsClesTexte.length > 1) {
854
				valeurFiltreTransformee = Util.implode(",", tabMotsClesTexte);
872
				valeurFiltreTransformee = Util.implode(",", tabMotsClesTexte);
855
			} else {
873
			} else {
856
				valeurFiltreTransformee = tabMotsClesTexte[0];
874
				valeurFiltreTransformee = tabMotsClesTexte[0];
857
			}
875
			}
858
		}
876
		}
859
		
877
		
860
		if(nomFiltre.equals("mois")) {
878
		if(nomFiltre.equals("mois")) {
861
			valeurFiltreTransformee = Util.renvoyerMois(Integer.parseInt(valeurFiltre));
879
			valeurFiltreTransformee = Util.renvoyerMois(Integer.parseInt(valeurFiltre));
862
		}
880
		}
863
		
881
		
864
		valeurFiltreTransformee = valeurFiltreTransformee.replaceAll("000null", "inconnue");
882
		valeurFiltreTransformee = valeurFiltreTransformee.replaceAll("000null", "inconnue");
865
		valeurFiltreTransformee = valeurFiltreTransformee.replaceAll("null", "inconnue");
883
		valeurFiltreTransformee = valeurFiltreTransformee.replaceAll("null", "inconnue");
866
		valeurFiltreTransformee = valeurFiltreTransformee.replaceAll("NULL", "inconnue");
884
		valeurFiltreTransformee = valeurFiltreTransformee.replaceAll("NULL", "inconnue");
867
 
885
 
868
		return valeurFiltreTransformee;
886
		return valeurFiltreTransformee;
869
		
887
		
870
	}
888
	}
871
 
889
 
872
	public void raz() {		
890
	public void raz() {		
873
		RecordDef rd = new RecordDef(getDefinitionChamps());
891
		RecordDef rd = new RecordDef(getDefinitionChamps());
874
		st = new Store(rd);
892
		st = new Store(rd);
875
		// on associe le store
893
		// on associe le store
876
		this.setStore(st);	
894
		this.setStore(st);	
877
	}
895
	}
878
	
896
	
879
	public boolean verifierFormatDate(String date) {
897
	public boolean verifierFormatDate(String date) {
880
		
898
		
881
		String regex = "[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}" ;
899
		String regex = "[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}" ;
882
		if(date.matches(regex) && !date.equals("0000-00-00")) {
900
		if(date.matches(regex) && !date.equals("0000-00-00")) {
883
			return true ;
901
			return true ;
884
		}
902
		}
885
		else {
903
		else {
886
			return false;
904
			return false;
887
		}
905
		}
888
	}
906
	}
889
	
907
	
890
	public boolean getTailleInitialisee() {
908
	public boolean getTailleInitialisee() {
891
		return tailleInitialisee ;
909
		return tailleInitialisee ;
892
	}
910
	}
893
	
911
	
894
	public void setTailleInitialisee() {
912
	public void setTailleInitialisee() {
895
		tailleInitialisee = true;
913
		tailleInitialisee = true;
896
	}
914
	}
897
}
915
}