Subversion Repositories eFlore/Applications.cel

Rev

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

Rev 965 Rev 989
1
package org.tela_botanica.client.vues.observation.filtres;
1
package org.tela_botanica.client.vues.observation.filtres;
2
 
2
 
3
import java.util.Comparator;
3
import java.util.Comparator;
4
import java.util.Iterator;
4
import java.util.Iterator;
5
 
5
 
6
import org.tela_botanica.client.interfaces.Filtrable;
6
import org.tela_botanica.client.interfaces.Filtrable;
7
import org.tela_botanica.client.interfaces.Rafraichissable;
7
import org.tela_botanica.client.interfaces.Rafraichissable;
8
import org.tela_botanica.client.modeles.EntiteGeographiqueObservation;
8
import org.tela_botanica.client.modeles.objets.EntiteGeographiqueObservation;
9
import org.tela_botanica.client.modeles.ListeEntiteGeographiqueObservation;
9
import org.tela_botanica.client.modeles.objets.ListeEntiteGeographiqueObservation;
10
import org.tela_botanica.client.modeles.Observation;
10
import org.tela_botanica.client.modeles.objets.Observation;
11
import org.tela_botanica.client.observation.ObservationMediateur;
11
import org.tela_botanica.client.observation.ObservationMediateur;
12
import org.tela_botanica.client.util.Util;
12
import org.tela_botanica.client.util.Util;
13
 
13
 
14
import com.google.gwt.core.client.GWT;
14
import com.google.gwt.core.client.GWT;
15
import com.google.gwt.user.client.Window;
15
import com.google.gwt.user.client.Window;
16
import com.gwtext.client.data.Node;
16
import com.gwtext.client.data.Node;
17
import com.gwtext.client.data.NodeTraversalCallback;
17
import com.gwtext.client.data.NodeTraversalCallback;
18
import com.gwtext.client.data.Tree;
18
import com.gwtext.client.data.Tree;
19
import com.gwtext.client.widgets.Component;
19
import com.gwtext.client.widgets.Component;
20
import com.gwtext.client.widgets.Panel;
20
import com.gwtext.client.widgets.Panel;
21
import com.gwtext.client.widgets.event.PanelListenerAdapter;
21
import com.gwtext.client.widgets.event.PanelListenerAdapter;
22
import com.gwtext.client.widgets.tree.TreeNode;
22
import com.gwtext.client.widgets.tree.TreeNode;
23
import com.gwtext.client.widgets.tree.TreePanel;
23
import com.gwtext.client.widgets.tree.TreePanel;
24
import com.gwtext.client.widgets.tree.event.TreeNodeListenerAdapter;
24
import com.gwtext.client.widgets.tree.event.TreeNodeListenerAdapter;
25
import com.gwtext.client.widgets.tree.event.TreePanelListenerAdapter;
25
import com.gwtext.client.widgets.tree.event.TreePanelListenerAdapter;
26
import com.gwtext.client.core.EventObject;
26
import com.gwtext.client.core.EventObject;
27
 
27
 
28
/**
28
/**
29
 * Arbre Filtrant sur les entites geographiques 
29
 * Arbre Filtrant sur les entites geographiques 
30
 *
30
 *
31
 * 
31
 * 
32
 * @author aurelien + david
32
 * @author aurelien + david
33
 * 
33
 * 
34
 */
34
 */
35
 
35
 
36
 
36
 
37
public class ArbreEntiteGeographiqueObservationFiltreVue extends Panel implements Rafraichissable,
37
public class ArbreEntiteGeographiqueObservationFiltreVue extends Panel implements Rafraichissable,
38
		Filtrable {
38
		Filtrable {
39
 
39
 
40
	/**
40
	/**
41
	 * Le médiateur associé à la vue
41
	 * Le médiateur associé à la vue
42
	 */
42
	 */
43
	private ObservationMediateur	observationMediateur		= null;
43
	private ObservationMediateur	observationMediateur		= null;
44
 
44
 
45
	/**
45
	/**
46
	 * Les localites en cours
46
	 * Les localites en cours
47
	 */
47
	 */
48
	private String entitesGeographiquesEncours = "";
48
	private String entitesGeographiquesEncours = "";
49
 
49
 
50
	/**
50
	/**
51
	 * Le treepanel qui affiche l'arbre
51
	 * Le treepanel qui affiche l'arbre
52
	 */
52
	 */
53
	private TreePanel arbreEntitesGeographiques = null;
53
	private TreePanel arbreEntitesGeographiques = null;
54
 
54
 
55
 
55
 
56
	/**
56
	/**
57
	 * booléen d'initialisation
57
	 * booléen d'initialisation
58
	 */
58
	 */
59
	private boolean estInstancie = false;
59
	private boolean estInstancie = false;
60
 
60
 
61
	/**
61
	/**
62
	 * booléen d'etat
62
	 * booléen d'etat
63
	 */
63
	 */
64
	private boolean filtreModifie = false;
64
	private boolean filtreModifie = false;
65
	private boolean arbreCharge = false ;
65
	private boolean arbreCharge = false ;
66
 
66
 
67
	private String nomFiltre = "" ;
67
	private String nomFiltre = "" ;
68
	
68
	
69
	/**
69
	/**
70
	 * Constructeur sans argument (privé car ne doit pas être utilisé)
70
	 * Constructeur sans argument (privé car ne doit pas être utilisé)
71
	 */
71
	 */
72
	@SuppressWarnings("unused")
72
	@SuppressWarnings("unused")
73
	private ArbreEntiteGeographiqueObservationFiltreVue() {
73
	private ArbreEntiteGeographiqueObservationFiltreVue() {
74
		super();
74
		super();
75
	}
75
	}
76
 
76
 
77
	/**
77
	/**
78
	 * Constructeur avec paramètres
78
	 * Constructeur avec paramètres
79
	 * 
79
	 * 
80
	 * @param im
80
	 * @param im
81
	 *            le médiateur à associer
81
	 *            le médiateur à associer
82
	 */
82
	 */
83
	public ArbreEntiteGeographiqueObservationFiltreVue(ObservationMediateur obs) {
83
	public ArbreEntiteGeographiqueObservationFiltreVue(ObservationMediateur obs) {
84
 
84
 
85
		// on crée le panel
85
		// on crée le panel
86
		super("Localités");
86
		super("Localités");
87
		
87
		
88
		this.observationMediateur = obs;
88
		this.observationMediateur = obs;
89
 
89
 
90
		arbreEntitesGeographiques = new TreePanel();
90
		arbreEntitesGeographiques = new TreePanel();
91
 
91
 
92
		this.setPaddings(5);
92
		this.setPaddings(5);
93
 
93
 
94
		this.setCollapsible(true);
94
		this.setCollapsible(true);
95
	
95
	
96
		this.setAutoScroll(true);
96
		this.setAutoScroll(true);
97
		
97
		
98
 
98
 
99
		// on ajoute les listeners
99
		// on ajoute les listeners
100
		ajouterListenersPanel();
100
		ajouterListenersPanel();
101
		estInstancie = false;
101
		estInstancie = false;
102
	}
102
	}
103
 
103
 
104
	/**
104
	/**
105
	 * Ajoute les listeners pour le rendu du panel
105
	 * Ajoute les listeners pour le rendu du panel
106
	 */
106
	 */
107
	private void ajouterListenersPanel() {
107
	private void ajouterListenersPanel() {
108
		  this.addListener(new PanelListenerAdapter() {
108
		  this.addListener(new PanelListenerAdapter() {
109
 
109
 
110
			// on instancie réellement les composants au moment du rendu pour
110
			// on instancie réellement les composants au moment du rendu pour
111
			// accélérer l'affichage
111
			// accélérer l'affichage
112
			// et éviter des bugs
112
			// et éviter des bugs
113
			public void onRender(Component component) {
113
			public void onRender(Component component) {
114
 
114
 
115
				// on interdit le drag and drop dans l'arbre
115
				// on interdit le drag and drop dans l'arbre
116
				arbreEntitesGeographiques.setEnableDD(false);
116
				arbreEntitesGeographiques.setEnableDD(false);
117
				arbreEntitesGeographiques.setId("x-view-tree-filter-entity");
117
				arbreEntitesGeographiques.setId("x-view-tree-filter-entity");
118
 
118
 
119
				// on crée une racine pour l'arbre
119
				// on crée une racine pour l'arbre
120
				TreeNode root = new TreeNode("Localités");
120
				TreeNode root = new TreeNode("Localités");
121
				root.setId("racine_entite");
121
				root.setId("racine_entite");
122
				String[] usObject = { "Localités" };
122
				String[] usObject = { "Localités" };
123
				root.setUserObject(usObject);
123
				root.setUserObject(usObject);
124
 
124
 
125
				arbreEntitesGeographiques.setRootNode(root);
125
				arbreEntitesGeographiques.setRootNode(root);
126
				arbreEntitesGeographiques.setRootVisible(true);
126
				arbreEntitesGeographiques.setRootVisible(true);
127
				arbreEntitesGeographiques.setBorder(false);
127
				arbreEntitesGeographiques.setBorder(false);
128
				root.setExpandable(true) ;
128
				root.setExpandable(true) ;
129
 
129
 
130
				add(arbreEntitesGeographiques);
130
				add(arbreEntitesGeographiques);
131
 
131
 
132
				// on ajoute les listeners d'évenements
132
				// on ajoute les listeners d'évenements
133
				ajouterListeners();
133
				ajouterListeners();
134
 
134
 
135
				
135
				
136
				// enfin on considère le composant comme instancié
136
				// enfin on considère le composant comme instancié
137
				estInstancie = true;
137
				estInstancie = true;
138
 
138
 
139
				
139
				
140
			}
140
			}
141
 
141
 
142
		});
142
		});
143
	}
143
	}
144
 
144
 
145
	
145
	
146
	
146
	
147
	/**
147
	/**
148
	 * ajoute les listeners pour les boutons et le cochage des entites
148
	 * ajoute les listeners pour les boutons et le cochage des entites
149
	 */
149
	 */
150
	private void ajouterListeners() {
150
	private void ajouterListeners() {
151
		
151
		
152
		arbreEntitesGeographiques.addListener(new TreePanelListenerAdapter() {
152
		arbreEntitesGeographiques.addListener(new TreePanelListenerAdapter() {
153
			
153
			
154
			public void onClick(TreeNode node, EventObject e) {
154
			public void onClick(TreeNode node, EventObject e) {
155
				gererClicNoeud(node);
155
				gererClicNoeud(node);
156
			}
156
			}
157
			
157
			
158
		}) ;
158
		}) ;
159
		
159
		
160
		arbreEntitesGeographiques.getRootNode().addListener(new TreeNodeListenerAdapter() {
160
		arbreEntitesGeographiques.getRootNode().addListener(new TreeNodeListenerAdapter() {
161
			
161
			
162
			public void onExpand(Node node) {
162
			public void onExpand(Node node) {
163
				if(!arbreCharge)
163
				if(!arbreCharge)
164
				{
164
				{
165
					observationMediateur.obtenirListeEntiteGeographique() ;
165
					observationMediateur.obtenirListeEntiteGeographique() ;
166
					arbreCharge = true ;
166
					arbreCharge = true ;
167
				}
167
				}
168
			}
168
			}
169
			
169
			
170
		}) ;
170
		}) ;
171
	}
171
	}
172
	
172
	
173
	private void gererClicNoeud(TreeNode node) {
173
	private void gererClicNoeud(TreeNode node) {
174
		
174
		
175
		mettreAJourValeurEnCours(node);
175
		mettreAJourValeurEnCours(node);
176
		observationMediateur.obtenirNombreObservation() ;
176
		observationMediateur.obtenirNombreObservation() ;
177
	}
177
	}
178
	
178
	
179
	private void mettreAJourValeurEnCours(TreeNode node) {
179
	private void mettreAJourValeurEnCours(TreeNode node) {
180
		
180
		
181
		nomFiltre = "" ;
181
		nomFiltre = "" ;
182
		entitesGeographiquesEncours = "" ;
182
		entitesGeographiquesEncours = "" ;
183
		String nomPere = "" ;
183
		String nomPere = "" ;
184
		String nomGrandPere = "" ;
184
		String nomGrandPere = "" ;
185
		String nomArriereGrandPere = "";
185
		String nomArriereGrandPere = "";
186
		
186
		
187
		switch(node.getDepth()) 
187
		switch(node.getDepth()) 
188
		{
188
		{
189
			case 0:
189
			case 0:
190
				if(!arbreCharge)
190
				if(!arbreCharge)
191
				{
191
				{
192
					arbreEntitesGeographiques.getRootNode().expand();
192
					arbreEntitesGeographiques.getRootNode().expand();
193
				}
193
				}
194
				else 
194
				else 
195
				{
195
				{
196
					observationMediateur.obtenirNombreObservation() ;
196
					observationMediateur.obtenirNombreObservation() ;
197
				}
197
				}
198
				return ;
198
				return ;
199
			case 4: nomFiltre += "station,lieudit,commune,departement";
199
			case 4: nomFiltre += "station,lieudit,commune,departement";
200
			nomPere = ((String[])node.getParentNode().getUserObject())[0] ;
200
			nomPere = ((String[])node.getParentNode().getUserObject())[0] ;
201
			nomGrandPere = ((String[])node.getParentNode().getParentNode().getUserObject())[0] ;
201
			nomGrandPere = ((String[])node.getParentNode().getParentNode().getUserObject())[0] ;
202
			nomArriereGrandPere = ((String[])node.getParentNode().getParentNode().getParentNode().getUserObject())[0] ;
202
			nomArriereGrandPere = ((String[])node.getParentNode().getParentNode().getParentNode().getUserObject())[0] ;
203
			entitesGeographiquesEncours += node.getText()+","+nomPere+","+nomGrandPere+","+nomArriereGrandPere ;
203
			entitesGeographiquesEncours += node.getText()+","+nomPere+","+nomGrandPere+","+nomArriereGrandPere ;
204
			break;
204
			break;
205
			case 3: nomFiltre += "lieudit,commune,departement";
205
			case 3: nomFiltre += "lieudit,commune,departement";
206
				nomPere = ((String[])node.getParentNode().getUserObject())[0] ;
206
				nomPere = ((String[])node.getParentNode().getUserObject())[0] ;
207
				nomGrandPere = ((String[])node.getParentNode().getParentNode().getUserObject())[0] ;
207
				nomGrandPere = ((String[])node.getParentNode().getParentNode().getUserObject())[0] ;
208
				entitesGeographiquesEncours += node.getText()+","+nomPere+","+nomGrandPere ;
208
				entitesGeographiquesEncours += node.getText()+","+nomPere+","+nomGrandPere ;
209
				break;
209
				break;
210
			case 2: nomFiltre += "commune,departement"; 
210
			case 2: nomFiltre += "commune,departement"; 
211
				nomPere = ((String[])node.getParentNode().getUserObject())[0] ;
211
				nomPere = ((String[])node.getParentNode().getUserObject())[0] ;
212
				entitesGeographiquesEncours += node.getText()+","+nomPere ;
212
				entitesGeographiquesEncours += node.getText()+","+nomPere ;
213
				break;
213
				break;
214
			case 1: nomFiltre += "departement"; 
214
			case 1: nomFiltre += "departement"; 
215
				entitesGeographiquesEncours += node.getText() ;
215
				entitesGeographiquesEncours += node.getText() ;
216
				break;
216
				break;
217
			default: 
217
			default: 
218
				break;
218
				break;
219
		}
219
		}
220
		
220
		
221
		filtreModifie = true ;
221
		filtreModifie = true ;
222
	}
222
	}
223
	
223
	
224
	public void initialiser() {
224
	public void initialiser() {
225
		
225
		
226
		arbreCharge = false ;
226
		arbreCharge = false ;
227
		entitesGeographiquesEncours = "";
227
		entitesGeographiquesEncours = "";
228
		arbreEntitesGeographiques.collapseAll();
228
		arbreEntitesGeographiques.collapseAll();
229
		// on vide l'ancien arbre
229
		// on vide l'ancien arbre
230
		Node[] rootChild = arbreEntitesGeographiques.getRootNode().getChildNodes();
230
		Node[] rootChild = arbreEntitesGeographiques.getRootNode().getChildNodes();
231
		for (int i = 0; i < rootChild.length; i++) {
231
		for (int i = 0; i < rootChild.length; i++) {
232
			
232
			
233
			rootChild[i].remove();
233
			rootChild[i].remove();
234
		}
234
		}
235
		
235
		
236
		arbreEntitesGeographiques.getRootNode().addListener(new TreeNodeListenerAdapter() {
236
		arbreEntitesGeographiques.getRootNode().addListener(new TreeNodeListenerAdapter() {
237
			
237
			
238
			public void onExpand(Node node) {
238
			public void onExpand(Node node) {
239
				if(!arbreCharge)
239
				if(!arbreCharge)
240
				{
240
				{
241
					observationMediateur.obtenirListeEntiteGeographique() ;
241
					observationMediateur.obtenirListeEntiteGeographique() ;
242
					arbreCharge = true ;
242
					arbreCharge = true ;
243
				}
243
				}
244
			}
244
			}
245
			
245
			
246
		}) ;
246
		}) ;
247
	}
247
	}
248
 
248
 
249
	/**
249
	/**
250
	 * Méthode héritée de l'interface rafraichissable
250
	 * Méthode héritée de l'interface rafraichissable
251
	 */
251
	 */
252
	public void rafraichir(Object nouvelleDonnees,
252
	public void rafraichir(Object nouvelleDonnees,
253
			boolean repandreRaffraichissement) {
253
			boolean repandreRaffraichissement) {
254
 
254
 
255
		
255
		
256
		if (nouvelleDonnees instanceof ListeEntiteGeographiqueObservation) {
256
		if (nouvelleDonnees instanceof ListeEntiteGeographiqueObservation) {
257
		
257
		
258
			ListeEntiteGeographiqueObservation data = (ListeEntiteGeographiqueObservation) nouvelleDonnees ;
258
			ListeEntiteGeographiqueObservation data = (ListeEntiteGeographiqueObservation) nouvelleDonnees ;
259
		
259
		
260
				// on crée un arbre vide
260
				// on crée un arbre vide
261
				Tree nouvelArbre = new Tree() ;
261
				Tree nouvelArbre = new Tree() ;
262
				TreeNode root = new TreeNode();
262
				TreeNode root = new TreeNode();
263
				root.setId("racine_entite");
263
				root.setId("racine_entite");
264
				root.setText("Localités");
264
				root.setText("Localités");
265
				String[] usObjRoot = { "Localités"};
265
				String[] usObjRoot = { "Localités"};
266
				root.setUserObject(usObjRoot);
266
				root.setUserObject(usObjRoot);
267
				nouvelArbre.setRootNode(root);
267
				nouvelArbre.setRootNode(root);
268
				
268
				
269
				// on vide tous les noeuds
269
				// on vide tous les noeuds
270
				arbreEntitesGeographiques.getRootNode().eachChild(new NodeTraversalCallback() {
270
				arbreEntitesGeographiques.getRootNode().eachChild(new NodeTraversalCallback() {
271
	
271
	
272
					public boolean execute(Node node) {
272
					public boolean execute(Node node) {
273
						node.remove();
273
						node.remove();
274
						return true;
274
						return true;
275
					}
275
					}
276
				});
276
				});
277
			
277
			
278
			// on la parse et on récupère les informations qui nous interessent
278
			// on la parse et on récupère les informations qui nous interessent
279
			for (Iterator<String> it= data.keySet().iterator(); it.hasNext();) {
279
			for (Iterator<String> it= data.keySet().iterator(); it.hasNext();) {
280
				
280
				
281
					EntiteGeographiqueObservation ent=(EntiteGeographiqueObservation) data.get(it.next());
281
					EntiteGeographiqueObservation ent=(EntiteGeographiqueObservation) data.get(it.next());
282
					creerHierarchieNoeud(nouvelArbre ,root, ent);
282
					creerHierarchieNoeud(nouvelArbre ,root, ent);
283
					doLayout();
283
					doLayout();
284
				}
284
				}
285
			
285
			
286
				copierFilsNoeud(root, arbreEntitesGeographiques.getRootNode());
286
				copierFilsNoeud(root, arbreEntitesGeographiques.getRootNode());
287
				arbreEntitesGeographiques.getRootNode().sort(comparerNoeuds()) ;
287
				arbreEntitesGeographiques.getRootNode().sort(comparerNoeuds()) ;
288
 
288
 
289
				// si l'arbre n'était pas encore considéré comme instancié
289
				// si l'arbre n'était pas encore considéré comme instancié
290
				
290
				
291
				if (!estInstancie) {
291
				if (!estInstancie) {
292
					// on signale que oui
292
					// on signale que oui
293
					estInstancie = true;
293
					estInstancie = true;
294
				}
294
				}
295
	
295
	
296
				// l'état du filtre est réinitialisé
296
				// l'état du filtre est réinitialisé
297
				filtreModifie = false;
297
				filtreModifie = false;
298
				
298
				
299
				//show() ;
299
				//show() ;
300
				arbreEntitesGeographiques.doLayout();
300
				arbreEntitesGeographiques.doLayout();
301
 
301
 
302
			}
302
			}
303
		
303
		
304
		if(nouvelleDonnees instanceof Observation)
304
		if(nouvelleDonnees instanceof Observation)
305
		{	
305
		{	
306
			// Cas d'ajout unitaire d'une observation
306
			// Cas d'ajout unitaire d'une observation
307
			
307
			
308
			// si l'arbre n'est pas encore chargé, on ne tient pas compte de l'ajout
308
			// si l'arbre n'est pas encore chargé, on ne tient pas compte de l'ajout
309
			// l'arbre complet sera de toute façon renvoyé plus tard lors du premier chargement
309
			// l'arbre complet sera de toute façon renvoyé plus tard lors du premier chargement
310
			// de l'arbre
310
			// de l'arbre
311
			if(!arbreCharge) {
311
			if(!arbreCharge) {
312
				return;
312
				return;
313
			}
313
			}
314
			
314
			
315
			Observation obs = (Observation)nouvelleDonnees ;
315
			Observation obs = (Observation)nouvelleDonnees ;
316
			EntiteGeographiqueObservation ent = new EntiteGeographiqueObservation(obs.getIdentifiantLocalite(),obs.getLocalite(),obs.getLieudit(),obs.getStation());
316
			EntiteGeographiqueObservation ent = new EntiteGeographiqueObservation(obs.getIdentifiantLocalite(),obs.getLocalite(),obs.getLieudit(),obs.getStation());
317
			
317
			
318
			creerHierarchieNoeud(arbreEntitesGeographiques.getTree(), arbreEntitesGeographiques.getRootNode(), ent);
318
			creerHierarchieNoeud(arbreEntitesGeographiques.getTree(), arbreEntitesGeographiques.getRootNode(), ent);
319
						
319
						
320
			doLayout();				
320
			doLayout();				
321
			arbreEntitesGeographiques.doLayout() ;
321
			arbreEntitesGeographiques.doLayout() ;
322
		}
322
		}
323
	}
323
	}
324
 
324
 
325
 
325
 
326
	/**
326
	/**
327
	 * Accesseur pour le panneau contenant l'arbre
327
	 * Accesseur pour le panneau contenant l'arbre
328
	 * 
328
	 * 
329
	 * @return le panneau de l'arbre des mots clés
329
	 * @return le panneau de l'arbre des mots clés
330
	 */
330
	 */
331
	public TreePanel getArbreMotsCles() {
331
	public TreePanel getArbreMotsCles() {
332
		return arbreEntitesGeographiques;
332
		return arbreEntitesGeographiques;
333
	}
333
	}
334
 
334
 
335
	/**
335
	/**
336
	 * Méthode héritée de Filtrable renvoie le nom du filtre
336
	 * Méthode héritée de Filtrable renvoie le nom du filtre
337
	 */
337
	 */
338
	public String renvoyerNomFiltre() {
338
	public String renvoyerNomFiltre() {
339
 
339
 
340
		return "Localités";
340
		return "Localités";
341
	}
341
	}
342
 
342
 
343
	/**
343
	/**
344
	 * Renvoie un tableau contenant le nom du champ à filtrer et la valeur
344
	 * Renvoie un tableau contenant le nom du champ à filtrer et la valeur
345
	 * 
345
	 * 
346
	 * @return un tableau contenant le nom du champ à filtrer et sa valeur
346
	 * @return un tableau contenant le nom du champ à filtrer et sa valeur
347
	 */
347
	 */
348
	public String[] renvoyerValeursAFiltrer() {
348
	public String[] renvoyerValeursAFiltrer() {
349
 
349
 
350
		valider();
350
		valider();
351
		
351
		
352
		String valeursFiltrees[] = {nomFiltre, entitesGeographiquesEncours } ;
352
		String valeursFiltrees[] = {nomFiltre, entitesGeographiquesEncours } ;
353
 
353
 
354
		return valeursFiltrees;
354
		return valeursFiltrees;
355
	}
355
	}
356
 
356
 
357
	/**
357
	/**
358
	 * Fonction récursive qui prend deux noeuds d'arbre en paramètre et crée un
358
	 * Fonction récursive qui prend deux noeuds d'arbre en paramètre et crée un
359
	 * copie du sous arbre du premier noeud, qu'elle concatène au deuxième
359
	 * copie du sous arbre du premier noeud, qu'elle concatène au deuxième
360
	 * 
360
	 * 
361
	 * @param ndPereOriginal
361
	 * @param ndPereOriginal
362
	 *            le père des noeuds de l'arbre original
362
	 *            le père des noeuds de l'arbre original
363
	 * @param ndPereCopie
363
	 * @param ndPereCopie
364
	 *            le père qui va recevoir les copies
364
	 *            le père qui va recevoir les copies
365
	 */
365
	 */
366
	private void copierFilsNoeud(Node ndPereOriginal, TreeNode ndPereCopie) {
366
	private void copierFilsNoeud(Node ndPereOriginal, TreeNode ndPereCopie) {
367
		if (ndPereCopie != null && ndPereOriginal != null) {
367
		if (ndPereCopie != null && ndPereOriginal != null) {
368
			Node[] ndNodeFils = ndPereOriginal.getChildNodes();
368
			Node[] ndNodeFils = ndPereOriginal.getChildNodes();
369
 
369
 
370
			for (int i = 0; i < ndNodeFils.length; i++) {
370
			for (int i = 0; i < ndNodeFils.length; i++) {
371
 
371
 
372
				String[] usObj = (String[]) ndNodeFils[i].getUserObject();
372
				String[] usObj = (String[]) ndNodeFils[i].getUserObject();
373
				TreeNode child = new TreeNode(usObj[0]);
373
				TreeNode child = new TreeNode(usObj[0]);
374
				child.setUserObject(usObj);
374
				child.setUserObject(usObj);
375
				child.setId(""+usObj[1]);
375
				child.setId(""+usObj[1]);
376
				ndPereCopie.appendChild(child);
376
				ndPereCopie.appendChild(child);
377
 
377
 
378
				if (!ndNodeFils[i].isLeaf()) {
378
				if (!ndNodeFils[i].isLeaf()) {
379
					copierFilsNoeud(ndNodeFils[i], child);
379
					copierFilsNoeud(ndNodeFils[i], child);
380
				}
380
				}
381
 
381
 
382
			}
382
			}
383
		}
383
		}
384
	}
384
	}
385
 
385
 
386
	/**
386
	/**
387
	 * Méthode héritée de Filtrable Renvoie l'état du filtre (modifié ou non)
387
	 * Méthode héritée de Filtrable Renvoie l'état du filtre (modifié ou non)
388
	 */
388
	 */
389
	public boolean renvoyerEtatFiltre() {
389
	public boolean renvoyerEtatFiltre() {
390
 
390
 
391
		return filtreModifie;
391
		return filtreModifie;
392
	}
392
	}
393
 
393
 
394
	public void valider() {
394
	public void valider() {
395
		
395
		
396
		if (estInstancie) {
396
		if (estInstancie) {
397
			
397
			
398
		}
398
		}
399
	}
399
	}
400
	
400
	
401
	public Comparator<TreeNode> comparerNoeuds()
401
	public Comparator<TreeNode> comparerNoeuds()
402
	{
402
	{
403
		return new Comparator<TreeNode>() {
403
		return new Comparator<TreeNode>() {
404
 
404
 
405
			public int compare(TreeNode o1, TreeNode o2) {
405
			public int compare(TreeNode o1, TreeNode o2) {
406
				
406
				
407
				if(o1.getText().equals("Inconnue")) {
407
				if(o1.getText().equals("Inconnue")) {
408
					return -1 ;
408
					return -1 ;
409
				}
409
				}
410
				
410
				
411
				if(o2.getText().equals("Inconnue")) {
411
				if(o2.getText().equals("Inconnue")) {
412
					return 1 ;
412
					return 1 ;
413
				}
413
				}
414
				
414
				
415
				if(o1.getDepth() == 1 && o2.getDepth() == 1)
415
				if(o1.getDepth() == 1 && o2.getDepth() == 1)
416
				{
416
				{
417
					String l1 = o1.getText() ;
417
					String l1 = o1.getText() ;
418
					String l2 = o2.getText() ;
418
					String l2 = o2.getText() ;
419
					if(l1.length() == 1) {
419
					if(l1.length() == 1) {
420
						l1 = "0"+l1;
420
						l1 = "0"+l1;
421
					}
421
					}
422
					
422
					
423
					if(l2.length() == 1) {
423
					if(l2.length() == 1) {
424
						l2 = "0"+l2;
424
						l2 = "0"+l2;
425
					}
425
					}
426
					
426
					
427
					Integer n1 = 0;
427
					Integer n1 = 0;
428
					Integer n2 = 0;
428
					Integer n2 = 0;
429
					
429
					
430
					try{
430
					try{
431
						n1 = Integer.parseInt(l1) ;
431
						n1 = Integer.parseInt(l1) ;
432
						n2 = Integer.parseInt(l2) ;
432
						n2 = Integer.parseInt(l2) ;
433
					} catch(NumberFormatException ne)  {
433
					} catch(NumberFormatException ne)  {
434
						n1 = 0;
434
						n1 = 0;
435
						n2 = 0;
435
						n2 = 0;
436
					}
436
					}
437
					
437
					
438
					return n1.compareTo(n2) ;
438
					return n1.compareTo(n2) ;
439
				}
439
				}
440
				else
440
				else
441
				{
441
				{
442
					String n1 = o1.getId() ;
442
					String n1 = o1.getId() ;
443
					String n2 = o2.getId() ;
443
					String n2 = o2.getId() ;
444
									
444
									
445
				
445
				
446
					return  n1.compareToIgnoreCase(n2);
446
					return  n1.compareToIgnoreCase(n2);
447
				}
447
				}
448
			}
448
			}
449
		} ;
449
		} ;
450
	}
450
	}
451
 
451
 
452
	public void raz() {
452
	public void raz() {
453
		
453
		
454
		arbreCharge = false ;
454
		arbreCharge = false ;
455
		arbreEntitesGeographiques.collapseAll();
455
		arbreEntitesGeographiques.collapseAll();
456
		arbreEntitesGeographiques.clear() ;
456
		arbreEntitesGeographiques.clear() ;
457
		
457
		
458
		// on crée une racine pour l'arbre
458
		// on crée une racine pour l'arbre
459
		TreeNode root = new TreeNode("Localités");
459
		TreeNode root = new TreeNode("Localités");
460
		root.setId("racine_entite");
460
		root.setId("racine_entite");
461
		String[] usObject = { "Localités" };
461
		String[] usObject = { "Localités" };
462
		root.setUserObject(usObject);
462
		root.setUserObject(usObject);
463
 
463
 
464
		arbreEntitesGeographiques.setRootNode(root);
464
		arbreEntitesGeographiques.setRootNode(root);
465
		
465
		
466
		arbreEntitesGeographiques.getRootNode().addListener(new TreeNodeListenerAdapter() {
466
		arbreEntitesGeographiques.getRootNode().addListener(new TreeNodeListenerAdapter() {
467
			
467
			
468
			public void onExpand(Node node) {
468
			public void onExpand(Node node) {
469
				if(!arbreCharge)
469
				if(!arbreCharge)
470
				{
470
				{
471
					observationMediateur.obtenirDatesObservation() ;
471
					observationMediateur.obtenirDatesObservation() ;
472
					arbreCharge = true ;
472
					arbreCharge = true ;
473
				}
473
				}
474
			}
474
			}
475
			
475
			
476
		}) ;
476
		}) ;
477
		
477
		
478
		entitesGeographiquesEncours  = "";
478
		entitesGeographiquesEncours  = "";
479
		
479
		
480
	}
480
	}
481
	
481
	
482
	private TreeNode creerNoeud(String id, String texte) {
482
	private TreeNode creerNoeud(String id, String texte) {
483
		
483
		
484
		TreeNode nouveauNoeud = new TreeNode();
484
		TreeNode nouveauNoeud = new TreeNode();
485
		nouveauNoeud.setId(""+(id));
485
		nouveauNoeud.setId(""+(id));
486
		nouveauNoeud.setText(texte);
486
		nouveauNoeud.setText(texte);
487
		String[] usObj = {texte,id+""};
487
		String[] usObj = {texte,id+""};
488
		nouveauNoeud.setUserObject(usObj);
488
		nouveauNoeud.setUserObject(usObj);
489
		
489
		
490
		return nouveauNoeud;
490
		return nouveauNoeud;
491
	}
491
	}
492
	
492
	
493
	/**
493
	/**
494
	 * 
494
	 * 
495
	 * @param arbre l'arbre dans lequel on recherche s'il faut créer les noeuds
495
	 * @param arbre l'arbre dans lequel on recherche s'il faut créer les noeuds
496
	 * @param root le noeud racine auquel on concatène la hierarchie crée
496
	 * @param root le noeud racine auquel on concatène la hierarchie crée
497
	 * @param ent l'entité géographique qui doit être décomposée en arborescence
497
	 * @param ent l'entité géographique qui doit être décomposée en arborescence
498
	 * @return
498
	 * @return
499
	 */
499
	 */
500
	private void creerHierarchieNoeud(Tree arbre, TreeNode root, EntiteGeographiqueObservation ent) {
500
	private void creerHierarchieNoeud(Tree arbre, TreeNode root, EntiteGeographiqueObservation ent) {
501
		
501
		
502
		String id_zone_geo=null;
502
		String id_zone_geo=null;
503
		String zone_geo=null;
503
		String zone_geo=null;
504
		String lieuDit=null;
504
		String lieuDit=null;
505
		String station=null;
505
		String station=null;
506
		
506
		
507
		// TODO creer une fonction plus efficace lors du passage au multi reférentiel
507
		// TODO creer une fonction plus efficace lors du passage au multi reférentiel
508
		id_zone_geo = Util.convertirChaineZoneGeoVersDepartement(ent.getIdZoneGeo());
508
		id_zone_geo = Util.convertirChaineZoneGeoVersDepartement(ent.getIdZoneGeo());
509
		
509
		
510
		id_zone_geo = id_zone_geo.replaceAll("\"", "");
510
		id_zone_geo = id_zone_geo.replaceAll("\"", "");
511
		id_zone_geo = id_zone_geo.replace('\\',' ');
511
		id_zone_geo = id_zone_geo.replace('\\',' ');
512
		id_zone_geo = id_zone_geo.trim();
512
		id_zone_geo = id_zone_geo.trim();
513
		zone_geo = ent.getZoneGeo();
513
		zone_geo = ent.getZoneGeo();
514
		lieuDit = ent.getLieuDit();
514
		lieuDit = ent.getLieuDit();
515
		station = ent.getStation();
515
		station = ent.getStation();
516
		
516
		
517
		if(id_zone_geo.contains("000null") || id_zone_geo.equals(null) || (id_zone_geo.trim()).equals("")) {
517
		if(id_zone_geo.contains("000null") || id_zone_geo.equals(null) || (id_zone_geo.trim()).equals("")) {
518
			id_zone_geo="Inconnue" ;
518
			id_zone_geo="Inconnue" ;
519
		}
519
		}
520
		
520
		
521
		if(zone_geo.contains("000null") || zone_geo.equals(null) || (zone_geo.trim().equals(""))) {
521
		if(zone_geo.contains("000null") || zone_geo.equals(null) || (zone_geo.trim().equals(""))) {
522
			zone_geo="Inconnue" ;
522
			zone_geo="Inconnue" ;
523
		}
523
		}
524
		
524
		
525
		if(lieuDit.contains("000null") || lieuDit.equals(null) || (lieuDit.trim().equals(""))) {
525
		if(lieuDit.contains("000null") || lieuDit.equals(null) || (lieuDit.trim().equals(""))) {
526
			lieuDit="Inconnue" ;
526
			lieuDit="Inconnue" ;
527
		}
527
		}
528
		
528
		
529
		if(station.contains("000null") || station.equals(null) || (station.trim().equals(""))) {
529
		if(station.contains("000null") || station.equals(null) || (station.trim().equals(""))) {
530
			station="Inconnue" ;
530
			station="Inconnue" ;
531
		}
531
		}
532
		
532
		
533
		Node noeudMemeId = arbre.getNodeById(""+id_zone_geo);		
533
		Node noeudMemeId = arbre.getNodeById(""+id_zone_geo);		
534
		if(noeudMemeId == null) {
534
		if(noeudMemeId == null) {
535
			// on crée le noeud de l'identifiant zone_geo
535
			// on crée le noeud de l'identifiant zone_geo
536
			noeudMemeId = creerNoeud(""+id_zone_geo,id_zone_geo);
536
			noeudMemeId = creerNoeud(""+id_zone_geo,id_zone_geo);
537
			root.appendChild(noeudMemeId) ;
537
			root.appendChild(noeudMemeId) ;
538
		}
538
		}
539
		
539
		
540
		// on teste si la localité existe
540
		// on teste si la localité existe
541
		Node noeudMemeLoc = arbre.getNodeById(""+(id_zone_geo+zone_geo));
541
		Node noeudMemeLoc = arbre.getNodeById(""+(id_zone_geo+zone_geo));
542
		if(noeudMemeLoc == null)
542
		if(noeudMemeLoc == null)
543
		{
543
		{
544
			//  on crée le noeud de la zone_geo
544
			//  on crée le noeud de la zone_geo
545
			noeudMemeLoc = creerNoeud(""+id_zone_geo+zone_geo, zone_geo);							
545
			noeudMemeLoc = creerNoeud(""+id_zone_geo+zone_geo, zone_geo);							
546
			noeudMemeId.appendChild(noeudMemeLoc) ;
546
			noeudMemeId.appendChild(noeudMemeLoc) ;
547
		}
547
		}
548
		
548
		
549
		// on teste si le lieu dit existe
549
		// on teste si le lieu dit existe
550
		Node noeudMemeLieu = arbre.getNodeById(""+(id_zone_geo+zone_geo+lieuDit));
550
		Node noeudMemeLieu = arbre.getNodeById(""+(id_zone_geo+zone_geo+lieuDit));
551
		if(noeudMemeLieu == null)
551
		if(noeudMemeLieu == null)
552
		{
552
		{
553
			// on crée le noeud du lieu dit
553
			// on crée le noeud du lieu dit
554
			noeudMemeLieu = creerNoeud(id_zone_geo+zone_geo+lieuDit, lieuDit);	
554
			noeudMemeLieu = creerNoeud(id_zone_geo+zone_geo+lieuDit, lieuDit);	
555
			noeudMemeLoc.appendChild(noeudMemeLieu) ;
555
			noeudMemeLoc.appendChild(noeudMemeLieu) ;
556
		}
556
		}
557
		
557
		
558
		// on teste si la station existe
558
		// on teste si la station existe
559
		Node noeudMemeStation = arbre.getNodeById(""+(id_zone_geo+zone_geo+lieuDit+station));
559
		Node noeudMemeStation = arbre.getNodeById(""+(id_zone_geo+zone_geo+lieuDit+station));
560
		if(noeudMemeStation == null) {
560
		if(noeudMemeStation == null) {
561
			// on crée le noeud de la station
561
			// on crée le noeud de la station
562
			noeudMemeStation = creerNoeud(id_zone_geo+zone_geo+lieuDit+station,station);
562
			noeudMemeStation = creerNoeud(id_zone_geo+zone_geo+lieuDit+station,station);
563
			noeudMemeLieu.appendChild(noeudMemeStation);
563
			noeudMemeLieu.appendChild(noeudMemeStation);
564
		}
564
		}
565
				
565
				
566
		root.sort(comparerNoeuds()) ;
566
		root.sort(comparerNoeuds()) ;
567
	}
567
	}
568
 
568
 
569
	@Override
569
	@Override
570
	public void viderFiltre() {
570
	public void viderFiltre() {
571
		arbreEntitesGeographiques.getSelectionModel().clearSelections();
571
		arbreEntitesGeographiques.getSelectionModel().clearSelections();
572
		entitesGeographiquesEncours ="";
572
		entitesGeographiquesEncours ="";
573
	}
573
	}
574
 
574
 
575
	public void viderFiltre(String nom) {
575
	public void viderFiltre(String nom) {
576
		
576
		
577
		final int profondeur = calculerProfondeurPourNomFiltre(nom);
577
		final int profondeur = calculerProfondeurPourNomFiltre(nom);
578
		
578
		
579
		// on vide tous les noeuds
579
		// on vide tous les noeuds
580
		arbreEntitesGeographiques.getRootNode().cascade(new NodeTraversalCallback() {
580
		arbreEntitesGeographiques.getRootNode().cascade(new NodeTraversalCallback() {
581
 
581
 
582
			public boolean execute(Node node) {
582
			public boolean execute(Node node) {
583
				
583
				
584
				boolean continuer = true;
584
				boolean continuer = true;
585
				
585
				
586
				TreeNode noeudArbreEncours = (TreeNode)node;
586
				TreeNode noeudArbreEncours = (TreeNode)node;
587
				
587
				
588
				if(arbreEntitesGeographiques.getSelectionModel().isSelected(noeudArbreEncours)) {
588
				if(arbreEntitesGeographiques.getSelectionModel().isSelected(noeudArbreEncours)) {
589
					
589
					
590
					int profondeurDepart = noeudArbreEncours.getDepth();
590
					int profondeurDepart = noeudArbreEncours.getDepth();
591
					
591
					
592
					for(int profondeurNoeudArbreEncours = profondeurDepart; profondeurNoeudArbreEncours >= profondeur; profondeurNoeudArbreEncours--) {
592
					for(int profondeurNoeudArbreEncours = profondeurDepart; profondeurNoeudArbreEncours >= profondeur; profondeurNoeudArbreEncours--) {
593
						noeudArbreEncours = (TreeNode)noeudArbreEncours.getParentNode();
593
						noeudArbreEncours = (TreeNode)noeudArbreEncours.getParentNode();
594
					}
594
					}
595
					
595
					
596
					arbreEntitesGeographiques.getSelectionModel().select(noeudArbreEncours); 
596
					arbreEntitesGeographiques.getSelectionModel().select(noeudArbreEncours); 
597
					mettreAJourValeurEnCours(noeudArbreEncours);
597
					mettreAJourValeurEnCours(noeudArbreEncours);
598
					
598
					
599
					continuer = false;
599
					continuer = false;
600
				}
600
				}
601
				
601
				
602
				return continuer;
602
				return continuer;
603
			}
603
			}
604
 
604
 
605
		});
605
		});
606
	}
606
	}
607
	
607
	
608
	private int calculerProfondeurPourNomFiltre(String nom) {
608
	private int calculerProfondeurPourNomFiltre(String nom) {
609
		
609
		
610
		int profondeur = 0;
610
		int profondeur = 0;
611
		
611
		
612
		if(nom.equals("departement")) {
612
		if(nom.equals("departement")) {
613
			profondeur = 1;
613
			profondeur = 1;
614
		}
614
		}
615
		
615
		
616
		if(nom.equals("commune")) {
616
		if(nom.equals("commune")) {
617
			profondeur = 2;
617
			profondeur = 2;
618
		}
618
		}
619
		
619
		
620
		if(nom.equals("lieudit")) {
620
		if(nom.equals("lieudit")) {
621
			profondeur = 3;
621
			profondeur = 3;
622
		}
622
		}
623
		
623
		
624
		if(nom.equals("station")) {
624
		if(nom.equals("station")) {
625
			profondeur = 4;
625
			profondeur = 4;
626
		}
626
		}
627
		
627
		
628
		return profondeur;
628
		return profondeur;
629
	}
629
	}
630
	
630
	
631
}
631
}