Subversion Repositories eFlore/Applications.cel

Rev

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

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