Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 351 Rev 361
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) {
427
			    	if(index < 0) {
428
			    		return true;
428
			    		return true;
429
			    	}
429
			    	}
430
			    	
430
			    	
431
			    	Record obsRd = getStore().getRecordAt(index);
431
			    	Record obsRd = getStore().getRecordAt(index);
432
			    	if(obsRd == null) {
432
			    	if(obsRd == null) {
433
			    		return true;
433
			    		return true;
434
			    	}
434
			    	}
435
			    	
435
			    	
436
			    	String ordreObs = obsRd.getAsString("ordre_observation");
436
			    	String ordreObs = obsRd.getAsString("ordre_observation");
437
			    	
437
			    	
438
			    	if(ordreObs != null) {
438
			    	if(ordreObs != null) {
439
			    		observationMediateur.gererDDMotCleSurObs(ordreObs, idMc);
439
			    		observationMediateur.gererDDMotCleSurObs(ordreObs, idMc);
440
			    		return true ;
440
			    		return true ;
441
			    	} else {
441
			    	} else {
442
			    		return true;
442
			    		return true;
443
			    	}
443
			    	}
444
				}
444
				}
445
		    	return true;
445
		    	return true;
446
			}
446
			}
447
			
447
			
448
			public String notifyOver(DragSource source, EventObject e, DragData data){
448
			public String notifyOver(DragSource source, EventObject e, DragData data){
449
				
449
				
450
				if(data instanceof TreeDragData)  {
450
				if(data instanceof TreeDragData)  {
451
			    	TreeDragData tdd = (TreeDragData)data ;
451
			    	TreeDragData tdd = (TreeDragData)data ;
452
			    	
452
			    	
453
			    	TreeNode treeNode = tdd.getTreeNode();  
453
			    	TreeNode treeNode = tdd.getTreeNode();  
454
			    	String idMc = treeNode.getId();  
454
			    	String idMc = treeNode.getId();  
455
			    	
455
			    	
456
			    	int index = getView().findRowIndex(e);
456
			    	int index = getView().findRowIndex(e);
457
			    	if(index < 0) {
457
			    	if(index < 0) {
458
			    		return "x-dd-drop-nodrop";
458
			    		return "x-dd-drop-nodrop";
459
			    	}
459
			    	}
460
			    	
460
			    	
461
			    	Record obsRd = getStore().getRecordAt(index);
461
			    	Record obsRd = getStore().getRecordAt(index);
462
			    	
462
			    	
463
			    	if(obsRd == null) {
463
			    	if(obsRd == null) {
464
			    		return "x-dd-drop-nodrop";
464
			    		return "x-dd-drop-nodrop";
465
			    	}
465
			    	}
466
			    	
466
			    	
467
			    	String ordreObs = obsRd.getAsString("ordre_observation");
467
			    	String ordreObs = obsRd.getAsString("ordre_observation");
468
			    	
468
			    	
469
			    	if(ordreObs != null) {
469
			    	if(ordreObs != null) {
470
			    		return observationMediateur.gererOverDDMotCleSurObs(ordreObs, idMc);
470
			    		return observationMediateur.gererOverDDMotCleSurObs(ordreObs, idMc);
471
			    	}
471
			    	}
472
				}
472
				}
473
				
473
				
474
				return "x-dd-drop-nodrop";
474
				return "x-dd-drop-nodrop";
475
			}
475
			}
476
		};
476
		};
477
	}
477
	}
478
 
478
 
479
	/**
479
	/**
480
	 * Méthode héritée de l'interface VueListable
480
	 * 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
481
	 * Sélectionne les observations  dans la liste suivant les identifiants donnés en paramètres
482
	 */
482
	 */
483
	
483
	
484
	public String[] getIdSelectionnees() {
484
	public String[] getIdSelectionnees() {
485
		
485
		
486
		Record[] selection = this.getSelectionModel().getSelections();
486
		Record[] selection = this.getSelectionModel().getSelections();
487
		int taille = selection.length;
487
		int taille = selection.length;
488
		String id_selection[] = new String[taille];
488
		String id_selection[] = new String[taille];
489
 
489
 
490
		for (int i = 0; i < selection.length; i++) {
490
		for (int i = 0; i < selection.length; i++) {
491
 
491
 
492
			id_selection[i] = selection[i].getAsString("ordre_observation");
492
			id_selection[i] = selection[i].getAsString("ordre_observation");
493
		}
493
		}
494
 
494
 
495
		return id_selection;
495
		return id_selection;
496
	}
496
	}
497
	
497
	
498
 
498
 
499
	
499
	
500
	/**
500
	/**
501
	 * Sélectionne des enregistrements donné 
501
	 * Sélectionne des enregistrements donné 
502
	 * @param sel un tableau d'enregistrement à selectionner
502
	 * @param sel un tableau d'enregistrement à selectionner
503
	 */
503
	 */
504
	public void selectionnerEnregistrements(Record[] sel) {
504
	public void selectionnerEnregistrements(Record[] sel) {
505
 
505
 
506
			getSelectionModel().clearSelections();
506
			getSelectionModel().clearSelections();
507
			getSelectionModel().selectRecords(sel);
507
			getSelectionModel().selectRecords(sel);
508
		
508
		
509
	}
509
	}
510
	
510
	
511
	/**
511
	/**
512
	 * Accesseur pour la toolbar de pagination
512
	 * Accesseur pour la toolbar de pagination
513
	 * @return la toolbar de pagination
513
	 * @return la toolbar de pagination
514
	 */
514
	 */
515
	
515
	
516
	public BarrePaginationVue getToolBarVue()
516
	public BarrePaginationVue getToolBarVue()
517
	{
517
	{
518
		return bt ;
518
		return bt ;
519
	}
519
	}
520
 
520
 
521
 
521
 
522
	/**
522
	/**
523
	 * Recherche l'élement actuellement affiché et affiche son message de chargement
523
	 * Recherche l'élement actuellement affiché et affiche son message de chargement
524
	 */
524
	 */
525
	public void masquerChargement()
525
	public void masquerChargement()
526
	{
526
	{
527
			ExtElement masked = Ext.get(getId()) ;
527
			ExtElement masked = Ext.get(getId()) ;
528
 
528
 
529
 
529
 
530
			if (masked!=null) {
530
			if (masked!=null) {
531
				masked.mask("Chargement") ;
531
				masked.mask("Chargement") ;
532
			}
532
			}
533
 
533
 
534
	}
534
	}
535
	
535
	
536
	/**
536
	/**
537
	 * 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é
538
	 */
538
	 */
539
	public void demasquerChargement()
539
	public void demasquerChargement()
540
	{
540
	{
541
		ExtElement masked = Ext.get(getId()) ;
541
		ExtElement masked = Ext.get(getId()) ;
542
		
542
		
543
		if (masked!=null) {
543
		if (masked!=null) {
544
			masked.unmask() ;
544
			masked.unmask() ;
545
		}
545
		}
546
	}
546
	}
547
	
547
	
548
 
548
 
549
 
549
 
550
	/**
550
	/**
551
	 * Méthode héritée de l'interface rafraichissable
551
	 * Méthode héritée de l'interface rafraichissable
552
	 * @param nouvelleDonnees les nouvelles données
552
	 * @param nouvelleDonnees les nouvelles données
553
	 * @param repandreRafraichissement le booleen de notification du rafraichissement
553
	 * @param repandreRafraichissement le booleen de notification du rafraichissement
554
	 */
554
	 */
555
	
555
	
556
 
556
 
557
 
557
 
558
	public void rafraichir(Object nouvelleDonnees, boolean repandreRafraichissement) {
558
	public void rafraichir(Object nouvelleDonnees, boolean repandreRafraichissement) {
559
	
559
	
560
//		 si l'on a reçu une liste d'observation
560
//		 si l'on a reçu une liste d'observation
561
		if(nouvelleDonnees instanceof ListeObservation)
561
		if(nouvelleDonnees instanceof ListeObservation)
562
		{
562
		{
563
			
563
			
564
				ListeObservation data = (ListeObservation) nouvelleDonnees ;
564
				ListeObservation data = (ListeObservation) nouvelleDonnees ;
565
				Object[][] observationData = new Object[data.size()][7];
565
				Object[][] observationData = new Object[data.size()][7];
566
				int i = 0 ;
566
				int i = 0 ;
567
				
567
				
568
				if(data.size() == 0)
568
				if(data.size() == 0)
569
				{
569
				{
570
					pageEncours = 0 ;
570
					pageEncours = 0 ;
571
				}
571
				}
572
				
572
				
573
				// 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
574
				for (Iterator it = data.keySet().iterator(); it.hasNext();) 
574
				for (Iterator it = data.keySet().iterator(); it.hasNext();) 
575
				{
575
				{
576
					
576
					
577
					Observation obs=(Observation) data.get(it.next());
577
					Observation obs=(Observation) data.get(it.next());
578
					
578
					
579
					observationData[i][0] = obs.getTransmis();
579
					observationData[i][0] = obs.getTransmis();
580
					observationData[i][1] = obs.getNomSaisi();
580
					observationData[i][1] = obs.getNomSaisi();
581
					observationData[i][2] = obs.getNomRetenu();
581
					observationData[i][2] = obs.getNomRetenu();
582
 
582
 
583
					observationData[i][3] = fabriquerLieu(obs);
583
					observationData[i][3] = fabriquerLieu(obs);
584
					observationData[i][4] = obs.getDate();
584
					observationData[i][4] = obs.getDate();
585
					observationData[i][5] = obs.getNumeroOrdre();		
585
					observationData[i][5] = obs.getNumeroOrdre();		
586
					observationData[i][6] = obs.getNumeroNomenclaturalSaisi();
586
					observationData[i][6] = obs.getNumeroNomenclaturalSaisi();
587
									
587
									
588
					i++ ;
588
					i++ ;
589
				}
589
				}
590
		
590
		
591
				// creation du store qui les contient
591
				// creation du store qui les contient
592
				FieldDef defEtatObservation = new StringFieldDef("etat_observation");
592
				FieldDef defEtatObservation = new StringFieldDef("etat_observation");
593
				FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
593
				FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
594
				FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
594
				FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
595
				FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
595
				FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
596
				FieldDef defDateObservation = new StringFieldDef("date_observation");
596
				FieldDef defDateObservation = new StringFieldDef("date_observation");
597
				FieldDef defOrdreObservation = new IntegerFieldDef("ordre_observation");
597
				FieldDef defOrdreObservation = new IntegerFieldDef("ordre_observation");
598
				
598
				
599
				// Non affiches :
599
				// Non affiches :
600
				FieldDef defNumeroNomenclaturalSaisiObservation = new StringFieldDef("numeroNomenclaturalSaisi_observation");
600
				FieldDef defNumeroNomenclaturalSaisiObservation = new StringFieldDef("numeroNomenclaturalSaisi_observation");
601
				
601
				
602
				
602
				
603
				// on associe le store
603
				// on associe le store
604
 
604
 
605
				FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation,
605
				FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation,
606
						defLieuObservation, defDateObservation, defOrdreObservation, defNumeroNomenclaturalSaisiObservation };
606
						defLieuObservation, defDateObservation, defOrdreObservation, defNumeroNomenclaturalSaisiObservation };
607
				
607
				
608
				RecordDef rd = new RecordDef(defTab);
608
				RecordDef rd = new RecordDef(defTab);
609
				
609
				
610
				final MemoryProxy dataProxy = new MemoryProxy(observationData);
610
				final MemoryProxy dataProxy = new MemoryProxy(observationData);
611
				final ArrayReader reader = new ArrayReader(rd);
611
				final ArrayReader reader = new ArrayReader(rd);
612
		
612
		
613
				final Store observationStore = new Store(dataProxy, reader);
613
				final Store observationStore = new Store(dataProxy, reader);
614
				
614
				
615
				
615
				
616
				st = observationStore ;
616
				st = observationStore ;
617
				st.load() ;
617
				st.load() ;
618
				
618
				
619
				
619
				
620
				// et on reconfigure et rafraichit la vue
620
				// et on reconfigure et rafraichit la vue
621
				this.reconfigure(st, this.getColumnModel());
621
				this.reconfigure(st, this.getColumnModel());
622
				
622
				
623
				demasquerChargement();
623
				demasquerChargement();
624
				
624
				
625
			    cacheListeObservation=data;
625
			    cacheListeObservation=data;
626
			    
626
			    
627
				observationMediateur.onRafraichissementListeObservations();
627
				observationMediateur.onRafraichissementListeObservations();
628
				
628
				
629
				
629
				
630
		}
630
		}
631
		
631
		
632
		
632
		
633
		// Si on reçoit un tableau d'entiers
633
		// 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
634
		// c'est un tableau d'un seul entier qui est le nombre d'observation correspondant aux critères
635
		if(nouvelleDonnees instanceof int[])
635
		if(nouvelleDonnees instanceof int[])
636
		{
636
		{
637
			int[] pages = (int[])nouvelleDonnees ;
637
			int[] pages = (int[])nouvelleDonnees ;
638
			
638
			
639
			// 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
640
			pageMax  = calculerNbPages(pages[0]) ;
640
			pageMax  = calculerNbPages(pages[0]) ;
641
			nbElements = pages[0] ;
641
			nbElements = pages[0] ;
642
			
642
			
643
			
643
			
644
			// et on notifie de le mediateur du changement des valeurs
644
			// et on notifie de le mediateur du changement des valeurs
645
			changerPageMaxEtCourante(pageMax,pageEncours,taillePage,pages[0]) ;
645
			changerPageMaxEtCourante(pageMax,pageEncours,taillePage,pages[0]) ;
646
			
646
			
647
			masquerChargement();
647
			masquerChargement();
648
			observationMediateur.obtenirListeObservation(this);
648
			observationMediateur.obtenirListeObservation(this);
649
		}
649
		}
650
		
650
		
651
		
651
		
652
//		 si l'on a reçu une Observation 
652
//		 si l'on a reçu une Observation 
653
		
653
		
654
		if(nouvelleDonnees instanceof Observation) {
654
		if(nouvelleDonnees instanceof Observation) {
655
		
655
		
656
			Observation obs= (Observation) nouvelleDonnees;
656
			Observation obs= (Observation) nouvelleDonnees;
657
			if (obs.getNumeroOrdre()==null) { // Nouvelle observation
657
			if (obs.getNumeroOrdre()==null) { // Nouvelle observation
658
			// On affiche la dernière page
658
			// On affiche la dernière page
659
			
659
			
660
			pageEncours = pageMax ;
660
			pageEncours = pageMax ;
661
			masquerChargement();
661
			masquerChargement();
662
 
662
 
663
			observationMediateur.obtenirNombreObservation();
663
			observationMediateur.obtenirNombreObservation();
664
			
664
			
665
			}
665
			}
666
			else { // Modification d'une observation
666
			else { // Modification d'une observation
667
				
667
				
668
				
668
				
669
				masquerChargement();
669
				masquerChargement();
670
 
670
 
671
				observationMediateur.obtenirNombreObservation();		
671
				observationMediateur.obtenirNombreObservation();		
672
				
672
				
673
			}
673
			}
674
		}
674
		}
675
		
675
		
676
		// Si on a effectué une suppression
676
		// Si on a effectué une suppression
677
		if(nouvelleDonnees instanceof String)
677
		if(nouvelleDonnees instanceof String)
678
		{
678
		{
679
			String str = (String)nouvelleDonnees ;
679
			String str = (String)nouvelleDonnees ;
680
			observationMediateur.obtenirNombreObservation() ;
680
			observationMediateur.obtenirNombreObservation() ;
681
		}
681
		}
-
 
682
		
-
 
683
		if(!getTailleInitialisee()) {
-
 
684
			if((int)Math.round(observationMediateur.getPanneauPrincipalObservation().getHeight() * 0.6) != 0) {
-
 
685
				doLayout();
-
 
686
				setTailleInitialisee();
-
 
687
			}
-
 
688
		}
682
		
689
		
683
	}
690
	}
684
	
691
	
685
	
692
	
686
	// GESTION DE LA PAGINATION
693
	// GESTION DE LA PAGINATION
687
 
694
 
688
	
695
	
689
	public ListeObservation getCacheListeObservation() {
696
	public ListeObservation getCacheListeObservation() {
690
		return cacheListeObservation;
697
		return cacheListeObservation;
691
	}
698
	}
692
 
699
 
693
	/**
700
	/**
694
	 * Calcule le nombre de pages nécessaires pour afficher un nombre d'élements donnés en fonction de la taille de page
701
	 * Calcule le nombre de pages nécessaires pour afficher un nombre d'élements donnés en fonction de la taille de page
695
	 * en cours
702
	 * en cours
696
	 * @param nbElements le nombre d'élements total
703
	 * @param nbElements le nombre d'élements total
697
	 * @return le nombre de pages 
704
	 * @return le nombre de pages 
698
	 */
705
	 */
699
	public int calculerNbPages(int nbElements)
706
	public int calculerNbPages(int nbElements)
700
	{
707
	{
701
		// A cause de la betise de java pour les conversion implicite on fait quelques conversions manuellement
708
		// A cause de la betise de java pour les conversion implicite on fait quelques conversions manuellement
702
		// pour eviter qu'il arrondisse mal la division
709
		// pour eviter qu'il arrondisse mal la division
703
		// nombre de pages = (nombre d'element / taille de la page) arrondie à l'entier superieur
710
		// nombre de pages = (nombre d'element / taille de la page) arrondie à l'entier superieur
704
		
711
		
705
		double nPage = (1.0*nbElements)/(1.0*taillePage) ; 
712
		double nPage = (1.0*nbElements)/(1.0*taillePage) ; 
706
		double nPageRound = Math.ceil(nPage) ;
713
		double nPageRound = Math.ceil(nPage) ;
707
		Double nPageInt = new Double(nPageRound) ;
714
		Double nPageInt = new Double(nPageRound) ;
708
		
715
		
709
		// on convertit en entier
716
		// on convertit en entier
710
		return nPageInt.intValue() ; 
717
		return nPageInt.intValue() ; 
711
	}
718
	}
712
 
719
 
713
	
720
	
714
	/**
721
	/**
715
	 * Recalcule la page en cours lors du changement du nombre d'élements
722
	 * Recalcule la page en cours lors du changement du nombre d'élements
716
	 * @param nbElements le nombre d'élements total
723
	 * @param nbElements le nombre d'élements total
717
	 * @return la nouvelle page encours
724
	 * @return la nouvelle page encours
718
	 */
725
	 */
719
	public int calculerPageCourante(int nbElements)
726
	public int calculerPageCourante(int nbElements)
720
	{
727
	{
721
		// on calcule le nombre de page
728
		// on calcule le nombre de page
722
		int nouvelNbPages = calculerNbPages(nbElements) ;
729
		int nouvelNbPages = calculerNbPages(nbElements) ;
723
		// la nouvelle page en cours
730
		// la nouvelle page en cours
724
		double nPageCourante = (1.0*pageEncours)/(1.0*pageMax) * (1.0*nouvelNbPages) ;
731
		double nPageCourante = (1.0*pageEncours)/(1.0*pageMax) * (1.0*nouvelNbPages) ;
725
		
732
		
726
		// on arrondit au supérieur
733
		// on arrondit au supérieur
727
		double nPageRound = Math.ceil(nPageCourante) ;
734
		double nPageRound = Math.ceil(nPageCourante) ;
728
		Double nPageInt = new Double(nPageRound) ;
735
		Double nPageInt = new Double(nPageRound) ;
729
		
736
		
730
		// on convertit en entier
737
		// on convertit en entier
731
		return Math.abs(nPageInt.intValue()) ; 
738
		return Math.abs(nPageInt.intValue()) ; 
732
	}
739
	}
733
	
740
	
734
 
741
 
735
	/**
742
	/**
736
	 * Appelle le modèle pour lui demander les données d'une page à afficher
743
	 * Appelle le modèle pour lui demander les données d'une page à afficher
737
	 * @param pageCourante le numéro de page à affciher
744
	 * @param pageCourante le numéro de page à affciher
738
	 */
745
	 */
739
	public void changerNumeroPage(int pageCourante) {
746
	public void changerNumeroPage(int pageCourante) {
740
		
747
		
741
		
748
		
742
		
749
		
743
		pageEncours = pageCourante ;
750
		pageEncours = pageCourante ;
744
		
751
		
745
		masquerChargement();
752
		masquerChargement();
746
 
753
 
747
		// On lance le chargerment des observations
754
		// On lance le chargerment des observations
748
		observationMediateur.obtenirNombreObservation();
755
		observationMediateur.obtenirNombreObservation();
749
		
756
		
750
		getToolBarVue().changerPageCourante(pageCourante);
757
		getToolBarVue().changerPageCourante(pageCourante);
751
		
758
		
752
	}
759
	}
753
	
760
	
754
	
761
	
755
	/**
762
	/**
756
	 * Appelle le modèle pour qu'il change la taille de page utilisée
763
	 * Appelle le modèle pour qu'il change la taille de page utilisée
757
	 * @param nouvelleTaillePage la nouvelle taille de page
764
	 * @param nouvelleTaillePage la nouvelle taille de page
758
	 */
765
	 */
759
	
766
	
760
	public void changerTaillePage(int nouvelleTaillePage)
767
	public void changerTaillePage(int nouvelleTaillePage)
761
	{
768
	{
762
	
769
	
763
		taillePage = nouvelleTaillePage ;
770
		taillePage = nouvelleTaillePage ;
764
		pageEncours = calculerPageCourante(nbElements) ;
771
		pageEncours = calculerPageCourante(nbElements) ;
765
 
772
 
766
		masquerChargement();
773
		masquerChargement();
767
 
774
 
768
		// 	On lance le chargement des observations
775
		// 	On lance le chargement des observations
769
		observationMediateur.obtenirNombreObservation();
776
		observationMediateur.obtenirNombreObservation();
770
		
777
		
771
		
778
		
772
		// et on met à jour la taille de page dans les barres d'outils
779
		// et on met à jour la taille de page dans les barres d'outils
773
		getToolBarVue().selectionnerTaillePage(nouvelleTaillePage);
780
		getToolBarVue().selectionnerTaillePage(nouvelleTaillePage);
774
		
781
		
775
		
782
		
776
	}
783
	}
777
 
784
 
778
	
785
	
779
	/**
786
	/**
780
	 * Met à jour les barre d'outils avec des nouvelles valeurs
787
	 * Met à jour les barre d'outils avec des nouvelles valeurs
781
	 * @param pageMax le nombre de pages
788
	 * @param pageMax le nombre de pages
782
	 * @param pageEncours la page en cours
789
	 * @param pageEncours la page en cours
783
	 * @param taillePage la taille de page
790
	 * @param taillePage la taille de page
784
	 * @param nbElement le nombre d'élements par page
791
	 * @param nbElement le nombre d'élements par page
785
	 */
792
	 */
786
	public void changerPageMaxEtCourante(int pageMax, int pageEncours, int taillePage, int nbElement) 
793
	public void changerPageMaxEtCourante(int pageMax, int pageEncours, int taillePage, int nbElement) 
787
	{
794
	{
788
				
795
				
789
		int[] pages = {pageMax,pageEncours, taillePage, nbElement} ;
796
		int[] pages = {pageMax,pageEncours, taillePage, nbElement} ;
790
		getToolBarVue().rafraichir(pages, false) ;
797
		getToolBarVue().rafraichir(pages, false) ;
791
		
798
		
792
	}
799
	}
793
	
800
	
794
	/**
801
	/**
795
	 * Renvoie la taille de page en cours d'utilisation
802
	 * Renvoie la taille de page en cours d'utilisation
796
	 * @return la taille de page
803
	 * @return la taille de page
797
	 */
804
	 */
798
	public int getTaillePage() {
805
	public int getTaillePage() {
799
		
806
		
800
		return taillePage;
807
		return taillePage;
801
	}
808
	}
802
	
809
	
803
	/**
810
	/**
804
	 * Renvoie le numéro de la page encours (attention on commence à 0)
811
	 * Renvoie le numéro de la page encours (attention on commence à 0)
805
	 * @return le numéro de la page en cours
812
	 * @return le numéro de la page en cours
806
	 */
813
	 */
807
	public int getPageEncours() {
814
	public int getPageEncours() {
808
		
815
		
809
		return pageEncours;
816
		return pageEncours;
810
	}
817
	}
811
	
818
	
812
	public void afficherFiltres(String nLieu, String nDate, String nTaxon)
819
	public void afficherFiltres(String nLieu, String nDate, String nTaxon)
813
	{
820
	{
814
		
821
		
815
		String titre = "Observations " ;
822
		String titre = "Observations " ;
816
		
823
		
817
		if(!nLieu.equals(""))
824
		if(!nLieu.equals(""))
818
		{
825
		{
819
			nLieu = nLieu.replaceAll(",", ", ");
826
			nLieu = nLieu.replaceAll(",", ", ");
820
			titre += "  -  Lieu : "+nLieu ;
827
			titre += "  -  Lieu : "+nLieu ;
821
			
828
			
822
		}
829
		}
823
			
830
			
824
		if(!nDate .equals(""))
831
		if(!nDate .equals(""))
825
		{
832
		{
826
			nDate = nDate.replaceAll(",", ", ");
833
			nDate = nDate.replaceAll(",", ", ");
827
			titre += "  -  Date : "+nDate ;
834
			titre += "  -  Date : "+nDate ;
828
		}
835
		}
829
		
836
		
830
		if(!nTaxon .equals(""))
837
		if(!nTaxon .equals(""))
831
		{
838
		{
832
			titre += "  -  Recherche : "+nTaxon ;
839
			titre += "  -  Recherche : "+nTaxon ;
833
		}
840
		}
834
		
841
		
835
		this.setTitle(titre) ;
842
		this.setTitle(titre) ;
836
	}
843
	}
837
 
844
 
838
	public void raz() {
845
	public void raz() {
839
		
846
		
840
		
847
		
841
		// creation du store qui les contient
848
		// creation du store qui les contient
842
		
849
		
843
		FieldDef defEtatObservation = new StringFieldDef("etat_observation");
850
		FieldDef defEtatObservation = new StringFieldDef("etat_observation");
844
		FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
851
		FieldDef defNomSaisiObservation = new StringFieldDef("nomSaisi_observation");
845
		FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
852
		FieldDef defNomRetenuObservation = new StringFieldDef("nomRetenu_observation");
846
		FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
853
		FieldDef defLieuObservation = new StringFieldDef("lieu_observation");
847
		FieldDef defDateObservation = new StringFieldDef("date_observation");
854
		FieldDef defDateObservation = new StringFieldDef("date_observation");
848
		FieldDef defOrdreObservation = new IntegerFieldDef("ordre_observation");
855
		FieldDef defOrdreObservation = new IntegerFieldDef("ordre_observation");
849
		
856
		
850
		// Non affiches :
857
		// Non affiches :
851
		FieldDef defNumeroNomenclaturalSaisiObservation = new StringFieldDef("numeroNomenclaturalSaisi_observation");
858
		FieldDef defNumeroNomenclaturalSaisiObservation = new StringFieldDef("numeroNomenclaturalSaisi_observation");
852
		
859
		
853
		FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation,
860
		FieldDef[] defTab = { defEtatObservation, defNomSaisiObservation, defNomRetenuObservation,
854
				defLieuObservation, defDateObservation, defOrdreObservation };
861
				defLieuObservation, defDateObservation, defOrdreObservation };
855
		
862
		
856
		RecordDef rd = new RecordDef(defTab);
863
		RecordDef rd = new RecordDef(defTab);
857
		st = new Store(rd);
864
		st = new Store(rd);
858
		
865
		
859
		// on associe le store
866
		// on associe le store
860
		
867
		
861
		this.setStore(st);
868
		this.setStore(st);
862
		
869
		
863
	}
870
	}
864
	
871
	
865
	public boolean verifierFormatDate(String date) {
872
	public boolean verifierFormatDate(String date) {
866
		
873
		
867
		String regex = "[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}" ;
874
		String regex = "[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}" ;
868
		if(date.matches(regex) && !date.equals("0000-00-00")) {
875
		if(date.matches(regex) && !date.equals("0000-00-00")) {
869
			return true ;
876
			return true ;
870
		}
877
		}
871
		else {
878
		else {
872
			return false;
879
			return false;
873
		}
880
		}
874
	}
881
	}
875
	
882
	
876
	private String fabriquerLieu(Observation obs) {
883
	private String fabriquerLieu(Observation obs) {
877
		
884
		
878
		String lieuModele = modeleLieu;
885
		String lieuModele = modeleLieu;
879
		
886
		
880
		String commune = obs.getLocalite(); 
887
		String commune = obs.getLocalite(); 
881
		String lieuDit = obs.getLieudit();
888
		String lieuDit = obs.getLieudit();
882
		String station = obs.getStation();
889
		String station = obs.getStation();
883
		
890
		
884
		String lieuCommuneFormate = "";
891
		String lieuCommuneFormate = "";
885
		String lieuDitFormate = "";
892
		String lieuDitFormate = "";
886
		String stationFormatee = "";
893
		String stationFormatee = "";
887
		
894
		
888
		if(commune != null && !commune.contains("000null") && !commune.trim().equals("")) {
895
		if(commune != null && !commune.contains("000null") && !commune.trim().equals("")) {
889
			String	idLoc =obs.getIdentifiantLocalite().replaceAll(" ","/");
896
			String	idLoc =obs.getIdentifiantLocalite().replaceAll(" ","/");
890
			if(idLoc != null && !idLoc.contains("000null") && !idLoc.trim().equals("")) {
897
			if(idLoc != null && !idLoc.contains("000null") && !idLoc.trim().equals("")) {
891
 
898
 
892
				idLoc = idLoc.replaceAll("%","");
899
				idLoc = idLoc.replaceAll("%","");
893
				idLoc = idLoc.replaceAll("\"","");
900
				idLoc = idLoc.replaceAll("\"","");
894
				idLoc = idLoc.replace('\\',' ');
901
				idLoc = idLoc.replace('\\',' ');
895
				idLoc = idLoc.trim();
902
				idLoc = idLoc.trim();
896
				lieuCommuneFormate += idLoc+" - ";
903
				lieuCommuneFormate += idLoc+" - ";
897
			}
904
			}
898
			lieuCommuneFormate += commune;
905
			lieuCommuneFormate += commune;
899
			lieuModele = lieuModele.replaceAll("IDLOCCOMMUNE", lieuCommuneFormate);
906
			lieuModele = lieuModele.replaceAll("IDLOCCOMMUNE", lieuCommuneFormate);
900
		} else {
907
		} else {
901
			
908
			
902
			lieuModele = lieuModele.replaceAll("IDLOCCOMMUNE,", lieuCommuneFormate);
909
			lieuModele = lieuModele.replaceAll("IDLOCCOMMUNE,", lieuCommuneFormate);
903
		}
910
		}
904
		
911
		
905
		if(lieuDit != null && !lieuDit.contains("000null") && !lieuDit.trim().equals("")) {
912
		if(lieuDit != null && !lieuDit.contains("000null") && !lieuDit.trim().equals("")) {
906
			lieuDitFormate += lieuDit;
913
			lieuDitFormate += lieuDit;
907
			lieuModele = lieuModele.replaceAll("LIEUDIT", lieuDitFormate);
914
			lieuModele = lieuModele.replaceAll("LIEUDIT", lieuDitFormate);
908
		} else {
915
		} else {
909
			lieuModele = lieuModele.replaceAll("LIEUDIT,", lieuDitFormate);
916
			lieuModele = lieuModele.replaceAll("LIEUDIT,", lieuDitFormate);
910
		}
917
		}
911
		
918
		
912
		if(station != null && !station.contains("000null") && !station.trim().equals("")) {
919
		if(station != null && !station.contains("000null") && !station.trim().equals("")) {
913
			stationFormatee += station;
920
			stationFormatee += station;
914
			lieuModele = lieuModele.replaceAll("STATION", stationFormatee);
921
			lieuModele = lieuModele.replaceAll("STATION", stationFormatee);
915
		} else {
922
		} else {
916
			lieuModele = lieuModele.replaceAll("STATION", stationFormatee);
923
			lieuModele = lieuModele.replaceAll("STATION", stationFormatee);
917
		}
924
		}
918
		
925
		
919
		lieuModele = lieuModele.trim();
926
		lieuModele = lieuModele.trim();
920
		lieuModele = lieuModele.replaceAll(",$","");
927
		lieuModele = lieuModele.replaceAll(",$","");
921
		lieuModele = lieuModele.replaceAll(",^$",", ");
928
		lieuModele = lieuModele.replaceAll(",^$",", ");
922
		
929
		
923
		return lieuModele;
930
		return lieuModele;
924
	}
931
	}
925
	
932
	
926
	public boolean getTailleInitialisee() {
933
	public boolean getTailleInitialisee() {
927
		return tailleInitialisee ;
934
		return tailleInitialisee ;
928
	}
935
	}
929
	
936
	
930
	public void setTailleInitialisee() {
937
	public void setTailleInitialisee() {
931
		tailleInitialisee = true;
938
		tailleInitialisee = true;
932
	}
939
	}
933
 
940
 
934
}
941
}