Subversion Repositories eFlore/Applications.cel

Rev

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

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