Subversion Repositories eFlore/Applications.cel

Rev

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

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