Subversion Repositories eFlore/Applications.cel

Rev

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

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