Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 682 Rev 727
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
 
-
 
6
import org.tela_botanica.client.Util;
5
 
7
import org.tela_botanica.client.modeles.ListeObservation;
6
import org.tela_botanica.client.modeles.ListeObservation;
8
import org.tela_botanica.client.modeles.Observation;
7
import org.tela_botanica.client.modeles.Observation;
9
import org.tela_botanica.client.observation.ObservationMediateur;
8
import org.tela_botanica.client.observation.ObservationMediateur;
-
 
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.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
				
-
 
673
				
672
					
674
				masquerChargement();
673
				masquerChargement();
675
 
-
 
676
				observationMediateur.obtenirNombreObservation();		
674
				observationMediateur.obtenirNombreObservation();		
677
				
675
				
678
			}
676
			}
679
		}
677
		}
680
		
678
		
681
		// Si on a effectué une suppression
679
		// Si on a effectué une suppression
682
		if(nouvelleDonnees instanceof String)
680
		if(nouvelleDonnees instanceof String)
683
		{
681
		{
684
			String str = (String)nouvelleDonnees ;
682
			String str = (String)nouvelleDonnees ;
685
			observationMediateur.obtenirNombreObservation() ;
683
			observationMediateur.obtenirNombreObservation() ;
686
		}
684
		}
687
		
685
		
688
		if(!getTailleInitialisee()) {
686
		if(!getTailleInitialisee()) {
689
			if((int)Math.round(observationMediateur.getPanneauPrincipalObservation().getHeight() * 0.6) != 0) {
687
			if((int)Math.round(observationMediateur.getPanneauPrincipalObservation().getHeight() * 0.6) != 0) {
690
				doLayout();
688
				doLayout();
691
				setTailleInitialisee();
689
				setTailleInitialisee();
692
			}
690
			}
693
		}
691
		}
694
		
692
		
695
	}
693
	}
696
	
694
	
697
	
695
	
698
	// GESTION DE LA PAGINATION
696
	// GESTION DE LA PAGINATION
699
 
697
 
700
	
698
	
701
	public ListeObservation getCacheListeObservation() {
699
	public ListeObservation getCacheListeObservation() {
702
		return cacheListeObservation;
700
		return cacheListeObservation;
703
	}
701
	}
704
 
702
 
705
	/**
703
	/**
706
	 * Calcule le nombre de pages nécessaires pour afficher un nombre d'élements donnés en fonction de la taille de page
704
	 * Calcule le nombre de pages nécessaires pour afficher un nombre d'élements donnés en fonction de la taille de page
707
	 * en cours
705
	 * en cours
708
	 * @param nbElements le nombre d'élements total
706
	 * @param nbElements le nombre d'élements total
709
	 * @return le nombre de pages 
707
	 * @return le nombre de pages 
710
	 */
708
	 */
711
	public int calculerNbPages(int nbElements)
709
	public int calculerNbPages(int nbElements)
712
	{
710
	{
713
		// A cause de la betise de java pour les conversion implicite on fait quelques conversions manuellement
711
		// A cause de la betise de java pour les conversion implicite on fait quelques conversions manuellement
714
		// pour eviter qu'il arrondisse mal la division
712
		// pour eviter qu'il arrondisse mal la division
715
		// nombre de pages = (nombre d'element / taille de la page) arrondie à l'entier superieur
713
		// nombre de pages = (nombre d'element / taille de la page) arrondie à l'entier superieur
716
		
714
		
717
		double nPage = (1.0*nbElements)/(1.0*taillePage) ; 
715
		double nPage = (1.0*nbElements)/(1.0*taillePage) ; 
718
		double nPageRound = Math.ceil(nPage) ;
716
		double nPageRound = Math.ceil(nPage) ;
719
		Double nPageInt = new Double(nPageRound) ;
717
		Double nPageInt = new Double(nPageRound) ;
720
		
718
		
721
		// on convertit en entier
719
		// on convertit en entier
722
		return nPageInt.intValue() ; 
720
		return nPageInt.intValue() ; 
723
	}
721
	}
724
 
722
 
725
	
723
	
726
	/**
724
	/**
727
	 * Recalcule la page en cours lors du changement du nombre d'élements
725
	 * Recalcule la page en cours lors du changement du nombre d'élements
728
	 * @param nbElements le nombre d'élements total
726
	 * @param nbElements le nombre d'élements total
729
	 * @return la nouvelle page encours
727
	 * @return la nouvelle page encours
730
	 */
728
	 */
731
	public int calculerPageCourante(int nbElements)
729
	public int calculerPageCourante(int nbElements)
732
	{
730
	{
733
		// on calcule le nombre de page
731
		// on calcule le nombre de page
734
		int nouvelNbPages = calculerNbPages(nbElements) ;
732
		int nouvelNbPages = calculerNbPages(nbElements) ;
735
		// la nouvelle page en cours
733
		// la nouvelle page en cours
736
		double nPageCourante = (1.0*pageEncours)/(1.0*pageMax) * (1.0*nouvelNbPages) ;
734
		double nPageCourante = (1.0*pageEncours)/(1.0*pageMax) * (1.0*nouvelNbPages) ;
737
		
735
		
738
		// on arrondit au supérieur
736
		// on arrondit au supérieur
739
		double nPageRound = Math.ceil(nPageCourante) ;
737
		double nPageRound = Math.ceil(nPageCourante) ;
740
		Double nPageInt = new Double(nPageRound) ;
738
		Double nPageInt = new Double(nPageRound) ;
741
		
739
		
742
		// on convertit en entier
740
		// on convertit en entier
743
		return Math.abs(nPageInt.intValue()) ; 
741
		return Math.abs(nPageInt.intValue()) ; 
744
	}
742
	}
745
	
743
	
746
 
744
 
747
	/**
745
	/**
748
	 * Appelle le modèle pour lui demander les données d'une page à afficher
746
	 * Appelle le modèle pour lui demander les données d'une page à afficher
749
	 * @param pageCourante le numéro de page à affciher
747
	 * @param pageCourante le numéro de page à affciher
750
	 */
748
	 */
751
	public void changerNumeroPage(int pageCourante) {
749
	public void changerNumeroPage(int pageCourante) {
752
		
750
		
753
		
751
		
754
		
752
		
755
		pageEncours = pageCourante ;
753
		pageEncours = pageCourante ;
756
		
754
		
757
		masquerChargement();
755
		masquerChargement();
758
 
756
 
759
		// On lance le chargerment des observations
757
		// On lance le chargerment des observations
760
		observationMediateur.obtenirNombreObservation();
758
		observationMediateur.obtenirNombreObservation();
761
		
759
		
762
		getToolBarVue().changerPageCourante(pageCourante);
760
		getToolBarVue().changerPageCourante(pageCourante);
763
		
761
		
764
	}
762
	}
765
	
763
	
766
	
764
	
767
	/**
765
	/**
768
	 * Appelle le modèle pour qu'il change la taille de page utilisée
766
	 * Appelle le modèle pour qu'il change la taille de page utilisée
769
	 * @param nouvelleTaillePage la nouvelle taille de page
767
	 * @param nouvelleTaillePage la nouvelle taille de page
770
	 */
768
	 */
771
	
769
	
772
	public void changerTaillePage(int nouvelleTaillePage)
770
	public void changerTaillePage(int nouvelleTaillePage)
773
	{
771
	{
774
	
772
	
775
		taillePage = nouvelleTaillePage ;
773
		taillePage = nouvelleTaillePage ;
776
		pageEncours = calculerPageCourante(nbElements) ;
774
		pageEncours = calculerPageCourante(nbElements) ;
777
 
775
 
778
		masquerChargement();
776
		masquerChargement();
779
 
777
 
780
		// 	On lance le chargement des observations
778
		// 	On lance le chargement des observations
781
		observationMediateur.obtenirNombreObservation();
779
		observationMediateur.obtenirNombreObservation();
782
		
780
		
783
		
781
		
784
		// et on met à jour la taille de page dans les barres d'outils
782
		// et on met à jour la taille de page dans les barres d'outils
785
		getToolBarVue().selectionnerTaillePage(nouvelleTaillePage);
783
		getToolBarVue().selectionnerTaillePage(nouvelleTaillePage);
786
		
784
		
787
		
785
		
788
	}
786
	}
789
 
787
 
790
	
788
	
791
	/**
789
	/**
792
	 * Met à jour les barre d'outils avec des nouvelles valeurs
790
	 * Met à jour les barre d'outils avec des nouvelles valeurs
793
	 * @param pageMax le nombre de pages
791
	 * @param pageMax le nombre de pages
794
	 * @param pageEncours la page en cours
792
	 * @param pageEncours la page en cours
795
	 * @param taillePage la taille de page
793
	 * @param taillePage la taille de page
796
	 * @param nbElement le nombre d'élements par page
794
	 * @param nbElement le nombre d'élements par page
797
	 */
795
	 */
798
	public void changerPageMaxEtCourante(int pageMax, int pageEncours, int taillePage, int nbElement) 
796
	public void changerPageMaxEtCourante(int pageMax, int pageEncours, int taillePage, int nbElement) 
799
	{
797
	{
800
				
798
				
801
		int[] pages = {pageMax,pageEncours, taillePage, nbElement} ;
799
		int[] pages = {pageMax,pageEncours, taillePage, nbElement} ;
802
		getToolBarVue().rafraichir(pages, false) ;
800
		getToolBarVue().rafraichir(pages, false) ;
803
		
801
		
804
	}
802
	}
805
	
803
	
806
	/**
804
	/**
807
	 * Renvoie la taille de page en cours d'utilisation
805
	 * Renvoie la taille de page en cours d'utilisation
808
	 * @return la taille de page
806
	 * @return la taille de page
809
	 */
807
	 */
810
	public int getTaillePage() {
808
	public int getTaillePage() {
811
		
809
		
812
		return taillePage;
810
		return taillePage;
813
	}
811
	}
814
	
812
	
815
	/**
813
	/**
816
	 * Renvoie le numéro de la page encours (attention on commence à 0)
814
	 * Renvoie le numéro de la page encours (attention on commence à 0)
817
	 * @return le numéro de la page en cours
815
	 * @return le numéro de la page en cours
818
	 */
816
	 */
819
	public int getPageEncours() {
817
	public int getPageEncours() {
820
		
818
		
821
		return pageEncours;
819
		return pageEncours;
822
	}
820
	}
823
	
821
	
824
	public void afficherFiltres(String[][] filtresEnCours) {
822
	public void afficherFiltres(String[][] filtresEnCours) {
825
		
823
		
826
		String texteFiltresEnCours = "";
824
		String texteFiltresEnCours = "";
827
		
825
		
828
		for(int i = 0; i < filtresEnCours.length; i++) {
826
		for(int i = 0; i < filtresEnCours.length; i++) {
829
			if(Util.filtreValide(filtresEnCours[i])) {
827
			if(Util.filtreValide(filtresEnCours[i])) {
830
				
828
				
831
				if(!texteFiltresEnCours.equals("")) {
829
				if(!texteFiltresEnCours.equals("")) {
832
					texteFiltresEnCours += " - ";
830
					texteFiltresEnCours += " - ";
833
				}
831
				}
834
				
832
				
835
				texteFiltresEnCours += "<span class=\"affichage_filtre\">"+
833
				texteFiltresEnCours += "<span class=\"affichage_filtre\">"+
836
											transformerNomFiltre(filtresEnCours[i][0])+": "+transformerValeurFiltre(filtresEnCours[i][0], filtresEnCours[i][1])+
834
											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]+"\" />"+
835
									   " <input value=\"X\" type=\"button\" rel=\""+filtresEnCours[i][0]+"\" id=\"bouton_raz_filtres_obs"+filtresEnCours[i][0]+"\" />"+
838
										"</span>";
836
										"</span>";
839
			}
837
			}
840
		}
838
		}
841
		
839
		
842
		if(!texteFiltresEnCours.equals("")) {
840
		if(!texteFiltresEnCours.equals("")) {
843
			texteFiltresEnCours = "- <span class=\"indicateur_filtres\"> Filtres - "+texteFiltresEnCours+"</span>";
841
			texteFiltresEnCours = "- <span class=\"indicateur_filtres\"> Filtres - "+texteFiltresEnCours+"</span>";
844
		}
842
		}
845
		
843
		
846
		this.setTitle("Observations"+texteFiltresEnCours) ;
844
		this.setTitle("Observations"+texteFiltresEnCours) ;
847
		
845
		
848
		for(int i = 0; i < filtresEnCours.length; i++) {
846
		for(int i = 0; i < filtresEnCours.length; i++) {
849
			
847
			
850
			if(Util.filtreValide(filtresEnCours[i])) {
848
			if(Util.filtreValide(filtresEnCours[i])) {
851
				if(Ext.get("bouton_raz_filtres_obs"+filtresEnCours[i][0]) != null) {
849
				if(Ext.get("bouton_raz_filtres_obs"+filtresEnCours[i][0]) != null) {
852
					
850
					
853
					Ext.get("bouton_raz_filtres_obs"+filtresEnCours[i][0]).addListener("click", new EventCallback() {
851
					Ext.get("bouton_raz_filtres_obs"+filtresEnCours[i][0]).addListener("click", new EventCallback() {
854
						
852
						
855
						public void execute(EventObject e) {
853
						public void execute(EventObject e) {
856
							e.stopEvent();
854
							e.stopEvent();
857
							observationMediateur.viderFiltre(e.getTarget().getAttribute("rel"));
855
							observationMediateur.viderFiltre(e.getTarget().getAttribute("rel"));
858
						}
856
						}
859
						
857
						
860
					});
858
					});
861
				}
859
				}
862
			}
860
			}
863
		}
861
		}
864
	}
862
	}
865
	
863
	
866
	private String transformerNomFiltre(String nomFiltre) {
864
	private String transformerNomFiltre(String nomFiltre) {
867
		
865
		
868
		if(nomFiltre.equals("id_location")) {
866
		if(nomFiltre.equals("id_location")) {
869
			nomFiltre = "departement";
867
			nomFiltre = "departement";
870
		}
868
		}
871
		
869
		
872
		if(nomFiltre.equals("location")) {
870
		if(nomFiltre.equals("location")) {
873
			nomFiltre = "commune";
871
			nomFiltre = "commune";
874
		}
872
		}
875
		
873
		
876
		if(nomFiltre.equals("nom_taxon")) {
874
		if(nomFiltre.equals("nom_taxon")) {
877
			nomFiltre = "recherche";
875
			nomFiltre = "recherche";
878
		}
876
		}
879
		
877
		
880
		if(nomFiltre.equals("mots_cles")) {
878
		if(nomFiltre.equals("mots_cles")) {
881
			nomFiltre = "projets";
879
			nomFiltre = "projets";
882
		}
880
		}
883
		
881
		
884
		return nomFiltre;
882
		return nomFiltre;
885
		
883
		
886
	}
884
	}
887
	
885
	
888
	private String transformerValeurFiltre(String nomFiltre, String valeurFiltre) {
886
	private String transformerValeurFiltre(String nomFiltre, String valeurFiltre) {
889
		
887
		
890
		String valeurFiltreTransformee = valeurFiltre;
888
		String valeurFiltreTransformee = valeurFiltre;
891
		
889
		
892
		if(nomFiltre.equals("mots_cles")) {
890
		if(nomFiltre.equals("mots_cles")) {
893
			
891
			
894
			String[] tabMotsCles = valeurFiltre.split(";");
892
			String[] tabMotsCles = valeurFiltre.split(";");
895
			String[] tabMotsClesTexte = observationMediateur.obtenirTexteMotsCles(tabMotsCles);
893
			String[] tabMotsClesTexte = observationMediateur.obtenirTexteMotsCles(tabMotsCles);
896
			
894
			
897
			if(tabMotsClesTexte.length > 1) {
895
			if(tabMotsClesTexte.length > 1) {
898
				valeurFiltreTransformee = Util.implode(",", tabMotsClesTexte);
896
				valeurFiltreTransformee = Util.implode(",", tabMotsClesTexte);
899
			} else {
897
			} else {
900
				valeurFiltreTransformee = tabMotsClesTexte[0];
898
				valeurFiltreTransformee = tabMotsClesTexte[0];
901
			}
899
			}
902
		}
900
		}
903
		
901
		
904
		if(nomFiltre.equals("mois")) {
902
		if(nomFiltre.equals("mois")) {
905
			valeurFiltreTransformee = Util.renvoyerMois(Integer.parseInt(valeurFiltre));
903
			valeurFiltreTransformee = Util.renvoyerMois(Integer.parseInt(valeurFiltre));
906
		}
904
		}
907
		
905
		
908
		valeurFiltreTransformee = valeurFiltreTransformee.replaceAll("000null", "inconnue");
906
		valeurFiltreTransformee = valeurFiltreTransformee.replaceAll("000null", "inconnue");
909
 
907
 
910
		return valeurFiltreTransformee;
908
		return valeurFiltreTransformee;
911
		
909
		
912
	}
910
	}
913
 
911
 
914
	public void raz() {
912
	public void raz() {
915
		
913
		
916
		
914
		
917
		// creation du store qui les contient
915
		// creation du store qui les contient
918
		
916
		
919
		FieldDef defEtatObservation = new StringFieldDef("etat_observation");
917
		FieldDef defEtatObservation = new StringFieldDef("etat_observation");
920
		FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
918
		FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
921
		FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
919
		FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
922
		FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
920
		FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
923
		FieldDef defDateObservation = new StringFieldDef("date_observation");
921
		FieldDef defDateObservation = new StringFieldDef("date_observation");
924
		FieldDef defOrdreObservation = new IntegerFieldDef("ordre_observation");
922
		FieldDef defOrdreObservation = new IntegerFieldDef("ordre_observation");
925
		
923
		
926
		// Non affiches :
924
		// Non affiches :
927
		FieldDef defNumeroNomenclaturalSaisiObservation = new StringFieldDef("numeroNomenclaturalSaisi_observation");
925
		FieldDef defNumeroNomenclaturalSaisiObservation = new StringFieldDef("numeroNomenclaturalSaisi_observation");
928
		
926
		
929
		FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation,
927
		FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation,
930
				defLieuObservation, defDateObservation, defOrdreObservation };
928
				defLieuObservation, defDateObservation, defOrdreObservation };
931
		
929
		
932
		RecordDef rd = new RecordDef(defTab);
930
		RecordDef rd = new RecordDef(defTab);
933
		st = new Store(rd);
931
		st = new Store(rd);
934
		
932
		
935
		// on associe le store
933
		// on associe le store
936
		
934
		
937
		this.setStore(st);
935
		this.setStore(st);
938
		
936
		
939
	}
937
	}
940
	
938
	
941
	public boolean verifierFormatDate(String date) {
939
	public boolean verifierFormatDate(String date) {
942
		
940
		
943
		String regex = "[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}" ;
941
		String regex = "[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}" ;
944
		if(date.matches(regex) && !date.equals("0000-00-00")) {
942
		if(date.matches(regex) && !date.equals("0000-00-00")) {
945
			return true ;
943
			return true ;
946
		}
944
		}
947
		else {
945
		else {
948
			return false;
946
			return false;
949
		}
947
		}
950
	}
948
	}
951
	
949
	
952
	public boolean getTailleInitialisee() {
950
	public boolean getTailleInitialisee() {
953
		return tailleInitialisee ;
951
		return tailleInitialisee ;
954
	}
952
	}
955
	
953
	
956
	public void setTailleInitialisee() {
954
	public void setTailleInitialisee() {
957
		tailleInitialisee = true;
955
		tailleInitialisee = true;
958
	}
956
	}
959
 
957
 
960
}
958
}