| 54 |
david |
1 |
package org.tela_botanica.client.vues;
|
|
|
2 |
|
| 68 |
david |
3 |
import java.util.Iterator;
|
|
|
4 |
|
| 54 |
david |
5 |
import org.tela_botanica.client.interfaces.Filtrable;
|
|
|
6 |
import org.tela_botanica.client.interfaces.Rafraichissable;
|
| 68 |
david |
7 |
import org.tela_botanica.client.modeles.EntiteGeographiqueObservation;
|
|
|
8 |
import org.tela_botanica.client.modeles.ListeEntiteGeographiqueObservation;
|
| 54 |
david |
9 |
import org.tela_botanica.client.observation.ObservationMediateur;
|
|
|
10 |
|
| 72 |
david |
11 |
import com.google.gwt.core.client.GWT;
|
| 68 |
david |
12 |
import com.google.gwt.json.client.JSONArray;
|
|
|
13 |
import com.google.gwt.json.client.JSONObject;
|
|
|
14 |
import com.google.gwt.user.client.Window;
|
| 54 |
david |
15 |
import com.google.gwt.user.client.ui.Label;
|
|
|
16 |
import com.gwtext.client.data.Node;
|
|
|
17 |
import com.gwtext.client.data.NodeTraversalCallback;
|
|
|
18 |
import com.gwtext.client.data.Tree;
|
| 87 |
jpm |
19 |
import com.gwtext.client.data.event.NodeListenerAdapter;
|
| 54 |
david |
20 |
import com.gwtext.client.widgets.Component;
|
|
|
21 |
import com.gwtext.client.widgets.Panel;
|
|
|
22 |
import com.gwtext.client.widgets.event.PanelListenerAdapter;
|
|
|
23 |
import com.gwtext.client.widgets.tree.TreeNode;
|
|
|
24 |
import com.gwtext.client.widgets.tree.TreePanel;
|
| 87 |
jpm |
25 |
import com.gwtext.client.widgets.tree.event.TreeNodeListenerAdapter;
|
| 85 |
jpm |
26 |
import com.gwtext.client.widgets.tree.event.TreePanelListenerAdapter;
|
|
|
27 |
import com.gwtext.client.core.EventObject;
|
| 54 |
david |
28 |
|
|
|
29 |
/**
|
|
|
30 |
* fenêtre de recherche affichant l'arbre des mots clés en lecture et un bouton
|
|
|
31 |
* cliquable
|
|
|
32 |
*
|
|
|
33 |
* @author aurelien
|
|
|
34 |
*
|
|
|
35 |
*/
|
| 68 |
david |
36 |
public class ArbreEntiteGeographiqueObservationFiltreVue extends Panel implements Rafraichissable,
|
| 54 |
david |
37 |
Filtrable {
|
|
|
38 |
|
|
|
39 |
/**
|
|
|
40 |
* Le médiateur associé à la vue
|
|
|
41 |
*/
|
|
|
42 |
private ObservationMediateur observationMediateur = null;
|
|
|
43 |
|
|
|
44 |
/**
|
|
|
45 |
* Les localites en cours
|
|
|
46 |
*/
|
| 68 |
david |
47 |
private String entitesGeographiquesEncours = "";
|
| 54 |
david |
48 |
|
|
|
49 |
/**
|
|
|
50 |
* Le treepanel qui affiche l'arbre
|
|
|
51 |
*/
|
| 68 |
david |
52 |
private TreePanel arbreEntitesGeographiques = null;
|
| 54 |
david |
53 |
|
| 68 |
david |
54 |
|
|
|
55 |
|
| 54 |
david |
56 |
/**
|
| 68 |
david |
57 |
* La structure de donnees qui stocke l'arbre. Utilisee a ce niveau car trop liee a la vue
|
|
|
58 |
*/
|
|
|
59 |
|
|
|
60 |
private Tree donneeEntitesGeographiques = new Tree();;
|
|
|
61 |
|
|
|
62 |
/**
|
| 54 |
david |
63 |
* booléen d'initialisation
|
|
|
64 |
*/
|
|
|
65 |
private boolean estInstancie = false;
|
|
|
66 |
|
|
|
67 |
/**
|
|
|
68 |
* booléen d'etat
|
|
|
69 |
*/
|
|
|
70 |
private boolean filtreModifie = false;
|
| 85 |
jpm |
71 |
|
|
|
72 |
private boolean arbreCharge = false ;
|
|
|
73 |
|
| 86 |
jpm |
74 |
private String nomFiltre = "" ;
|
|
|
75 |
|
| 54 |
david |
76 |
/**
|
|
|
77 |
* Constructeur sans argument (privé car ne doit pas être utilisé)
|
|
|
78 |
*/
|
|
|
79 |
@SuppressWarnings("unused")
|
| 68 |
david |
80 |
private ArbreEntiteGeographiqueObservationFiltreVue() {
|
| 54 |
david |
81 |
super();
|
|
|
82 |
}
|
|
|
83 |
|
|
|
84 |
/**
|
|
|
85 |
* Constructeur avec paramètres
|
|
|
86 |
*
|
|
|
87 |
* @param im
|
|
|
88 |
* le médiateur à associer
|
|
|
89 |
*/
|
| 68 |
david |
90 |
public ArbreEntiteGeographiqueObservationFiltreVue(ObservationMediateur obs) {
|
| 54 |
david |
91 |
|
|
|
92 |
// on crée le panel
|
| 70 |
david |
93 |
super("Localité");
|
| 54 |
david |
94 |
|
|
|
95 |
this.observationMediateur = obs;
|
|
|
96 |
|
| 68 |
david |
97 |
arbreEntitesGeographiques = new TreePanel();
|
| 54 |
david |
98 |
|
|
|
99 |
this.setPaddings(5);
|
|
|
100 |
|
|
|
101 |
this.setBorder(false);
|
|
|
102 |
this.setCollapsible(true);
|
|
|
103 |
this.setAutoWidth(true);
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
// on ajoute les listeners
|
|
|
107 |
ajouterListenersPanel();
|
|
|
108 |
estInstancie = false;
|
|
|
109 |
}
|
|
|
110 |
|
|
|
111 |
/**
|
|
|
112 |
* Ajoute les listeners pour le rendu du panel
|
|
|
113 |
*/
|
|
|
114 |
private void ajouterListenersPanel() {
|
| 68 |
david |
115 |
this.addListener(new PanelListenerAdapter() {
|
| 54 |
david |
116 |
|
|
|
117 |
// on instancie réellement les composants au moment du rendu pour
|
|
|
118 |
// accélérer l'affichage
|
|
|
119 |
// et éviter des bugs
|
|
|
120 |
public void onRender(Component component) {
|
|
|
121 |
|
|
|
122 |
// on interdit le drag and drop dans l'arbre
|
| 68 |
david |
123 |
arbreEntitesGeographiques.setEnableDD(false);
|
| 73 |
david |
124 |
arbreEntitesGeographiques.setId("x-view-tree-filter-entity");
|
| 72 |
david |
125 |
arbreEntitesGeographiques.setAutoWidth(false);
|
|
|
126 |
|
|
|
127 |
if (GWT.isScript()) {
|
|
|
128 |
arbreEntitesGeographiques.setAutoScroll(true);
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
arbreEntitesGeographiques.setBorder(false);
|
| 54 |
david |
132 |
|
|
|
133 |
// on crée une racine pour l'arbre
|
| 72 |
david |
134 |
TreeNode root = new TreeNode("Localités");
|
| 70 |
david |
135 |
root.setId("racine_entite");
|
| 72 |
david |
136 |
String[] usObject = { "Localités" };
|
| 54 |
david |
137 |
root.setUserObject(usObject);
|
|
|
138 |
|
| 68 |
david |
139 |
arbreEntitesGeographiques.setRootNode(root);
|
|
|
140 |
arbreEntitesGeographiques.setRootVisible(true);
|
|
|
141 |
arbreEntitesGeographiques.setBorder(false);
|
| 85 |
jpm |
142 |
root.setExpandable(true) ;
|
| 54 |
david |
143 |
|
| 68 |
david |
144 |
add(arbreEntitesGeographiques);
|
| 54 |
david |
145 |
|
|
|
146 |
// on ajoute les listeners d'évenements
|
|
|
147 |
ajouterListeners();
|
|
|
148 |
|
|
|
149 |
|
|
|
150 |
// enfin on considère le composant comme instancié
|
|
|
151 |
estInstancie = true;
|
|
|
152 |
|
| 68 |
david |
153 |
|
| 54 |
david |
154 |
}
|
|
|
155 |
|
|
|
156 |
});
|
|
|
157 |
}
|
|
|
158 |
|
| 68 |
david |
159 |
|
|
|
160 |
|
| 54 |
david |
161 |
/**
|
| 70 |
david |
162 |
* ajoute les listeners pour les boutons et le cochage des entites
|
| 54 |
david |
163 |
*/
|
|
|
164 |
private void ajouterListeners() {
|
| 85 |
jpm |
165 |
|
|
|
166 |
arbreEntitesGeographiques.addListener(new TreePanelListenerAdapter() {
|
|
|
167 |
|
|
|
168 |
public void onClick(TreeNode node, EventObject e) {
|
|
|
169 |
|
| 86 |
jpm |
170 |
nomFiltre = "" ;
|
| 87 |
jpm |
171 |
entitesGeographiquesEncours = "" ;
|
|
|
172 |
String nomPere = "" ;
|
|
|
173 |
String nomGrandPere = "" ;
|
| 85 |
jpm |
174 |
|
|
|
175 |
switch(node.getDepth())
|
|
|
176 |
{
|
|
|
177 |
case 0:
|
|
|
178 |
if(!arbreCharge)
|
|
|
179 |
{
|
|
|
180 |
observationMediateur.obtenirListeEntiteGeographique() ;
|
|
|
181 |
arbreCharge = true ;
|
|
|
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 |
}
|
|
|
223 |
|
|
|
224 |
/**
|
|
|
225 |
* Méthode héritée de l'interface rafraichissable
|
|
|
226 |
*/
|
|
|
227 |
public void rafraichir(Object nouvelleDonnees,
|
|
|
228 |
boolean repandreRaffraichissement) {
|
|
|
229 |
|
|
|
230 |
|
| 68 |
david |
231 |
if (nouvelleDonnees instanceof ListeEntiteGeographiqueObservation) {
|
|
|
232 |
|
|
|
233 |
String entite=null;
|
| 72 |
david |
234 |
String idEntite=null;
|
|
|
235 |
String idParent=null;
|
| 68 |
david |
236 |
|
|
|
237 |
ListeEntiteGeographiqueObservation data = (ListeEntiteGeographiqueObservation) nouvelleDonnees ;
|
|
|
238 |
|
|
|
239 |
|
|
|
240 |
if (data.isEmpty()) {
|
|
|
241 |
// on crée un arbre vide
|
|
|
242 |
TreeNode root = new TreeNode();
|
| 72 |
david |
243 |
root.setId("racine_entite");
|
|
|
244 |
root.setText("Localités");
|
|
|
245 |
String[] usObj = { "Localités"};
|
| 68 |
david |
246 |
root.setUserObject(usObj);
|
|
|
247 |
donneeEntitesGeographiques.setRootNode(root);
|
|
|
248 |
|
|
|
249 |
}
|
|
|
250 |
|
| 83 |
david |
251 |
// on la parse et on récupère les informations qui nous interessent
|
| 68 |
david |
252 |
for (Iterator<String> it= data.keySet().iterator(); it.hasNext();) {
|
|
|
253 |
|
|
|
254 |
EntiteGeographiqueObservation ent=(EntiteGeographiqueObservation) data.get(it.next());
|
|
|
255 |
|
|
|
256 |
entite=ent.getEntite();
|
| 73 |
david |
257 |
|
| 85 |
jpm |
258 |
if(entite.contains("000null")) {
|
|
|
259 |
entite="Inconnue" ;
|
|
|
260 |
}
|
| 73 |
david |
261 |
|
| 72 |
david |
262 |
idEntite=ent.getIdEntite();
|
|
|
263 |
idParent=ent.getIdParent();
|
| 68 |
david |
264 |
|
| 72 |
david |
265 |
|
| 68 |
david |
266 |
String[] usObj = { entite };
|
|
|
267 |
|
|
|
268 |
// et on construit l'arbre à partir de la racine (qui est
|
|
|
269 |
// toujours le premier élément)
|
| 72 |
david |
270 |
if (entite.equals("racine_entite")) {
|
| 68 |
david |
271 |
TreeNode root = new TreeNode();
|
| 72 |
david |
272 |
root.setId(idEntite);
|
| 68 |
david |
273 |
root.setText(entite);
|
|
|
274 |
root.setUserObject(usObj);
|
|
|
275 |
donneeEntitesGeographiques.setRootNode(root);
|
|
|
276 |
} else {
|
|
|
277 |
// et en ajoutant les noeuds un à un (qui sont renvoyé
|
|
|
278 |
// dans l'ordre hierarchique de leur niveau
|
|
|
279 |
// ce qui permet de les traiter séquentiellement)
|
|
|
280 |
TreeNode node = new TreeNode();
|
| 72 |
david |
281 |
node.setId(idEntite);
|
| 86 |
jpm |
282 |
node.setText(entite);
|
| 72 |
david |
283 |
Node parentNode = donneeEntitesGeographiques.getNodeById(idParent);
|
| 85 |
jpm |
284 |
if(parentNode != null)
|
|
|
285 |
{
|
|
|
286 |
node.setUserObject(usObj);
|
|
|
287 |
parentNode.appendChild(node);
|
|
|
288 |
}
|
| 68 |
david |
289 |
}
|
|
|
290 |
}
|
|
|
291 |
|
|
|
292 |
}
|
|
|
293 |
|
| 54 |
david |
294 |
// on vide tous les noeuds
|
| 68 |
david |
295 |
arbreEntitesGeographiques.getRootNode().eachChild(new NodeTraversalCallback() {
|
| 54 |
david |
296 |
|
|
|
297 |
public boolean execute(Node node) {
|
|
|
298 |
|
|
|
299 |
node.remove();
|
|
|
300 |
return true;
|
|
|
301 |
}
|
|
|
302 |
|
|
|
303 |
});
|
|
|
304 |
|
|
|
305 |
// et on recopie le nouvel arbre
|
| 68 |
david |
306 |
copierFilsNoeud(donneeEntitesGeographiques.getRootNode(), arbreEntitesGeographiques
|
| 54 |
david |
307 |
.getRootNode());
|
|
|
308 |
|
|
|
309 |
// si l'arbre n'était pas encore considéré comme instancié
|
|
|
310 |
if (!estInstancie) {
|
|
|
311 |
// on signale que oui
|
|
|
312 |
estInstancie = true;
|
|
|
313 |
}
|
|
|
314 |
|
|
|
315 |
// l'état du filtre est réinitialisé
|
|
|
316 |
filtreModifie = false;
|
| 70 |
david |
317 |
//show() ;
|
|
|
318 |
doLayout();
|
| 68 |
david |
319 |
}
|
|
|
320 |
|
| 54 |
david |
321 |
|
| 68 |
david |
322 |
|
| 54 |
david |
323 |
|
|
|
324 |
|
|
|
325 |
/**
|
|
|
326 |
* Accesseur pour le panneau contenant l'arbre
|
|
|
327 |
*
|
|
|
328 |
* @return le panneau de l'arbre des mots clés
|
|
|
329 |
*/
|
|
|
330 |
public TreePanel getArbreMotsCles() {
|
| 68 |
david |
331 |
return arbreEntitesGeographiques;
|
| 54 |
david |
332 |
}
|
|
|
333 |
|
|
|
334 |
/**
|
|
|
335 |
* Méthode héritée de Filtrable renvoie le nom du filtre
|
|
|
336 |
*/
|
|
|
337 |
public String renvoyerNomFiltre() {
|
|
|
338 |
|
|
|
339 |
return "Localités";
|
|
|
340 |
}
|
|
|
341 |
|
|
|
342 |
/**
|
|
|
343 |
* Renvoie un tableau contenant le nom du champ à filtrer et la valeur
|
|
|
344 |
*
|
|
|
345 |
* @return un tableau contenant le nom du champ à filtrer et sa valeur
|
|
|
346 |
*/
|
|
|
347 |
public String[] renvoyerValeursAFiltrer() {
|
|
|
348 |
|
|
|
349 |
valider();
|
| 85 |
jpm |
350 |
|
| 86 |
jpm |
351 |
String valeursFiltrees[] = {nomFiltre, entitesGeographiquesEncours } ;
|
| 54 |
david |
352 |
|
|
|
353 |
return valeursFiltrees;
|
|
|
354 |
}
|
|
|
355 |
|
|
|
356 |
/**
|
|
|
357 |
* Fonction récursive qui prend deux noeuds d'arbre en paramètre et crée un
|
|
|
358 |
* copie du sous arbre du premier noeud, qu'elle concatène au deuxième
|
|
|
359 |
*
|
|
|
360 |
* @param ndPereOriginal
|
|
|
361 |
* le père des noeuds de l'arbre original
|
|
|
362 |
* @param ndPereCopie
|
|
|
363 |
* le père qui va recevoir les copies
|
|
|
364 |
*/
|
|
|
365 |
private void copierFilsNoeud(Node ndPereOriginal, TreeNode ndPereCopie) {
|
|
|
366 |
if (ndPereCopie != null && ndPereOriginal != null) {
|
|
|
367 |
Node[] ndNodeFils = ndPereOriginal.getChildNodes();
|
|
|
368 |
|
|
|
369 |
for (int i = 0; i < ndNodeFils.length; i++) {
|
|
|
370 |
|
|
|
371 |
String[] usObj = (String[]) ndNodeFils[i].getUserObject();
|
|
|
372 |
TreeNode child = new TreeNode(usObj[0]);
|
|
|
373 |
child.setUserObject(usObj);
|
|
|
374 |
ndPereCopie.appendChild(child);
|
|
|
375 |
|
|
|
376 |
if (!ndNodeFils[i].isLeaf()) {
|
|
|
377 |
copierFilsNoeud(ndNodeFils[i], child);
|
|
|
378 |
}
|
|
|
379 |
|
|
|
380 |
}
|
|
|
381 |
}
|
|
|
382 |
}
|
|
|
383 |
|
|
|
384 |
/**
|
|
|
385 |
* Méthode héritée de Filtrable Renvoie l'état du filtre (modifié ou non)
|
|
|
386 |
*/
|
|
|
387 |
public boolean renvoyerEtatFiltre() {
|
|
|
388 |
|
|
|
389 |
return filtreModifie;
|
|
|
390 |
}
|
|
|
391 |
|
|
|
392 |
public void valider() {
|
| 86 |
jpm |
393 |
|
| 54 |
david |
394 |
if (estInstancie) {
|
| 86 |
jpm |
395 |
|
| 54 |
david |
396 |
}
|
|
|
397 |
}
|
|
|
398 |
|
|
|
399 |
}
|