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