Subversion Repositories eFlore/Applications.cel

Rev

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

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