Subversion Repositories eFlore/Applications.cel

Rev

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

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