Subversion Repositories eFlore/Applications.cel

Rev

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

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