Subversion Repositories eFlore/Applications.cel

Rev

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

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