Subversion Repositories eFlore/Applications.cel

Rev

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

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