Subversion Repositories eFlore/Applications.cel

Rev

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

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