Subversion Repositories eFlore/Applications.cel

Rev

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

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