Subversion Repositories eFlore/Applications.cel

Rev

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

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