Subversion Repositories eFlore/Applications.cel

Rev

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

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