Subversion Repositories eFlore/Applications.cel

Rev

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

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