Subversion Repositories eFlore/Applications.cel

Rev

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

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