Subversion Repositories eFlore/Applications.cel

Rev

Rev 128 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 128 Rev 129
1
package org.tela_botanica.client.vues;
1
package org.tela_botanica.client.vues;
2
 
2
 
3
 
3
 
4
import java.util.Iterator;
4
import java.util.Iterator;
5
 
5
 
6
import org.tela_botanica.client.modeles.ListeObservation;
6
import org.tela_botanica.client.modeles.ListeObservation;
7
import org.tela_botanica.client.modeles.Observation;
7
import org.tela_botanica.client.modeles.Observation;
8
import org.tela_botanica.client.observation.ObservationMediateur;
8
import org.tela_botanica.client.observation.ObservationMediateur;
9
import org.tela_botanica.client.interfaces.ListePaginable;
9
import org.tela_botanica.client.interfaces.ListePaginable;
10
import org.tela_botanica.client.interfaces.Rafraichissable;
10
import org.tela_botanica.client.interfaces.Rafraichissable;
11
import org.tela_botanica.client.interfaces.VueListable;
11
import org.tela_botanica.client.interfaces.VueListable;
12
import com.gwtext.client.core.EventCallback;
12
import com.gwtext.client.core.EventCallback;
13
import com.gwtext.client.core.EventObject;
13
import com.gwtext.client.core.EventObject;
14
import com.gwtext.client.core.Ext;
14
import com.gwtext.client.core.Ext;
15
import com.gwtext.client.core.ExtElement;
15
import com.gwtext.client.core.ExtElement;
16
import com.gwtext.client.core.Function;
16
import com.gwtext.client.core.Function;
17
import com.gwtext.client.data.ArrayReader;
17
import com.gwtext.client.data.ArrayReader;
18
import com.gwtext.client.data.FieldDef;
18
import com.gwtext.client.data.FieldDef;
19
import com.gwtext.client.data.MemoryProxy;
19
import com.gwtext.client.data.MemoryProxy;
20
import com.gwtext.client.data.Record;
20
import com.gwtext.client.data.Record;
21
import com.gwtext.client.data.RecordDef;
21
import com.gwtext.client.data.RecordDef;
22
import com.gwtext.client.data.Store;
22
import com.gwtext.client.data.Store;
23
import com.gwtext.client.data.StringFieldDef;
23
import com.gwtext.client.data.StringFieldDef;
24
import com.gwtext.client.widgets.Button;
24
import com.gwtext.client.widgets.Button;
25
import com.gwtext.client.widgets.Component;
25
import com.gwtext.client.widgets.Component;
26
import com.gwtext.client.widgets.Tool;
26
import com.gwtext.client.widgets.Tool;
27
import com.gwtext.client.widgets.Toolbar;
27
import com.gwtext.client.widgets.Toolbar;
28
import com.gwtext.client.widgets.ToolbarButton;
28
import com.gwtext.client.widgets.ToolbarButton;
29
import com.gwtext.client.widgets.ToolbarTextItem;
29
import com.gwtext.client.widgets.ToolbarTextItem;
30
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
30
import com.gwtext.client.widgets.event.ButtonListenerAdapter;
31
import com.gwtext.client.widgets.event.PanelListenerAdapter;
31
import com.gwtext.client.widgets.event.PanelListenerAdapter;
32
import com.gwtext.client.widgets.grid.CellMetadata;
32
import com.gwtext.client.widgets.grid.CellMetadata;
33
import com.gwtext.client.widgets.grid.ColumnConfig;
33
import com.gwtext.client.widgets.grid.ColumnConfig;
34
import com.gwtext.client.widgets.grid.ColumnModel;
34
import com.gwtext.client.widgets.grid.ColumnModel;
35
import com.gwtext.client.widgets.grid.GridPanel;
35
import com.gwtext.client.widgets.grid.GridPanel;
36
import com.gwtext.client.widgets.grid.Renderer;
36
import com.gwtext.client.widgets.grid.Renderer;
37
import com.gwtext.client.widgets.grid.event.GridRowListenerAdapter;
37
import com.gwtext.client.widgets.grid.event.GridRowListenerAdapter;
38
 
38
 
39
/**
39
/**
40
 * Liste d'observation composée de ligne d'observation
40
 * Liste d'observation composée de ligne d'observation
41
 * l'interface rafraichissable et l'interface vueListable
41
 * l'interface rafraichissable et l'interface vueListable
42
 * 
42
 * 
43
 * @author David Delon 2008
43
 * @author David Delon 2008
44
 */
44
 */
45
public class ListeObservationVue extends GridPanel implements Rafraichissable,
45
public class ListeObservationVue extends GridPanel implements Rafraichissable,
46
		VueListable, ListePaginable {
46
		VueListable, ListePaginable {
47
 
47
 
48
	/**
48
	/**
49
	 * Le médiateur associé à la vue
49
	 * Le médiateur associé à la vue
50
	 */
50
	 */
51
	private ObservationMediateur	observationMediateur		= null;
51
	private ObservationMediateur	observationMediateur		= null;
52
 
52
 
53
 
53
 
54
	/**
54
	/**
55
	 * Config de colonne
55
	 * Config de colonne
56
	 */
56
	 */
57
	private ColumnConfig	etatObservation;
57
	private ColumnConfig	etatObservation;
58
	/**
58
	/**
59
	 * Config de colonne
59
	 * Config de colonne
60
	 */
60
	 */
61
	private ColumnConfig	nomSaisiObservation;
61
	private ColumnConfig	nomSaisiObservation;
62
	/**
62
	/**
63
	 * Config de colonne
63
	 * Config de colonne
64
	 */
64
	 */
65
	private ColumnConfig	nomRetenuObservation;
65
	private ColumnConfig	nomRetenuObservation;
66
	/**
66
	/**
67
	 * Config de colonne
67
	 * Config de colonne
68
	 */
68
	 */
69
	private ColumnConfig	lieuObservation;
69
	private ColumnConfig	lieuObservation;
70
	/**
70
	/**
71
	 * Config de colonne
71
	 * Config de colonne
72
	 */
72
	 */
73
	private ColumnConfig	dateObservation;
73
	private ColumnConfig	dateObservation;
74
	/**
74
	/**
75
	 * Config de colonne
75
	 * Config de colonne
76
	 */
76
	 */
77
	private ColumnConfig	ordreObservation;
77
	private ColumnConfig	ordreObservation;
78
	/**
78
	/**
79
	 * Modele de colonnes
79
	 * Modele de colonnes
80
	 */
80
	 */
81
	private ColumnModel		modeleColonnes;
81
	private ColumnModel		modeleColonnes;
82
 
82
 
83
	
83
	
84
	/**
84
	/**
85
	 * Store qui contient les données à afficher
85
	 * Store qui contient les données à afficher
86
	 */
86
	 */
87
	private Store			st				= null;
87
	private Store			st				= null;
88
	
88
	
89
	
89
	
90
	/**
90
	/**
91
	 * Barre de pagination
91
	 * Barre de pagination
92
	 */
92
	 */
93
	private BarrePaginationVue bt = null ;
93
	private BarrePaginationVue bt = null ;
94
 
94
 
95
	/**
95
	/**
96
	 * Numéro de page en cours
96
	 * Numéro de page en cours
97
	 */
97
	 */
98
	private int pageEncours = 0 ;
98
	private int pageEncours = 0 ;
99
	/**
99
	/**
100
	 * Nombre de pages totales
100
	 * Nombre de pages totales
101
	 */
101
	 */
102
	private int pageMax = 1 ;
102
	private int pageMax = 1 ;
103
	/**
103
	/**
104
	 * Taille de page (par défaut 20)
104
	 * Taille de page (par défaut 20)
105
	 */
105
	 */
106
	private int taillePage = 20 ;
106
	private int taillePage = 20 ;
107
	/**
107
	/**
108
	 * Nombre d'éléments total correspondant à la requete
108
	 * Nombre d'éléments total correspondant à la requete
109
	 */
109
	 */
110
	private int nbElements = 0 ;
110
	private int nbElements = 0 ;
111
	
111
	
112
	private ListeObservation cacheListeObservation = null;
112
	private ListeObservation cacheListeObservation = null;
113
	
113
	
114
	private Tool exporterObservations = null ;
114
	private Tool exporterObservations = null ;
115
	
115
	
116
	/**
116
	/**
117
	 * Constructeur sans arguments (privé car ne doit pas être utilisé)
117
	 * Constructeur sans arguments (privé car ne doit pas être utilisé)
118
	 */
118
	 */
119
	@SuppressWarnings("unused")
119
	@SuppressWarnings("unused")
120
	private ListeObservationVue()
120
	private ListeObservationVue()
121
	{
121
	{
122
		super() ;
122
		super() ;
123
	}
123
	}
124
	
124
	
125
	/**
125
	/**
126
	 * Constructeur avec argument
126
	 * Constructeur avec argument
127
	 * @param im le médiateur à associer
127
	 * @param im le médiateur à associer
128
	 */
128
	 */
129
	public ListeObservationVue(ObservationMediateur obs) {		
129
	public ListeObservationVue(ObservationMediateur obs) {		
130
		
130
		
131
		this.observationMediateur = obs;
131
		this.observationMediateur = obs;
132
		
132
		
133
		setHeader(true);
133
		setHeader(true);
134
		
134
		
135
        
135
        
136
		// on place la barre de pagination
136
		// on place la barre de pagination
137
		bt = new BarrePaginationVue(this);		
137
		bt = new BarrePaginationVue(this);		
138
		bt.setLabelElement("Observations");
138
		bt.setLabelElement("Observations");
139
		bt.setTaillePageParDefaut(20);
139
		bt.setTaillePageParDefaut(20);
140
		bt.setIntervallesPages(new String[] {"400","200",  "100" , "50" , "20", "10"}) ;
140
		bt.setIntervallesPages(new String[] {"400","200",  "100" , "50" , "20", "10"}) ;
141
		this.setTopToolbar(bt) ;
141
		this.setTopToolbar(bt) ;
142
		
142
		
143
		Toolbar barreActions = new Toolbar();
143
		Toolbar barreActions = new Toolbar();
144
		ToolbarButton transmettre = new ToolbarButton("Transmettre");
144
		ToolbarButton transmettre = new ToolbarButton("Transmettre");
145
		transmettre.addListener(new ButtonListenerAdapter() {
145
		transmettre.addListener(new ButtonListenerAdapter() {
146
			public void onClick(Button b, EventObject e) {
146
			public void onClick(Button b, EventObject e) {
147
				observationMediateur.transmettreObservations();
147
				observationMediateur.transmettreObservations();
148
			}
148
			}
149
		});
149
		});
150
		ToolbarButton supprimer = new ToolbarButton("Supprimer");
150
		ToolbarButton supprimer = new ToolbarButton("Supprimer");
151
		supprimer.addListener(new ButtonListenerAdapter() {
151
		supprimer.addListener(new ButtonListenerAdapter() {
152
			public void onClick(Button b, EventObject e) {
152
			public void onClick(Button b, EventObject e) {
153
				observationMediateur.supprimerObservations();
153
				observationMediateur.supprimerObservations();
154
			}
154
			}
155
		});
155
		});
156
		
156
		
157
 
157
 
158
		ToolbarTextItem exporter = new ToolbarTextItem("<a href=\"#\" id=\"lienExport\"> Exporter </a>");
158
		ToolbarTextItem exporter = new ToolbarTextItem("<a href=\"#\" id=\"lienExport\"> Exporter </a>");
159
		
159
		
160
		barreActions.addButton(transmettre);
160
		barreActions.addButton(transmettre);
161
		barreActions.addSpacer();
161
		barreActions.addSpacer();
162
		barreActions.addButton(supprimer);
162
		barreActions.addButton(supprimer);
163
		barreActions.addSpacer();
163
		barreActions.addSpacer();
164
		barreActions.addItem(exporter);
164
		barreActions.addItem(exporter);
165
		
165
		
166
		
166
		
167
		this.setBottomToolbar(barreActions);
167
		this.setBottomToolbar(barreActions);
-
 
168
		
-
 
169
		this.setCollapsible(true);
-
 
170
		this.setTitleCollapse(true);
168
		
171
		
169
		exporterObservations = new Tool(Tool.PIN, new Function() {
172
		/*exporterObservations = new Tool(Tool.PIN, new Function() {
170
 
173
 
171
			public void execute() {
174
			public void execute() {
172
				observationMediateur.exporterObservations() ;				
175
				observationMediateur.exporterObservations() ;				
173
			}
176
			}
174
			
177
			
175
		}, "Exporter des observations") ;
178
		}, "Exporter des observations") ;
176
		
179
		
177
		this.addTool(exporterObservations) ;
180
		this.addTool(exporterObservations) ;
178
		
181
		*/
179
		this.setTitle("Observations") ;
182
		this.setTitle("Observations") ;
180
 
183
 
181
		// on construit le modèle de colonnes
184
		// on construit le modèle de colonnes
182
 
185
 
183
		// Le store suivant est ensuite remplacé par le store contenant les données obtenus depuis le serveur (cf rafraichir) 
186
		// Le store suivant est ensuite remplacé par le store contenant les données obtenus depuis le serveur (cf rafraichir) 
184
				
187
				
185
		Renderer colRend = new Renderer() {
188
		Renderer colRend = new Renderer() {
186
 
189
 
187
			public String render(Object value, CellMetadata cellMetadata,
190
			public String render(Object value, CellMetadata cellMetadata,
188
					Record record, int rowIndex, int colNum, Store store) {
191
					Record record, int rowIndex, int colNum, Store store) {
189
				
192
				
190
				if(value == null || value.equals("null") || value.equals("000null") || value.equals("0000-00-00 00:00:00")) {
193
				if(value == null || value.equals("null") || value.equals("000null") || value.equals("0000-00-00 00:00:00")) {
191
				
194
				
192
					return "" ;
195
					return "" ;
193
				}	
196
				}	
194
				else
197
				else
195
				{
198
				{
196
					
199
					
197
				}
200
				}
198
				
201
				
199
				return value.toString() ;
202
				return value.toString() ;
200
			}
203
			}
201
			
204
			
202
		} ;
205
		} ;
203
		
206
		
204
		etatObservation = new ColumnConfig("Transmis", "etat_observation", 20, true, new Renderer() {
207
		etatObservation = new ColumnConfig("Transmis", "etat_observation", 20, true, new Renderer() {
205
 
208
 
206
			public String render(Object value, CellMetadata cellMetadata,
209
			public String render(Object value, CellMetadata cellMetadata,
207
					Record record, int rowIndex, int colNum, Store store) {
210
					Record record, int rowIndex, int colNum, Store store) {
208
				if(value.equals("1"))
211
				if(value.equals("1"))
209
				{
212
				{
210
					return "<img src=\"tela.png\"/></img>" ;
213
					return "<img src=\"tela.png\"/></img>" ;
211
				}
214
				}
212
				else
215
				else
213
				{
216
				{
214
					return "" ;
217
					return "" ;
215
				}
218
				}
216
			}
219
			}
217
			
220
			
218
		});		
221
		});		
219
		nomSaisiObservation = new ColumnConfig("Nom saisi", "nomSaisi_observation", 200, true, colRend);
222
		nomSaisiObservation = new ColumnConfig("Nom saisi", "nomSaisi_observation", 200, true, colRend);
220
		nomRetenuObservation = new ColumnConfig("Nom retenu", "nomRetenu_observation", 200, true, colRend);
223
		nomRetenuObservation = new ColumnConfig("Nom retenu", "nomRetenu_observation", 200, true, colRend);
221
		lieuObservation = new ColumnConfig("Lieu", "lieu_observation", 200, true, colRend);
224
		lieuObservation = new ColumnConfig("Lieu", "lieu_observation", 200, true, colRend);
222
		dateObservation = new ColumnConfig("Date", "date_observation", 120, true, colRend);
225
		dateObservation = new ColumnConfig("Date", "date_observation", 120, true, colRend);
223
		ordreObservation = new ColumnConfig("Ordre", "ordre_observation", 50, true, colRend);
226
		ordreObservation = new ColumnConfig("Ordre", "ordre_observation", 50, true, colRend);
224
			
227
			
225
	
228
	
226
		// on associe le modèle de colonnes
229
		// on associe le modèle de colonnes
227
		
230
		
228
		ColumnConfig[] cm = {etatObservation, nomSaisiObservation, nomRetenuObservation, lieuObservation, dateObservation, ordreObservation};
231
		ColumnConfig[] cm = {etatObservation, nomSaisiObservation, nomRetenuObservation, lieuObservation, dateObservation, ordreObservation};
229
		
232
		
230
		modeleColonnes = new ColumnModel(cm);
233
		modeleColonnes = new ColumnModel(cm);
231
		
234
		
232
		this.setColumnModel(modeleColonnes);
235
		this.setColumnModel(modeleColonnes);
233
		
236
		
234
		this.setAutoScroll(true);
237
		this.setAutoScroll(true);
235
		this.setEnableColumnResize(true);
238
		this.setEnableColumnResize(true);
236
		
239
		
237
		//temp dd viewport desactive ajout de ces 2 lignes
240
		//temp dd viewport desactive ajout de ces 2 lignes
238
	//	this.setAutoWidth(true);
241
	//	this.setAutoWidth(true);
239
		// temp
242
		// temp
240
		
243
		
241
		// creation du store
244
		// creation du store
242
 
245
 
243
		FieldDef defEtatObservation = new StringFieldDef("etat_observation");
246
		FieldDef defEtatObservation = new StringFieldDef("etat_observation");
244
		FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
247
		FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
245
		FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
248
		FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
246
		FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
249
		FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
247
		FieldDef defDateObservation = new StringFieldDef("date_observation");
250
		FieldDef defDateObservation = new StringFieldDef("date_observation");
248
		FieldDef defOrdreObservation = new StringFieldDef("ordre_observation");
251
		FieldDef defOrdreObservation = new StringFieldDef("ordre_observation");
249
		
252
		
250
		
253
		
251
		FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation,
254
		FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation,
252
				defLieuObservation, defDateObservation, defOrdreObservation };
255
				defLieuObservation, defDateObservation, defOrdreObservation };
253
		
256
		
254
		RecordDef rd = new RecordDef(defTab);
257
		RecordDef rd = new RecordDef(defTab);
255
		st = new Store(rd);
258
		st = new Store(rd);
256
		
259
		
257
		// on associe le store
260
		// on associe le store
258
		
261
		
259
		this.setStore(st);
262
		this.setStore(st);
260
		this.getView().setAutoFill(true);
263
		this.getView().setAutoFill(true);
261
		this.getView().setForceFit(true) ;
264
		this.getView().setForceFit(true) ;
262
		
265
		
263
		// on crée un masque de chargement qui s'affichera lors des mises à jour
266
		// on crée un masque de chargement qui s'affichera lors des mises à jour
264
		this.setLoadMask("Chargement");
267
		this.setLoadMask("Chargement");
265
	
268
	
266
		// on ajoute les listeners
269
		// on ajoute les listeners
267
		ajouterListeners();
270
		ajouterListeners();
268
		
271
		
269
		
272
		
270
	}
273
	}
271
 
274
 
272
 
275
 
273
	/**
276
	/**
274
	 * Ajoute les listeners pour la gestion des évènements
277
	 * Ajoute les listeners pour la gestion des évènements
275
	 */
278
	 */
276
	private void ajouterListeners() {
279
	private void ajouterListeners() {
277
		
280
		
278
		this.addGridRowListener(new GridRowListenerAdapter() {
281
		this.addGridRowListener(new GridRowListenerAdapter() {
279
			
282
			
280
			// gestion du clic sur une ligne
283
			// gestion du clic sur une ligne
281
			public void onRowClick(GridPanel grid, int rowIndex,
284
			public void onRowClick(GridPanel grid, int rowIndex,
282
					EventObject e) {
285
					EventObject e) {
283
				// on notifie le médiateur et on lui passe le nuémro de ligne
286
				// on notifie le médiateur et on lui passe le nuémro de ligne
284
				Record rd = getSelectionModel().getSelected();
287
				Record rd = getSelectionModel().getSelected();
285
				String ordreObservation = rd.getAsString("ordre_observation") ;
288
				String ordreObservation = rd.getAsString("ordre_observation") ;
286
				observationMediateur.onClicListeObservation(rowIndex,ordreObservation);
289
				observationMediateur.onClicListeObservation(rowIndex,ordreObservation);
287
				
290
				
288
			}
291
			}
289
 
292
 
290
			// gestion du clic droit
293
			// gestion du clic droit
291
			public void onRowContextMenu(GridPanel grid, int rowIndex,
294
			public void onRowContextMenu(GridPanel grid, int rowIndex,
292
					EventObject e) {
295
					EventObject e) {
293
				// on stoppe l'évenement pour empecher le navigateur d'afficher son propre menu
296
				// on stoppe l'évenement pour empecher le navigateur d'afficher son propre menu
294
				e.stopEvent() ;
297
				e.stopEvent() ;
295
				// on notifie le médiateur en lui passant l'évenement
298
				// on notifie le médiateur en lui passant l'évenement
296
				observationMediateur.montrerContextMenu(e);
299
				observationMediateur.montrerContextMenu(e);
297
			}
300
			}
298
 
301
 
299
			// gestion du double clic
302
			// gestion du double clic
300
			public void onRowDblClick(GridPanel grid, int rowIndex,
303
			public void onRowDblClick(GridPanel grid, int rowIndex,
301
					EventObject e) {
304
					EventObject e) {
302
				// on notifie le médiateur en lui passant le numéro de ligne
305
				// on notifie le médiateur en lui passant le numéro de ligne
303
				observationMediateur.doubleClicListeObservation(rowIndex);
306
				observationMediateur.doubleClicListeObservation(rowIndex);
304
			}
307
			}
305
			
308
			
306
		});
309
		});
307
		
310
		
308
		this.addListener(new PanelListenerAdapter() {
311
		this.addListener(new PanelListenerAdapter() {
309
			public void onRender(Component c) {
312
			public void onRender(Component c) {
310
				
313
				
311
				ExtElement lienExport = Ext.get("lienExport") ;
314
				ExtElement lienExport = Ext.get("lienExport") ;
312
				lienExport.addListener("click", new EventCallback() {
315
				lienExport.addListener("click", new EventCallback() {
313
 
316
 
314
					public void execute(EventObject e) {
317
					public void execute(EventObject e) {
315
						
318
						
316
						observationMediateur.exporterObservations();
319
						observationMediateur.exporterObservations();
317
					}
320
					}
318
					
321
					
319
				});
322
				});
320
			}
323
			}
321
		});
324
		});
322
	}
325
	}
323
 
326
 
324
	/**
327
	/**
325
	 * Méthode héritée de l'interface VueListable
328
	 * Méthode héritée de l'interface VueListable
326
	 * Sélectionne les observations  dans la liste suivant les identifiants donnés en paramètres
329
	 * Sélectionne les observations  dans la liste suivant les identifiants donnés en paramètres
327
	 */
330
	 */
328
	
331
	
329
	public String[] getIdSelectionnees() {
332
	public String[] getIdSelectionnees() {
330
		
333
		
331
		Record[] selection = this.getSelectionModel().getSelections();
334
		Record[] selection = this.getSelectionModel().getSelections();
332
		int taille = selection.length;
335
		int taille = selection.length;
333
		String id_selection[] = new String[taille];
336
		String id_selection[] = new String[taille];
334
 
337
 
335
		for (int i = 0; i < selection.length; i++) {
338
		for (int i = 0; i < selection.length; i++) {
336
 
339
 
337
			id_selection[i] = selection[i].getAsString("ordre_observation");
340
			id_selection[i] = selection[i].getAsString("ordre_observation");
338
		}
341
		}
339
 
342
 
340
		return id_selection;
343
		return id_selection;
341
	}
344
	}
342
	
345
	
343
 
346
 
344
	
347
	
345
	/**
348
	/**
346
	 * Sélectionne des enregistrements donné 
349
	 * Sélectionne des enregistrements donné 
347
	 * @param sel un tableau d'enregistrement à selectionner
350
	 * @param sel un tableau d'enregistrement à selectionner
348
	 */
351
	 */
349
	public void selectionnerEnregistrements(Record[] sel) {
352
	public void selectionnerEnregistrements(Record[] sel) {
350
 
353
 
351
			getSelectionModel().clearSelections();
354
			getSelectionModel().clearSelections();
352
			getSelectionModel().selectRecords(sel);
355
			getSelectionModel().selectRecords(sel);
353
		
356
		
354
	}
357
	}
355
	
358
	
356
	/**
359
	/**
357
	 * Accesseur pour la toolbar de pagination
360
	 * Accesseur pour la toolbar de pagination
358
	 * @return la toolbar de pagination
361
	 * @return la toolbar de pagination
359
	 */
362
	 */
360
	
363
	
361
	public BarrePaginationVue getToolBarVue()
364
	public BarrePaginationVue getToolBarVue()
362
	{
365
	{
363
		return bt ;
366
		return bt ;
364
	}
367
	}
365
 
368
 
366
 
369
 
367
	/**
370
	/**
368
	 * Recherche l'élement actuellement affiché et affiche son message de chargement
371
	 * Recherche l'élement actuellement affiché et affiche son message de chargement
369
	 */
372
	 */
370
	public void masquerChargement()
373
	public void masquerChargement()
371
	{
374
	{
372
			ExtElement masked = Ext.get(getId()) ;
375
			ExtElement masked = Ext.get(getId()) ;
373
 
376
 
374
 
377
 
375
			if (masked!=null) {
378
			if (masked!=null) {
376
				masked.mask("Chargement") ;
379
				masked.mask("Chargement") ;
377
			}
380
			}
378
 
381
 
379
	}
382
	}
380
	
383
	
381
	/**
384
	/**
382
	 * Recherche l'élement actuellement affiché et retire son message de chargement si l'était affiché
385
	 * Recherche l'élement actuellement affiché et retire son message de chargement si l'était affiché
383
	 */
386
	 */
384
	public void demasquerChargement()
387
	public void demasquerChargement()
385
	{
388
	{
386
			ExtElement masked = Ext.get(getId()) ;
389
			ExtElement masked = Ext.get(getId()) ;
387
			
390
			
388
 
391
 
389
			if (masked!=null) {
392
			if (masked!=null) {
390
				
393
				
391
				if(masked.isMasked())
394
				if(masked.isMasked())
392
				{
395
				{
393
					masked.unmask() ;
396
					masked.unmask() ;
394
				}
397
				}
395
			}
398
			}
396
	}
399
	}
397
	
400
	
398
 
401
 
399
 
402
 
400
	/**
403
	/**
401
	 * Méthode héritée de l'interface rafraichissable
404
	 * Méthode héritée de l'interface rafraichissable
402
	 * @param nouvelleDonnees les nouvelles données
405
	 * @param nouvelleDonnees les nouvelles données
403
	 * @param repandreRafraichissement le booleen de notification du rafraichissement
406
	 * @param repandreRafraichissement le booleen de notification du rafraichissement
404
	 */
407
	 */
405
	
408
	
406
 
409
 
407
 
410
 
408
	public void rafraichir(Object nouvelleDonnees, boolean repandreRafraichissement) {
411
	public void rafraichir(Object nouvelleDonnees, boolean repandreRafraichissement) {
409
	
412
	
410
	
413
	
411
	
414
	
412
		
415
		
413
//		 si l'on a reçu une liste d'observation
416
//		 si l'on a reçu une liste d'observation
414
		if(nouvelleDonnees instanceof ListeObservation)
417
		if(nouvelleDonnees instanceof ListeObservation)
415
		{
418
		{
416
			
419
			
417
				ListeObservation data = (ListeObservation) nouvelleDonnees ;
420
				ListeObservation data = (ListeObservation) nouvelleDonnees ;
418
				Object[][] observationData = new Object[data.size()][7];
421
				Object[][] observationData = new Object[data.size()][7];
419
				int i = 0 ;
422
				int i = 0 ;
420
				
423
				
421
				if(data.size() == 0)
424
				if(data.size() == 0)
422
				{
425
				{
423
					pageEncours = 0 ;
426
					pageEncours = 0 ;
424
				}
427
				}
425
				
428
				
426
				// on la parse et on récupère les informations qui nous interessent
429
				// on la parse et on récupère les informations qui nous interessent
427
				for (Iterator it = data.keySet().iterator(); it.hasNext();) 
430
				for (Iterator it = data.keySet().iterator(); it.hasNext();) 
428
				{
431
				{
429
					
432
					
430
					Observation obs=(Observation) data.get(it.next());
433
					Observation obs=(Observation) data.get(it.next());
431
					
434
					
432
					observationData[i][0]= obs.getTransmis();
435
					observationData[i][0]= obs.getTransmis();
433
					observationData[i][1]= obs.getNomSaisi();
436
					observationData[i][1]= obs.getNomSaisi();
434
					observationData[i][2]= obs.getNomRetenu();
437
					observationData[i][2]= obs.getNomRetenu();
435
					observationData[i][3]= obs.getLieudit();
438
					observationData[i][3]= obs.getLieudit();
436
					observationData[i][4]= obs.getDate();
439
					observationData[i][4]= obs.getDate();
437
					observationData[i][5]= obs.getNumeroOrdre();		
440
					observationData[i][5]= obs.getNumeroOrdre();		
438
					observationData[i][6]= obs.getNumeroNomenclaturalSaisi();
441
					observationData[i][6]= obs.getNumeroNomenclaturalSaisi();
439
									
442
									
440
				
443
				
441
					i++ ;
444
					i++ ;
442
				}
445
				}
443
		
446
		
444
				// creation du store qui les contient
447
				// creation du store qui les contient
445
				
448
				
446
				FieldDef defEtatObservation = new StringFieldDef("etat_observation");
449
				FieldDef defEtatObservation = new StringFieldDef("etat_observation");
447
				FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
450
				FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
448
				FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
451
				FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
449
				FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
452
				FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
450
				FieldDef defDateObservation = new StringFieldDef("date_observation");
453
				FieldDef defDateObservation = new StringFieldDef("date_observation");
451
				FieldDef defOrdreObservation = new StringFieldDef("ordre_observation");
454
				FieldDef defOrdreObservation = new StringFieldDef("ordre_observation");
452
				
455
				
453
				// Non affiches :
456
				// Non affiches :
454
				FieldDef defNumeroNomenclaturalSaisiObservation = new StringFieldDef("numeroNomenclaturalSaisi_observation");
457
				FieldDef defNumeroNomenclaturalSaisiObservation = new StringFieldDef("numeroNomenclaturalSaisi_observation");
455
				
458
				
456
				
459
				
457
				// on associe le store
460
				// on associe le store
458
 
461
 
459
				FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation,
462
				FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation,
460
						defLieuObservation, defDateObservation, defOrdreObservation, defNumeroNomenclaturalSaisiObservation };
463
						defLieuObservation, defDateObservation, defOrdreObservation, defNumeroNomenclaturalSaisiObservation };
461
				
464
				
462
				RecordDef rd = new RecordDef(defTab);
465
				RecordDef rd = new RecordDef(defTab);
463
				
466
				
464
				final MemoryProxy dataProxy = new MemoryProxy(observationData);
467
				final MemoryProxy dataProxy = new MemoryProxy(observationData);
465
				final ArrayReader reader = new ArrayReader(rd);
468
				final ArrayReader reader = new ArrayReader(rd);
466
		
469
		
467
				final Store observationStore = new Store(dataProxy, reader);
470
				final Store observationStore = new Store(dataProxy, reader);
468
				
471
				
469
				
472
				
470
				st = observationStore ;
473
				st = observationStore ;
471
				st.load() ;
474
				st.load() ;
472
				
475
				
473
				
476
				
474
				// et on reconfigure et rafraichit la vue
477
				// et on reconfigure et rafraichit la vue
475
				this.reconfigure(st, this.getColumnModel());
478
				this.reconfigure(st, this.getColumnModel());
476
				
479
				
477
				demasquerChargement();
480
				demasquerChargement();
478
				
481
				
479
			    cacheListeObservation=data;
482
			    cacheListeObservation=data;
480
			    
483
			    
481
				observationMediateur.onRafraichissementListeObservations();
484
				observationMediateur.onRafraichissementListeObservations();
482
				
485
				
483
				
486
				
484
		}
487
		}
485
		
488
		
486
		
489
		
487
		// Si on reçoit un tableau d'entiers
490
		// Si on reçoit un tableau d'entiers
488
		// c'est un tableau d'un seul entier qui est le nombre d'observation correspondant aux critères
491
		// c'est un tableau d'un seul entier qui est le nombre d'observation correspondant aux critères
489
		if(nouvelleDonnees instanceof int[])
492
		if(nouvelleDonnees instanceof int[])
490
		{
493
		{
491
			int[] pages = (int[])nouvelleDonnees ;
494
			int[] pages = (int[])nouvelleDonnees ;
492
			
495
			
493
			// on calcule le nombre de pages nécessaires et on les met à jour dans le modèle
496
			// on calcule le nombre de pages nécessaires et on les met à jour dans le modèle
494
			pageMax  = calculerNbPages(pages[0]) ;
497
			pageMax  = calculerNbPages(pages[0]) ;
495
			nbElements = pages[0] ;
498
			nbElements = pages[0] ;
496
			
499
			
497
			
500
			
498
			// et on notifie de le mediateur du changement des valeurs
501
			// et on notifie de le mediateur du changement des valeurs
499
			changerPageMaxEtCourante(pageMax,pageEncours,taillePage,pages[0]) ;
502
			changerPageMaxEtCourante(pageMax,pageEncours,taillePage,pages[0]) ;
500
			
503
			
501
			masquerChargement();
504
			masquerChargement();
502
			observationMediateur.obtenirListeObservation(this);
505
			observationMediateur.obtenirListeObservation(this);
503
		}
506
		}
504
		
507
		
505
		
508
		
506
//		 si l'on a reçu une Observation 
509
//		 si l'on a reçu une Observation 
507
		
510
		
508
		if(nouvelleDonnees instanceof Observation) {
511
		if(nouvelleDonnees instanceof Observation) {
509
		
512
		
510
			Observation obs= (Observation) nouvelleDonnees;
513
			Observation obs= (Observation) nouvelleDonnees;
511
			if (obs.getNumeroOrdre()==null) { // Nouvelle observation
514
			if (obs.getNumeroOrdre()==null) { // Nouvelle observation
512
			// On affiche la dernière page
515
			// On affiche la dernière page
513
			
516
			
514
			pageEncours = pageMax ;
517
			pageEncours = pageMax ;
515
			masquerChargement();
518
			masquerChargement();
516
 
519
 
517
			observationMediateur.obtenirNombreObservation();
520
			observationMediateur.obtenirNombreObservation();
518
			
521
			
519
			}
522
			}
520
			else { // Modification d'une observation
523
			else { // Modification d'une observation
521
				
524
				
522
				
525
				
523
				masquerChargement();
526
				masquerChargement();
524
 
527
 
525
				observationMediateur.obtenirNombreObservation();		
528
				observationMediateur.obtenirNombreObservation();		
526
				
529
				
527
			}
530
			}
528
		}
531
		}
529
		
532
		
530
		// Si on a effectué une suppression
533
		// Si on a effectué une suppression
531
		if(nouvelleDonnees instanceof String)
534
		if(nouvelleDonnees instanceof String)
532
		{
535
		{
533
			String str = (String)nouvelleDonnees ;
536
			String str = (String)nouvelleDonnees ;
534
			observationMediateur.obtenirNombreObservation() ;
537
			observationMediateur.obtenirNombreObservation() ;
535
		}
538
		}
536
		
539
		
537
	}
540
	}
538
	
541
	
539
	
542
	
540
	// GESTION DE LA PAGINATION
543
	// GESTION DE LA PAGINATION
541
 
544
 
542
	
545
	
543
	public ListeObservation getCacheListeObservation() {
546
	public ListeObservation getCacheListeObservation() {
544
		return cacheListeObservation;
547
		return cacheListeObservation;
545
	}
548
	}
546
 
549
 
547
	/**
550
	/**
548
	 * Calcule le nombre de pages nécessaires pour afficher un nombre d'élements donnés en fonction de la taille de page
551
	 * Calcule le nombre de pages nécessaires pour afficher un nombre d'élements donnés en fonction de la taille de page
549
	 * en cours
552
	 * en cours
550
	 * @param nbElements le nombre d'élements total
553
	 * @param nbElements le nombre d'élements total
551
	 * @return le nombre de pages 
554
	 * @return le nombre de pages 
552
	 */
555
	 */
553
	public int calculerNbPages(int nbElements)
556
	public int calculerNbPages(int nbElements)
554
	{
557
	{
555
		// A cause de la betise de java pour les conversion implicite on fait quelques conversions manuellement
558
		// A cause de la betise de java pour les conversion implicite on fait quelques conversions manuellement
556
		// pour eviter qu'il arrondisse mal la division
559
		// pour eviter qu'il arrondisse mal la division
557
		// nombre de pages = (nombre d'element / taille de la page) arrondie à l'entier superieur
560
		// nombre de pages = (nombre d'element / taille de la page) arrondie à l'entier superieur
558
		
561
		
559
		double nPage = (1.0*nbElements)/(1.0*taillePage) ; 
562
		double nPage = (1.0*nbElements)/(1.0*taillePage) ; 
560
		double nPageRound = Math.ceil(nPage) ;
563
		double nPageRound = Math.ceil(nPage) ;
561
		Double nPageInt = new Double(nPageRound) ;
564
		Double nPageInt = new Double(nPageRound) ;
562
		
565
		
563
		// on convertit en entier
566
		// on convertit en entier
564
		return nPageInt.intValue() ; 
567
		return nPageInt.intValue() ; 
565
	}
568
	}
566
 
569
 
567
	
570
	
568
	/**
571
	/**
569
	 * Recalcule la page en cours lors du changement du nombre d'élements
572
	 * Recalcule la page en cours lors du changement du nombre d'élements
570
	 * @param nbElements le nombre d'élements total
573
	 * @param nbElements le nombre d'élements total
571
	 * @return la nouvelle page encours
574
	 * @return la nouvelle page encours
572
	 */
575
	 */
573
	public int calculerPageCourante(int nbElements)
576
	public int calculerPageCourante(int nbElements)
574
	{
577
	{
575
		// on calcule le nombre de page
578
		// on calcule le nombre de page
576
		int nouvelNbPages = calculerNbPages(nbElements) ;
579
		int nouvelNbPages = calculerNbPages(nbElements) ;
577
		// la nouvelle page en cours
580
		// la nouvelle page en cours
578
		double nPageCourante = (1.0*pageEncours)/(1.0*pageMax) * (1.0*nouvelNbPages) ;
581
		double nPageCourante = (1.0*pageEncours)/(1.0*pageMax) * (1.0*nouvelNbPages) ;
579
		
582
		
580
		// on arrondit au supérieur
583
		// on arrondit au supérieur
581
		double nPageRound = Math.ceil(nPageCourante) ;
584
		double nPageRound = Math.ceil(nPageCourante) ;
582
		Double nPageInt = new Double(nPageRound) ;
585
		Double nPageInt = new Double(nPageRound) ;
583
		
586
		
584
		// on convertit en entier
587
		// on convertit en entier
585
		return Math.abs(nPageInt.intValue()) ; 
588
		return Math.abs(nPageInt.intValue()) ; 
586
	}
589
	}
587
	
590
	
588
 
591
 
589
	/**
592
	/**
590
	 * Appelle le modèle pour lui demander les données d'une page à afficher
593
	 * Appelle le modèle pour lui demander les données d'une page à afficher
591
	 * @param pageCourante le numéro de page à affciher
594
	 * @param pageCourante le numéro de page à affciher
592
	 */
595
	 */
593
	public void changerNumeroPage(int pageCourante) {
596
	public void changerNumeroPage(int pageCourante) {
594
		
597
		
595
		
598
		
596
		
599
		
597
		pageEncours = pageCourante ;
600
		pageEncours = pageCourante ;
598
		
601
		
599
		masquerChargement();
602
		masquerChargement();
600
 
603
 
601
		// On lance le chargerment des observations
604
		// On lance le chargerment des observations
602
		observationMediateur.obtenirNombreObservation();
605
		observationMediateur.obtenirNombreObservation();
603
		
606
		
604
		getToolBarVue().changerPageCourante(pageCourante);
607
		getToolBarVue().changerPageCourante(pageCourante);
605
		
608
		
606
	}
609
	}
607
	
610
	
608
	
611
	
609
	/**
612
	/**
610
	 * Appelle le modèle pour qu'il change la taille de page utilisée
613
	 * Appelle le modèle pour qu'il change la taille de page utilisée
611
	 * @param nouvelleTaillePage la nouvelle taille de page
614
	 * @param nouvelleTaillePage la nouvelle taille de page
612
	 */
615
	 */
613
	
616
	
614
	public void changerTaillePage(int nouvelleTaillePage)
617
	public void changerTaillePage(int nouvelleTaillePage)
615
	{
618
	{
616
	
619
	
617
		taillePage = nouvelleTaillePage ;
620
		taillePage = nouvelleTaillePage ;
618
		pageEncours = calculerPageCourante(nbElements) ;
621
		pageEncours = calculerPageCourante(nbElements) ;
619
 
622
 
620
		masquerChargement();
623
		masquerChargement();
621
 
624
 
622
		// 	On lance le chargement des observations
625
		// 	On lance le chargement des observations
623
		observationMediateur.obtenirNombreObservation();
626
		observationMediateur.obtenirNombreObservation();
624
		
627
		
625
		
628
		
626
		// et on met à jour la taille de page dans les barres d'outils
629
		// et on met à jour la taille de page dans les barres d'outils
627
		getToolBarVue().selectionnerTaillePage(nouvelleTaillePage);
630
		getToolBarVue().selectionnerTaillePage(nouvelleTaillePage);
628
		
631
		
629
		
632
		
630
	}
633
	}
631
 
634
 
632
	
635
	
633
	/**
636
	/**
634
	 * Met à jour les barre d'outils avec des nouvelles valeurs
637
	 * Met à jour les barre d'outils avec des nouvelles valeurs
635
	 * @param pageMax le nombre de pages
638
	 * @param pageMax le nombre de pages
636
	 * @param pageEncours la page en cours
639
	 * @param pageEncours la page en cours
637
	 * @param taillePage la taille de page
640
	 * @param taillePage la taille de page
638
	 * @param nbElement le nombre d'élements par page
641
	 * @param nbElement le nombre d'élements par page
639
	 */
642
	 */
640
	public void changerPageMaxEtCourante(int pageMax, int pageEncours, int taillePage, int nbElement) 
643
	public void changerPageMaxEtCourante(int pageMax, int pageEncours, int taillePage, int nbElement) 
641
	{
644
	{
642
				
645
				
643
		int[] pages = {pageMax,pageEncours, taillePage, nbElement} ;
646
		int[] pages = {pageMax,pageEncours, taillePage, nbElement} ;
644
		getToolBarVue().rafraichir(pages, false) ;
647
		getToolBarVue().rafraichir(pages, false) ;
645
		
648
		
646
	}
649
	}
647
	
650
	
648
	/**
651
	/**
649
	 * Renvoie la taille de page en cours d'utilisation
652
	 * Renvoie la taille de page en cours d'utilisation
650
	 * @return la taille de page
653
	 * @return la taille de page
651
	 */
654
	 */
652
	public int getTaillePage() {
655
	public int getTaillePage() {
653
		
656
		
654
		return taillePage;
657
		return taillePage;
655
	}
658
	}
656
	
659
	
657
	/**
660
	/**
658
	 * Renvoie le numéro de la page encours (attention on commence à 0)
661
	 * Renvoie le numéro de la page encours (attention on commence à 0)
659
	 * @return le numéro de la page en cours
662
	 * @return le numéro de la page en cours
660
	 */
663
	 */
661
	public int getPageEncours() {
664
	public int getPageEncours() {
662
		
665
		
663
		return pageEncours;
666
		return pageEncours;
664
	}
667
	}
665
	
668
	
666
	public void afficherFiltres(String nLieu, String nDate)
669
	public void afficherFiltres(String nLieu, String nDate)
667
	{
670
	{
668
		
671
		
669
		String titre = "Observations " ;
672
		String titre = "Observations " ;
670
		
673
		
671
		if(!nLieu.equals(""))
674
		if(!nLieu.equals(""))
672
		{
675
		{
673
			titre += "  -  Lieu : "+nLieu ;
676
			titre += "  -  Lieu : "+nLieu ;
674
			
677
			
675
		}
678
		}
676
			
679
			
677
		if(!nDate .equals(""))
680
		if(!nDate .equals(""))
678
		{
681
		{
679
			titre += "  -  Date : "+nDate ;
682
			titre += "  -  Date : "+nDate ;
680
		}
683
		}
681
		
684
		
682
		this.setTitle(titre) ;
685
		this.setTitle(titre) ;
683
	}
686
	}
684
 
687
 
685
	public void raz() {
688
	public void raz() {
686
		
689
		
687
		
690
		
688
		// creation du store qui les contient
691
		// creation du store qui les contient
689
		
692
		
690
		FieldDef defEtatObservation = new StringFieldDef("etat_observation");
693
		FieldDef defEtatObservation = new StringFieldDef("etat_observation");
691
		FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
694
		FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
692
		FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
695
		FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
693
		FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
696
		FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
694
		FieldDef defDateObservation = new StringFieldDef("date_observation");
697
		FieldDef defDateObservation = new StringFieldDef("date_observation");
695
		FieldDef defOrdreObservation = new StringFieldDef("ordre_observation");
698
		FieldDef defOrdreObservation = new StringFieldDef("ordre_observation");
696
		
699
		
697
		// Non affiches :
700
		// Non affiches :
698
		FieldDef defNumeroNomenclaturalSaisiObservation = new StringFieldDef("numeroNomenclaturalSaisi_observation");
701
		FieldDef defNumeroNomenclaturalSaisiObservation = new StringFieldDef("numeroNomenclaturalSaisi_observation");
699
		
702
		
700
		FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation,
703
		FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation,
701
				defLieuObservation, defDateObservation, defOrdreObservation };
704
				defLieuObservation, defDateObservation, defOrdreObservation };
702
		
705
		
703
		RecordDef rd = new RecordDef(defTab);
706
		RecordDef rd = new RecordDef(defTab);
704
		st = new Store(rd);
707
		st = new Store(rd);
705
		
708
		
706
		// on associe le store
709
		// on associe le store
707
		
710
		
708
		this.setStore(st);
711
		this.setStore(st);
709
		
712
		
710
	}
713
	}
711
 
714
 
712
}
715
}