Subversion Repositories eFlore/Applications.cel

Rev

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

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