Subversion Repositories eFlore/Applications.cel

Rev

Rev 109 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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