/branches/becassine/src/org/tela_botanica/client/vues/observation/filtres/ArbreEntiteGeographiqueObservationFiltreVue.java |
---|
New file |
0,0 → 1,661 |
package org.tela_botanica.client.vues.observation.filtres; |
import java.util.Comparator; |
import java.util.Iterator; |
import org.tela_botanica.client.interfaces.Filtrable; |
import org.tela_botanica.client.interfaces.Rafraichissable; |
import org.tela_botanica.client.modeles.EntiteGeographiqueObservation; |
import org.tela_botanica.client.modeles.ListeEntiteGeographiqueObservation; |
import org.tela_botanica.client.modeles.Observation; |
import org.tela_botanica.client.observation.ObservationMediateur; |
import com.google.gwt.core.client.GWT; |
import com.gwtext.client.data.Node; |
import com.gwtext.client.data.NodeTraversalCallback; |
import com.gwtext.client.data.Tree; |
import com.gwtext.client.widgets.Component; |
import com.gwtext.client.widgets.Panel; |
import com.gwtext.client.widgets.event.PanelListenerAdapter; |
import com.gwtext.client.widgets.tree.TreeNode; |
import com.gwtext.client.widgets.tree.TreePanel; |
import com.gwtext.client.widgets.tree.event.TreeNodeListenerAdapter; |
import com.gwtext.client.widgets.tree.event.TreePanelListenerAdapter; |
import com.gwtext.client.core.EventObject; |
/** |
* Arbre Filtrant sur les entites geographiques |
* |
* |
* @author aurelien + david |
* |
*/ |
public class ArbreEntiteGeographiqueObservationFiltreVue extends Panel implements Rafraichissable, |
Filtrable { |
/** |
* Le médiateur associé à la vue |
*/ |
private ObservationMediateur observationMediateur = null; |
/** |
* Les localites en cours |
*/ |
private String entitesGeographiquesEncours = ""; |
/** |
* Le treepanel qui affiche l'arbre |
*/ |
private TreePanel arbreEntitesGeographiques = null; |
/** |
* booléen d'initialisation |
*/ |
private boolean estInstancie = false; |
/** |
* booléen d'etat |
*/ |
private boolean filtreModifie = false; |
private boolean arbreCharge = false ; |
private String nomFiltre = "" ; |
/** |
* Constructeur sans argument (privé car ne doit pas être utilisé) |
*/ |
@SuppressWarnings("unused") |
private ArbreEntiteGeographiqueObservationFiltreVue() { |
super(); |
} |
/** |
* Constructeur avec paramètres |
* |
* @param im |
* le médiateur à associer |
*/ |
public ArbreEntiteGeographiqueObservationFiltreVue(ObservationMediateur obs) { |
// on crée le panel |
super("Localités"); |
this.observationMediateur = obs; |
arbreEntitesGeographiques = new TreePanel(); |
this.setPaddings(5); |
this.setCollapsible(true); |
this.setAutoScroll(true); |
// on ajoute les listeners |
ajouterListenersPanel(); |
estInstancie = false; |
} |
/** |
* Ajoute les listeners pour le rendu du panel |
*/ |
private void ajouterListenersPanel() { |
this.addListener(new PanelListenerAdapter() { |
// on instancie réellement les composants au moment du rendu pour |
// accélérer l'affichage |
// et éviter des bugs |
public void onRender(Component component) { |
// on interdit le drag and drop dans l'arbre |
arbreEntitesGeographiques.setEnableDD(false); |
arbreEntitesGeographiques.setId("x-view-tree-filter-entity"); |
// on crée une racine pour l'arbre |
TreeNode root = new TreeNode("Localités"); |
root.setId("racine_entite"); |
String[] usObject = { "Localités" }; |
root.setUserObject(usObject); |
arbreEntitesGeographiques.setRootNode(root); |
arbreEntitesGeographiques.setRootVisible(true); |
arbreEntitesGeographiques.setBorder(false); |
root.setExpandable(true) ; |
add(arbreEntitesGeographiques); |
// on ajoute les listeners d'évenements |
ajouterListeners(); |
// enfin on considère le composant comme instancié |
estInstancie = true; |
} |
}); |
} |
/** |
* ajoute les listeners pour les boutons et le cochage des entites |
*/ |
private void ajouterListeners() { |
arbreEntitesGeographiques.addListener(new TreePanelListenerAdapter() { |
public void onClick(TreeNode node, EventObject e) { |
nomFiltre = "" ; |
entitesGeographiquesEncours = "" ; |
String nomPere = "" ; |
String nomGrandPere = "" ; |
switch(node.getDepth()) |
{ |
case 0: |
if(!arbreCharge) |
{ |
arbreEntitesGeographiques.getRootNode().expand(); |
} |
else |
{ |
observationMediateur.obtenirNombreObservation() ; |
} |
return ; |
case 3: nomFiltre += "lieudit,location,id_location"; |
nomPere = ((String[])node.getParentNode().getUserObject())[0] ; |
nomGrandPere = ((String[])node.getParentNode().getParentNode().getUserObject())[0] ; |
entitesGeographiquesEncours += node.getText()+","+nomPere+","+nomGrandPere ; |
break; |
case 2: nomFiltre += "location,id_location"; |
nomPere = ((String[])node.getParentNode().getUserObject())[0] ; |
entitesGeographiquesEncours += node.getText()+","+nomPere ; |
break; |
case 1: nomFiltre += "id_location"; |
entitesGeographiquesEncours += node.getText() ; |
break; |
default: |
break; |
} |
filtreModifie = true ; |
// Le filtre est modifie : on lance un rafraaaichissement de la liste des observations affichees |
observationMediateur.obtenirNombreObservation() ; |
} |
}) ; |
arbreEntitesGeographiques.getRootNode().addListener(new TreeNodeListenerAdapter() { |
public void onExpand(Node node) { |
if(!arbreCharge) |
{ |
observationMediateur.obtenirListeEntiteGeographique() ; |
arbreCharge = true ; |
} |
} |
}) ; |
} |
public void initialiser() { |
arbreCharge = false ; |
arbreEntitesGeographiques.collapseAll(); |
// on vide l'ancien arbre |
Node[] rootChild = arbreEntitesGeographiques.getRootNode().getChildNodes(); |
for (int i = 0; i < rootChild.length; i++) { |
rootChild[i].remove(); |
} |
arbreEntitesGeographiques.getRootNode().addListener(new TreeNodeListenerAdapter() { |
public void onExpand(Node node) { |
if(!arbreCharge) |
{ |
observationMediateur.obtenirListeEntiteGeographique() ; |
arbreCharge = true ; |
} |
} |
}) ; |
} |
/** |
* Méthode héritée de l'interface rafraichissable |
*/ |
public void rafraichir(Object nouvelleDonnees, |
boolean repandreRaffraichissement) { |
if (nouvelleDonnees instanceof ListeEntiteGeographiqueObservation) { |
String id_location=null; |
String location=null; |
String lieuDit=null; |
ListeEntiteGeographiqueObservation data = (ListeEntiteGeographiqueObservation) nouvelleDonnees ; |
// on crée un arbre vide |
Tree nouvelArbre = new Tree() ; |
TreeNode root = new TreeNode(); |
root.setId("racine_entite"); |
root.setText("Localités"); |
String[] usObjRoot = { "Localités"}; |
root.setUserObject(usObjRoot); |
nouvelArbre.setRootNode(root); |
// on la parse et on récupère les informations qui nous interessent |
for (Iterator<String> it= data.keySet().iterator(); it.hasNext();) { |
EntiteGeographiqueObservation ent=(EntiteGeographiqueObservation) data.get(it.next()); |
id_location=ent.getIdLocation(); |
id_location = id_location.replaceAll("\"", ""); |
id_location = id_location.replace('\\',' '); |
id_location = id_location.trim(); |
location=ent.getLocation(); |
lieuDit=ent.getLieuDit(); |
if(id_location.contains("000null") || id_location.equals(null) || (id_location.trim()).equals("")) { |
id_location="Inconnue" ; |
} |
if(location.contains("000null") || location.equals(null) || (location.trim().equals(""))) { |
location="Inconnue" ; |
} |
if(lieuDit.contains("000null") || lieuDit.equals(null) || (lieuDit.trim().equals(""))) { |
lieuDit="Inconnue" ; |
} |
Node noeudMemeId = nouvelArbre.getNodeById(""+id_location); |
// si la région existe déjà |
if(noeudMemeId != null) |
{ |
// on teste si la localité existe |
Node noeudMemeLoc = nouvelArbre.getNodeById(""+(id_location+location)); |
if(noeudMemeLoc != null) |
{ |
// enfin on teste si le lieu dit existe |
Node noeudMemeLieu = nouvelArbre.getNodeById(""+(id_location+location+lieuDit)); |
if(noeudMemeLieu != null) |
{ |
// tous les noeuds existent déjà, normalement ça ne devrait pas arriver |
} |
else |
{ |
// enfin on ne crée que le noeud du lieu dit |
TreeNode node_lieu = new TreeNode(); |
node_lieu.setId(""+(id_location+location+lieuDit)); |
node_lieu.setText(lieuDit); |
noeudMemeLoc.appendChild(node_lieu) ; |
String[] usObj = {lieuDit,id_location+location+lieuDit}; |
node_lieu.setUserObject(usObj); |
} |
} |
else |
{ |
// on crée le noeud de la location |
TreeNode node_loc = new TreeNode(); |
node_loc.setId(""+(id_location+location)); |
node_loc.setText(location); |
noeudMemeId.appendChild(node_loc) ; |
String[] usObj = {location,id_location+location}; |
node_loc.setUserObject(usObj); |
TreeNode node_lieu = new TreeNode(); |
node_lieu.setId(""+(id_location+location+lieuDit)); |
node_lieu.setText(lieuDit); |
node_loc.appendChild(node_lieu) ; |
String[] usObj2 = {lieuDit,id_location+location+lieuDit}; |
node_lieu.setUserObject(usObj2); |
} |
} |
else |
{ |
// on crée le noeud de l'identifiant location |
TreeNode node_id_loc = new TreeNode(); |
node_id_loc.setId(""+id_location); |
node_id_loc.setText(id_location); |
root.appendChild(node_id_loc) ; |
String[] usObj = {id_location,id_location}; |
node_id_loc.setUserObject(usObj); |
TreeNode node_loc = new TreeNode(); |
node_loc.setId(""+(id_location+location)); |
node_loc.setText(location); |
node_id_loc.appendChild(node_loc) ; |
String[] usObj2 = {location,id_location+location}; |
node_loc.setUserObject(usObj2); |
TreeNode node_lieu = new TreeNode(); |
node_lieu.setId(""+(id_location+location+lieuDit)); |
node_lieu.setText(lieuDit); |
node_loc.appendChild(node_lieu) ; |
String[] usObj3 = {lieuDit,id_location+location+lieuDit}; |
node_lieu.setUserObject(usObj3); |
} |
root.sort(comparerNoeuds()) ; |
doLayout(); |
} |
// on vide tous les noeuds |
arbreEntitesGeographiques.getRootNode().eachChild(new NodeTraversalCallback() { |
public boolean execute(Node node) { |
node.remove(); |
return true; |
} |
}); |
copierFilsNoeud(root, arbreEntitesGeographiques.getRootNode()); |
// si l'arbre n'était pas encore considéré comme instancié |
if (!estInstancie) { |
// on signale que oui |
estInstancie = true; |
} |
// l'état du filtre est réinitialisé |
filtreModifie = false; |
//show() ; |
arbreEntitesGeographiques.doLayout(); |
} |
if(nouvelleDonnees instanceof Observation) |
{ |
// Cas d'ajout unitaire d'une observation |
// si l'arbre n'est pas encore chargé, on ne tient pas compte de l'ajout |
// l'arbre complet sera de toute façon renvoyé plus tard lors du premier chargement |
// de l'arbre |
if(!arbreCharge) { |
return; |
} |
Observation obs = (Observation)nouvelleDonnees ; |
String id_location= obs.getIdentifiantLocalite(); |
id_location = id_location.replaceAll("\"", ""); |
id_location = id_location.replace('\\',' '); |
id_location = id_location.trim(); |
String location=obs.getLocalite(); |
String lieuDit=obs.getLieudit(); |
Node root = arbreEntitesGeographiques.getRootNode() ; |
if(id_location.contains("000null") || id_location.equals(null) || (id_location.trim()).equals("")) { |
id_location="Inconnue" ; |
} |
if(location.contains("000null") || location.equals(null) || (location.trim().equals(""))) { |
location="Inconnue" ; |
} |
if(lieuDit.contains("000null") || lieuDit.equals(null) || (lieuDit.trim().equals(""))) { |
lieuDit="Inconnue" ; |
} |
Node noeudMemeId = arbreEntitesGeographiques.getNodeById(""+id_location); |
// si la région existe déjà |
if(noeudMemeId != null) |
{ |
// on teste si la localité existe |
Node noeudMemeLoc = arbreEntitesGeographiques.getNodeById(""+(id_location+location)); |
if(noeudMemeLoc != null) |
{ |
// enfin on teste si le lieu dit existe |
Node noeudMemeLieu = arbreEntitesGeographiques.getNodeById(""+(id_location+location+lieuDit)); |
if(noeudMemeLieu != null) |
{ |
// tous les noeuds existent déjà, normalement ça ne devrait pas arriver |
} |
else |
{ |
// enfin on ne crée que le noeud du lieu dit |
TreeNode node_lieu = new TreeNode(); |
node_lieu.setId(""+(id_location+location+lieuDit)); |
node_lieu.setText(lieuDit); |
String[] usObj = {lieuDit,id_location+location+lieuDit}; |
node_lieu.setUserObject(usObj); |
noeudMemeLoc.appendChild(node_lieu) ; |
root.sort(comparerNoeuds()) ; |
} |
} |
else |
{ |
// on crée le noeud de la location |
TreeNode node_loc = new TreeNode(); |
node_loc.setId(""+(id_location+location)); |
node_loc.setText(location); |
String[] usObj = {location,id_location+location}; |
node_loc.setUserObject(usObj); |
noeudMemeId.appendChild(node_loc) ; |
TreeNode node_lieu = new TreeNode(); |
node_lieu.setId(""+(id_location+location+lieuDit)); |
node_lieu.setText(lieuDit); |
String[] usObj2 = {lieuDit,id_location+location+lieuDit}; |
node_lieu.setUserObject(usObj2); |
node_loc.appendChild(node_lieu) ; |
root.sort(comparerNoeuds()) ; |
} |
} |
else |
{ |
// TODO: Pourquoi l'ajout ne marche que sur la racine ? |
// on crée le noeud de l'id location |
TreeNode node_id_loc = new TreeNode(); |
node_id_loc.setId(""+id_location); |
node_id_loc.setText(id_location); |
String[] usObj = {id_location,id_location}; |
node_id_loc.setUserObject(usObj); |
root.appendChild(node_id_loc) ; |
TreeNode node_loc = new TreeNode(); |
node_loc.setId(""+(id_location+location)); |
node_loc.setText(location); |
String[] usObj2 = {location,id_location+location}; |
node_loc.setUserObject(usObj2); |
node_id_loc.appendChild(node_loc) ; |
TreeNode node_lieu = new TreeNode(); |
node_lieu.setId(""+(id_location+location+lieuDit)); |
node_lieu.setText(lieuDit); |
String[] usObj3 = {lieuDit,id_location+location+lieuDit}; |
node_lieu.setUserObject(usObj3); |
node_loc.appendChild(node_lieu) ; |
root.sort(comparerNoeuds()) ; |
} |
arbreEntitesGeographiques.doLayout() ; |
} |
} |
/** |
* Accesseur pour le panneau contenant l'arbre |
* |
* @return le panneau de l'arbre des mots clés |
*/ |
public TreePanel getArbreMotsCles() { |
return arbreEntitesGeographiques; |
} |
/** |
* Méthode héritée de Filtrable renvoie le nom du filtre |
*/ |
public String renvoyerNomFiltre() { |
return "Localités"; |
} |
/** |
* Renvoie un tableau contenant le nom du champ à filtrer et la valeur |
* |
* @return un tableau contenant le nom du champ à filtrer et sa valeur |
*/ |
public String[] renvoyerValeursAFiltrer() { |
valider(); |
String valeursFiltrees[] = {nomFiltre, entitesGeographiquesEncours } ; |
return valeursFiltrees; |
} |
/** |
* Fonction récursive qui prend deux noeuds d'arbre en paramètre et crée un |
* copie du sous arbre du premier noeud, qu'elle concatène au deuxième |
* |
* @param ndPereOriginal |
* le père des noeuds de l'arbre original |
* @param ndPereCopie |
* le père qui va recevoir les copies |
*/ |
private void copierFilsNoeud(Node ndPereOriginal, TreeNode ndPereCopie) { |
if (ndPereCopie != null && ndPereOriginal != null) { |
Node[] ndNodeFils = ndPereOriginal.getChildNodes(); |
for (int i = 0; i < ndNodeFils.length; i++) { |
String[] usObj = (String[]) ndNodeFils[i].getUserObject(); |
TreeNode child = new TreeNode(usObj[0]); |
child.setUserObject(usObj); |
child.setId(""+usObj[1]); |
ndPereCopie.appendChild(child); |
if (!ndNodeFils[i].isLeaf()) { |
copierFilsNoeud(ndNodeFils[i], child); |
} |
} |
} |
} |
/** |
* Méthode héritée de Filtrable Renvoie l'état du filtre (modifié ou non) |
*/ |
public boolean renvoyerEtatFiltre() { |
return filtreModifie; |
} |
public void valider() { |
if (estInstancie) { |
} |
} |
public Comparator<TreeNode> comparerNoeuds() |
{ |
return new Comparator<TreeNode>() { |
public int compare(TreeNode o1, TreeNode o2) { |
if(o1.getText().equals("Inconnue")) { |
return -1 ; |
} |
if(o2.getText().equals("Inconnue")) { |
return 1 ; |
} |
if(o1.getDepth() == 1 && o2.getDepth() == 1) |
{ |
String l1 = o1.getText() ; |
String l2 = o2.getText() ; |
if(l1.length() == 1) { |
l1 = "0"+l1; |
} |
if(l2.length() == 1) { |
l2 = "0"+l2; |
} |
Integer n1 = 0; |
Integer n2 = 0; |
try{ |
n1 = Integer.parseInt(l1) ; |
n2 = Integer.parseInt(l2) ; |
} catch(NumberFormatException ne) { |
n1 = 0; |
n2 = 0; |
} |
return n1.compareTo(n2) ; |
} |
else |
{ |
String n1 = o1.getText() ; |
String n2 = o2.getText() ; |
return n1.compareTo(n2) ; |
} |
} |
} ; |
} |
public void raz() { |
arbreCharge = false ; |
arbreEntitesGeographiques.collapseAll(); |
arbreEntitesGeographiques.clear() ; |
// on crée une racine pour l'arbre |
TreeNode root = new TreeNode("Localités"); |
root.setId("racine_entite"); |
String[] usObject = { "Localités" }; |
root.setUserObject(usObject); |
arbreEntitesGeographiques.setRootNode(root); |
arbreEntitesGeographiques.getRootNode().addListener(new TreeNodeListenerAdapter() { |
public void onExpand(Node node) { |
if(!arbreCharge) |
{ |
observationMediateur.obtenirDatesObservation() ; |
arbreCharge = true ; |
} |
} |
}) ; |
arbreCharge = false ; |
this.doLayout() ; |
} |
} |
Property changes: |
Added: svn:mergeinfo |
/branches/becassine/src/org/tela_botanica/client/vues/observation/filtres/ArbreDateObservationFiltreVue.java |
---|
New file |
0,0 → 1,642 |
package org.tela_botanica.client.vues.observation.filtres; |
import java.util.Comparator; |
import java.util.Iterator; |
import org.tela_botanica.client.interfaces.Filtrable; |
import org.tela_botanica.client.interfaces.Rafraichissable; |
import org.tela_botanica.client.modeles.DateObservation; |
import org.tela_botanica.client.modeles.ListeDateObservation; |
import org.tela_botanica.client.modeles.Observation; |
import org.tela_botanica.client.observation.ObservationMediateur; |
import com.google.gwt.core.client.GWT; |
import com.gwtext.client.data.Node; |
import com.gwtext.client.data.NodeTraversalCallback; |
import com.gwtext.client.data.Tree; |
import com.gwtext.client.widgets.Component; |
import com.gwtext.client.widgets.Panel; |
import com.gwtext.client.widgets.event.PanelListenerAdapter; |
import com.gwtext.client.widgets.tree.TreeNode; |
import com.gwtext.client.widgets.tree.TreePanel; |
import com.gwtext.client.widgets.tree.event.TreeNodeListenerAdapter; |
import com.gwtext.client.widgets.tree.event.TreePanelListenerAdapter; |
import com.gwtext.client.core.EventObject; |
/** |
* fenêtre de recherche affichant l'arbre des mots clés en lecture et un bouton |
* cliquable |
* |
* @author aurelien |
* |
*/ |
public class ArbreDateObservationFiltreVue extends Panel implements Rafraichissable, |
Filtrable { |
/** |
* Le médiateur associé à la vue |
*/ |
private ObservationMediateur observationMediateur = null; |
/** |
* Les localites en cours |
*/ |
private String donneesDateEnCours = ""; |
/** |
* Le treepanel qui affiche l'arbre |
*/ |
private TreePanel arbreDonneesDates = null; |
/** |
* La structure de donnees qui stocke l'arbre. Utilisee a ce niveau car trop liee a la vue |
*/ |
private Tree donneesDates = new Tree(); |
/** |
* booléen d'initialisation |
*/ |
private boolean estInstancie = false; |
/** |
* booléen d'etat |
*/ |
private boolean filtreModifie = false; |
private boolean arbreCharge = false ; |
private String nomFiltre = "" ; |
/** |
* Constructeur sans argument (privé car ne doit pas être utilisé) |
*/ |
@SuppressWarnings("unused") |
private ArbreDateObservationFiltreVue() { |
super(); |
} |
/** |
* Constructeur avec paramètres |
* |
* @param im |
* le médiateur à associer |
*/ |
public ArbreDateObservationFiltreVue(ObservationMediateur obs) { |
// on crée le panel |
super("Dates"); |
this.observationMediateur = obs; |
arbreDonneesDates = new TreePanel(); |
this.setPaddings(5); |
this.setCollapsible(true); |
this.setAutoScroll(true); |
// on ajoute les listeners |
ajouterListenersPanel(); |
estInstancie = false; |
} |
/** |
* Ajoute les listeners pour le rendu du panel |
*/ |
private void ajouterListenersPanel() { |
this.addListener(new PanelListenerAdapter() { |
// on instancie réellement les composants au moment du rendu pour |
// accélérer l'affichage |
// et éviter des bugs |
public void onRender(Component component) { |
// on interdit le drag and drop dans l'arbre |
arbreDonneesDates.setEnableDD(false); |
arbreDonneesDates.setId("x-view-tree-filter-date"); |
arbreDonneesDates.setBorder(false); |
// on crée une racine pour l'arbre |
TreeNode root = new TreeNode("Dates"); |
root.setId("racine_date"); |
String[] usObject = { "Dates", "Dates", "racine_date" }; |
root.setUserObject(usObject); |
arbreDonneesDates.setRootNode(root); |
arbreDonneesDates.setRootVisible(true); |
arbreDonneesDates.setBorder(false); |
root.setExpandable(true) ; |
add(arbreDonneesDates); |
// on ajoute les listeners d'évenements |
ajouterListeners(); |
// enfin on considère le composant comme instancié |
estInstancie = true; |
} |
}); |
} |
/** |
* ajoute les listeners pour les boutons et le cochage des entites |
*/ |
private void ajouterListeners() { |
arbreDonneesDates.addListener(new TreePanelListenerAdapter() { |
public void onClick(TreeNode node, EventObject e) { |
nomFiltre = "" ; |
donneesDateEnCours = "" ; |
String nomPere = "" ; |
String nomGrandPere = "" ; |
switch(node.getDepth()) |
{ |
case 0: |
if(!arbreCharge) |
{ |
/* arbreCharge = true ; |
observationMediateur.obtenirDatesObservation() ;*/ |
arbreDonneesDates.getRootNode().expand(); |
} |
else |
{ |
observationMediateur.obtenirNombreObservation() ; |
} |
return ; |
case 3: nomFiltre += "annee,mois,jour"; |
nomPere = ((String[])node.getParentNode().getUserObject())[1] ; |
nomGrandPere = ((String[])node.getParentNode().getParentNode().getUserObject())[1] ; |
donneesDateEnCours += nomGrandPere+","+nomPere+","+((String[])node.getUserObject())[1] ; |
break; |
case 2: nomFiltre += "annee,mois"; |
nomPere = ((String[])node.getParentNode().getUserObject())[1] ; |
donneesDateEnCours += nomPere+","+((String[])node.getUserObject())[1] ; |
break; |
case 1: nomFiltre += "annee"; |
donneesDateEnCours += ((String[])node.getUserObject())[1] ; |
break; |
default: |
break; |
} |
filtreModifie = true ; |
observationMediateur.obtenirNombreObservation() ; |
} |
}) ; |
arbreDonneesDates.getRootNode().addListener(new TreeNodeListenerAdapter() { |
public void onExpand(Node node) { |
if(!arbreCharge) |
{ |
observationMediateur.obtenirDatesObservation() ; |
arbreCharge = true ; |
} |
} |
}) ; |
} |
public void initialiser() { |
arbreCharge = false ; |
arbreDonneesDates.collapseAll(); |
// on vide l'ancien arbre |
Node[] rootChild = arbreDonneesDates.getRootNode().getChildNodes(); |
for (int i = 0; i < rootChild.length; i++) { |
rootChild[i].remove(); |
} |
arbreDonneesDates.getRootNode().addListener(new TreeNodeListenerAdapter() { |
public void onExpand(Node node) { |
if(!arbreCharge) |
{ |
observationMediateur.obtenirDatesObservation() ; |
arbreCharge = true ; |
} |
} |
}) ; |
} |
/** |
* Méthode héritée de l'interface rafraichissable |
*/ |
public void rafraichir(Object nouvelleDonnees, |
boolean repandreRaffraichissement) { |
if (nouvelleDonnees instanceof ListeDateObservation) { |
String annee=null; |
String mois=null; |
String jour=null; |
ListeDateObservation data = (ListeDateObservation) nouvelleDonnees ; |
// on crée un arbre vide |
TreeNode root = new TreeNode(); |
root.setId("racine_date"); |
root.setText("Dates"); |
String[] usObjRoot = { "Dates", "Dates", "racine_date"}; |
root.setUserObject(usObjRoot); |
Tree nouvelArbre = new Tree(); |
nouvelArbre.setRootNode(root); |
// on la parse et on récupère les informations qui nous interessent |
for (Iterator<String> it= data.keySet().iterator(); it.hasNext();) { |
DateObservation ent=(DateObservation) data.get(it.next()); |
annee= ent.getAnnee() ; |
mois= ent.getMois() ; |
String moisLettre = renvoyerMois(Integer.parseInt(mois)) ; |
jour= ent.getJour() ; |
if(annee.contains("0000")) { |
annee="Inconnue" ; |
} |
if(jour.contains("00")) { |
jour="Inconnue" ; |
} |
Node noeudMemeAnnee = nouvelArbre.getNodeById(""+annee); |
// si la région existe déjà |
if(noeudMemeAnnee != null) |
{ |
// on teste si la localité existe |
Node noeudMemeMois = nouvelArbre.getNodeById(""+(annee+mois)); |
if(noeudMemeMois != null) |
{ |
// enfin on teste si le lieu dit existe |
Node noeudMemeJour = nouvelArbre.getNodeById(""+(annee+mois+jour)); |
if(noeudMemeJour != null) |
{ |
// tous les noeuds existent déjà, normalement ça ne devrait pas arriver |
} |
else |
{ |
// enfin on ne crée que le noeud du lieu dit |
TreeNode node_jour = new TreeNode(); |
node_jour.setId(""+(annee+mois+jour)); |
node_jour.setText(jour); |
noeudMemeMois.appendChild(node_jour) ; |
String[] usObj = {jour,jour,annee+mois+jour}; |
node_jour.setUserObject(usObj); |
} |
} |
else |
{ |
TreeNode node_mois = new TreeNode(); |
node_mois.setId(""+(annee+mois)); |
node_mois.setText(moisLettre); |
noeudMemeAnnee.appendChild(node_mois) ; |
String[] usObj = {moisLettre,mois,annee+mois}; |
node_mois.setUserObject(usObj); |
TreeNode node_jour = new TreeNode(); |
node_jour.setId(""+(annee+mois+jour)); |
node_jour.setText(jour); |
node_mois.appendChild(node_jour) ; |
String[] usObj2 = {jour,jour,annee+mois+jour}; |
node_jour.setUserObject(usObj2); |
} |
} |
else |
{ |
TreeNode node_annee = new TreeNode(); |
node_annee.setId(""+annee); |
node_annee.setText(annee); |
root.appendChild(node_annee) ; |
String[] usObj = {annee, annee, annee}; |
node_annee.setUserObject(usObj); |
TreeNode node_mois = new TreeNode(); |
node_mois.setId(""+(annee+mois)); |
node_mois.setText(moisLettre); |
node_annee.appendChild(node_mois) ; |
String[] usObj2 = {moisLettre,mois,annee+mois}; |
node_mois.setUserObject(usObj2); |
TreeNode node_jour = new TreeNode(); |
node_jour.setId(""+(annee+mois+jour)); |
node_jour.setText(jour); |
node_mois.appendChild(node_jour) ; |
String[] usObj3 = {jour,jour,annee+mois+jour}; |
node_jour.setUserObject(usObj3); |
} |
} |
// on trie |
root.sort(comparerNoeuds()) ; |
// on vide tous les noeuds |
arbreDonneesDates.getRootNode().eachChild(new NodeTraversalCallback() { |
public boolean execute(Node node) { |
node.remove(); |
return true; |
} |
}); |
// et on recopie le nouvel arbre |
copierFilsNoeud(nouvelArbre.getRootNode(), arbreDonneesDates |
.getRootNode()); |
// si l'arbre n'était pas encore considéré comme instancié |
if (!estInstancie) { |
// on signale que oui |
estInstancie = true; |
} |
// l'état du filtre est réinitialisé |
filtreModifie = false; |
//show() ; |
doLayout(); |
} |
if(nouvelleDonnees instanceof Observation) |
{ |
// si l'arbre n'est pas encore chargé, on ne tient pas compte de l'ajout |
// l'arbre complet sera de toute façon renvoyé plus tard lors du premier chargement |
// de l'arbre |
if(!arbreCharge) { |
return; |
} |
Observation ent = (Observation)nouvelleDonnees ; |
String dateSpl[] = ent.getDate().split("/") ; |
String annee= dateSpl[2]; |
String mois= dateSpl[1]; |
String jour= dateSpl[0]; |
String moisLettre = renvoyerMois(Integer.parseInt(mois)) ; |
Node root = arbreDonneesDates.getRootNode() ; |
if(annee.contains("0000") || annee.equals(null)) { |
annee="Inconnue" ; |
} |
if(jour.contains("00") || jour.equals(null)) { |
jour="Inconnue" ; |
} |
Node noeudMemeAnnee = arbreDonneesDates.getNodeById(""+annee); |
// si la région existe déjà |
if(noeudMemeAnnee != null) |
{ |
// on teste si la localité existe |
Node noeudMemeMois = arbreDonneesDates.getNodeById(""+(annee+mois)); |
if(noeudMemeMois != null) |
{ |
// enfin on teste si le lieu dit existe |
Node noeudMemeJour = arbreDonneesDates.getNodeById(""+(annee+mois+jour)); |
if(noeudMemeJour != null) |
{ |
// tous les noeuds existent déjà, normalement ça ne devrait pas arriver |
} |
else |
{ |
// enfin on ne crée que le noeud du lieu dit |
TreeNode node_jour = new TreeNode(); |
node_jour.setId(""+(annee+mois+jour)); |
node_jour.setText(jour); |
String[] usObj = {jour,jour,annee+mois+jour}; |
node_jour.setUserObject(usObj); |
noeudMemeMois.appendChild(node_jour) ; |
root.sort(comparerNoeuds()) ; |
} |
} |
else |
{ |
TreeNode node_mois = new TreeNode(); |
node_mois.setId(""+(annee+mois)); |
node_mois.setText(moisLettre); |
String[] usObj = {moisLettre,mois,annee+mois}; |
node_mois.setUserObject(usObj); |
noeudMemeAnnee.appendChild(node_mois) ; |
TreeNode node_jour = new TreeNode(); |
node_jour.setId(""+(annee+mois+jour)); |
node_jour.setText(jour); |
String[] usObj2 = {jour,jour,annee+mois+jour}; |
node_jour.setUserObject(usObj2); |
node_mois.appendChild(node_jour) ; |
root.sort(comparerNoeuds()) ; |
} |
} |
else |
{ |
TreeNode node_annee = new TreeNode(); |
node_annee.setId(""+annee); |
node_annee.setText(annee); |
String[] usObj = {annee,annee,annee}; |
node_annee.setUserObject(usObj); |
root.appendChild(node_annee) ; |
TreeNode node_mois = new TreeNode(); |
node_mois.setId(""+(annee+mois)); |
node_mois.setText(moisLettre); |
String[] usObj2 = {moisLettre,mois,annee+mois}; |
node_mois.setUserObject(usObj2); |
node_annee.appendChild(node_mois) ; |
TreeNode node_jour = new TreeNode(); |
node_jour.setId(""+(annee+mois+jour)); |
node_jour.setText(jour); |
String[] usObj3 = {jour,jour,annee+mois+jour}; |
node_jour.setUserObject(usObj3); |
node_mois.appendChild(node_jour) ; |
// TODO : améliorer la compararaison des noeuds |
root.sort(comparerNoeuds()) ; |
} |
arbreDonneesDates.doLayout() ; |
} |
} |
/** |
* Accesseur pour le panneau contenant l'arbre |
* |
* @return le panneau de l'arbre des mots clés |
*/ |
public TreePanel getArbreMotsCles() { |
return arbreDonneesDates; |
} |
/** |
* Méthode héritée de Filtrable renvoie le nom du filtre |
*/ |
public String renvoyerNomFiltre() { |
return "Dates"; |
} |
/** |
* Renvoie un tableau contenant le nom du champ à filtrer et la valeur |
* |
* @return un tableau contenant le nom du champ à filtrer et sa valeur |
*/ |
public String[] renvoyerValeursAFiltrer() { |
valider(); |
String valeursFiltrees[] = {nomFiltre, donneesDateEnCours } ; |
return valeursFiltrees; |
} |
/** |
* Fonction récursive qui prend deux noeuds d'arbre en paramètre et crée un |
* copie du sous arbre du premier noeud, qu'elle concatène au deuxième |
* |
* @param ndPereOriginal |
* le père des noeuds de l'arbre original |
* @param ndPereCopie |
* le père qui va recevoir les copies |
*/ |
private void copierFilsNoeud(Node ndPereOriginal, TreeNode ndPereCopie) { |
if (ndPereCopie != null && ndPereOriginal != null) { |
Node[] ndNodeFils = ndPereOriginal.getChildNodes(); |
for (int i = 0; i < ndNodeFils.length; i++) { |
String[] usObj = (String[]) ndNodeFils[i].getUserObject(); |
TreeNode child = new TreeNode(usObj[0]); |
child.setUserObject(usObj); |
child.setId(""+usObj[2]); |
ndPereCopie.appendChild(child); |
if (!ndNodeFils[i].isLeaf()) { |
copierFilsNoeud(ndNodeFils[i], child); |
} |
} |
} |
} |
/** |
* Méthode héritée de Filtrable Renvoie l'état du filtre (modifié ou non) |
*/ |
public boolean renvoyerEtatFiltre() { |
return filtreModifie; |
} |
public void valider() { |
if (estInstancie) { |
} |
} |
public Comparator<TreeNode> comparerNoeuds() |
{ |
return new Comparator<TreeNode>() { |
public int compare(TreeNode o1, TreeNode o2) { |
String n1 = ((String[])o1.getUserObject())[1] ; |
String n2 = ((String[])o2.getUserObject())[1] ; |
return n1.compareTo(n2) ; |
} |
} ; |
} |
public String renvoyerMois(int numMois) { |
switch (numMois) { |
case 1: |
return "janvier" ; |
case 2: |
return "fevrier" ; |
case 3: |
return "mars" ; |
case 4: |
return "avril" ; |
case 5: |
return "mai" ; |
case 6: |
return "juin" ; |
case 7: |
return "juillet" ; |
case 8: |
return "août" ; |
case 9: |
return "septembre" ; |
case 10: |
return "octobre" ; |
case 11: |
return "novembre" ; |
case 12: |
return "décembre" ; |
default: |
return "Inconnue" ; |
} |
} |
public void raz() { |
arbreCharge = false ; |
arbreDonneesDates.collapseAll(); |
arbreDonneesDates.clear(); |
TreeNode root = new TreeNode("Dates"); |
root.setId("racine_date"); |
String[] usObject = { "Dates", "Dates", "racine_date" }; |
root.setUserObject(usObject); |
arbreDonneesDates.setRootNode(root); |
arbreDonneesDates.getRootNode().addListener(new TreeNodeListenerAdapter() { |
public void onExpand(Node node) { |
if(!arbreCharge) |
{ |
observationMediateur.obtenirDatesObservation() ; |
arbreCharge = true ; |
} |
} |
}) ; |
this.doLayout() ; |
} |
} |
Property changes: |
Added: svn:mergeinfo |
/branches/becassine/src/org/tela_botanica/client/vues/observation/filtres/ArbreMotsClesObservationVue.java |
---|
New file |
0,0 → 1,520 |
package org.tela_botanica.client.vues.observation.filtres; |
import org.tela_botanica.client.interfaces.Rafraichissable; |
import org.tela_botanica.client.observation.ObservationMediateur; |
import com.google.gwt.user.client.Window; |
import com.gwtext.client.core.EventObject; |
import com.gwtext.client.data.Node; |
import com.gwtext.client.data.NodeTraversalCallback; |
import com.gwtext.client.data.Tree; |
import com.gwtext.client.widgets.Button; |
import com.gwtext.client.widgets.Panel; |
import com.gwtext.client.widgets.event.ButtonListenerAdapter; |
import com.gwtext.client.widgets.form.TextField; |
import com.gwtext.client.widgets.layout.VerticalLayout; |
import com.gwtext.client.widgets.tree.TreeEditor; |
import com.gwtext.client.widgets.tree.TreeNode; |
import com.gwtext.client.widgets.tree.TreePanel; |
import com.gwtext.client.widgets.tree.event.TreeNodeListenerAdapter; |
import com.gwtext.client.widgets.tree.event.TreePanelListenerAdapter; |
public class ArbreMotsClesObservationVue extends Panel implements Rafraichissable { |
/** |
* Le médiateur associé à la vue |
*/ |
private ObservationMediateur oMediateur = null; |
/** |
* Le treepanel qui affiche l'arbre |
*/ |
private static TreePanel arbreMotsCles = null; |
/** |
* L'éditeur qui permet de modifier les mots clés dans l'arbre |
*/ |
private TreeEditor te = null; |
/** |
* Le textfield associé à l'éditeur |
*/ |
private TextField tfEdit = null; |
/** |
* Bouton de validation |
*/ |
private Button valider = null; |
/** |
* Une string permettant connaitre les mots clés cochés en cours séparés par |
* des virgules |
*/ |
private String motsClesEnCours = ""; |
/** |
* Tableau contenant les mots clés qui n'ont pas encore été jaouté à l'arbre |
* (sert au lazy rendering quand on reçoit des mots clés avant que le rendu |
* du conteneur n'ai été effectué) |
*/ |
private String[] motsClesEnAttente = new String[0]; |
/** |
* Booléen d'évènement qui sert à savoir si on est en train d'ajouter un |
* noeud |
*/ |
private boolean ajoutNoeud = false; |
/** |
* Booléen d'évènement qui sert à savoir si on est en train de modifier un |
* noeud |
*/ |
private boolean modifNoeud = false; |
/** |
* Booléen d'instanciation du conteneur |
*/ |
private boolean arbreCharge = false; |
/** |
* Booléen d'évènement qui sert à savoir si les mots clés ont bien été reçu |
*/ |
private boolean motsCleInitialises; |
/** |
* Constructeur sans paramètre (privé car interdit d'utilisation) |
*/ |
@SuppressWarnings("unused") |
private ArbreMotsClesObservationVue() { |
super(); |
} |
/** |
* Constructeur avec paramètre |
* |
* @param im |
* le médiateur à associer |
*/ |
public ArbreMotsClesObservationVue(ObservationMediateur om) { |
// on crée le panel |
super("Mots clés"); |
this.setLayout(new VerticalLayout()); |
oMediateur = om; |
// on crée le conteneur de l'arbre |
arbreMotsCles = new TreePanel(); |
// on permet le drag and drop dans l'arbre |
arbreMotsCles.setEnableDD(true); |
arbreMotsCles.setId("x-view-tree-keyword-obs"); |
// on crée une racine pour l'arbre |
TreeNode root = new TreeNode("Tags"); |
root.setId("racine_obs"); |
String[] usObject = { "Mots clés", "racine" }; |
root.setUserObject(usObject); |
root.setExpandable(true); |
arbreMotsCles.setRootNode(root); |
arbreMotsCles.setRootVisible(true); |
arbreMotsCles.setBorder(false); |
// arbreMotsCles.setWidth(500); |
arbreMotsCles.getRootNode().addListener(new TreeNodeListenerAdapter() { |
public void onClick(Node node, EventObject e) { |
if(!arbreCharge) { |
expand(); |
} |
} |
public void onExpand(Node node) { |
if(!arbreCharge) { |
obtenirArbreMotsCles(); |
arbreCharge = true; |
} |
} |
}); |
// on crée l'éditeur pour l'arbre |
tfEdit = new TextField(); |
te = new TreeEditor(arbreMotsCles, tfEdit); |
valider = new Button("Appliquer"); |
arbreMotsCles.add(te); |
// on met en forme le layout |
this.add(arbreMotsCles); |
this.add(valider); |
this.setBorder(false); |
this.setCollapsible(true); |
this.setTitleCollapse(true); |
// on ajoute les listeners |
ajouterListeners(); |
} |
/** |
* Acesseur pour le médiateur |
* |
* @return le médiateur associé à la vue |
*/ |
private ObservationMediateur getOMediateur() { |
return oMediateur; |
} |
/** |
* Acesseur pour l'arbre des mots clés |
* |
* @return le panel contenant l'arbre |
*/ |
public TreePanel getArbreMotsCles() { |
return arbreMotsCles; |
} |
/** |
* Accesseur pour l'éditeur |
* |
* @return l'éditeur associé à l'arbre |
*/ |
public TreeEditor getTe() { |
return te; |
} |
/** |
* Acesseur pour le TextField associé à l'éditeur |
* |
* @return le champ texte associé à l'éditeur |
*/ |
public TextField getTfEdit() { |
return tfEdit; |
} |
/** |
* Ajoute les listeners nécessaires pour la gestion des évènements |
*/ |
private void ajouterListeners() { |
arbreMotsCles.addListener(new TreePanelListenerAdapter() { |
// gestion du clic sur un noeud |
public void onClick(TreeNode node, EventObject e) { |
e.stopEvent(); |
gererClicNoeud(node); |
} |
// gestion du clic droit sur un noeud |
public void onContextMenu(TreeNode node, EventObject e) { |
e.stopEvent(); |
getOMediateur().montrerContextMenuArbre(node, e, getTe()); |
} |
// gestion du double clic sur un noeud |
public void onDblClick(TreeNode node, EventObject e) { |
modifNoeud = true; |
if (!node.getId().equals("racine_obs")) { |
te.startEdit(node); |
} |
} |
// gestion de la modification du texte d'un noeud |
public void onTextChange(TreeNode node, String text, String oldText) { |
// on récupère les informations associées au noeud |
TreeNode nd = node; |
String[] usObject = new String[2]; |
usObject[0] = text; |
usObject[1] = ((String[]) nd.getUserObject())[1]; |
nd.setUserObject(usObject); |
// si c'est un nouveau noeud |
if (ajoutNoeud) { |
// on notifie le médiateur de l'ajout et on lui passe |
// l'arbre |
getOMediateur().ajouterMotCleDansArbre(nd, |
getArbreMotsCles().getTree()); |
// et considère l'ajout achevé |
ajoutNoeud = false; |
} |
// si c'est noeud déjà existant |
else { |
if (modifNoeud) { |
// on notifie le médiateur de la modification et on lui |
// passe l'arbre |
getOMediateur().modifierMotCleDansArbre(nd, |
getArbreMotsCles().getTree()); |
// et on considère la modification achevée |
modifNoeud = false; |
} |
} |
} |
// gestion du déplacement d'un noeud |
public void onMoveNode(Tree tree, TreeNode node, |
TreeNode oldParent, TreeNode newParent, int index) { |
// on notifie le médiateur et on lui passe l'arbre |
getOMediateur().deplacerMotCleDansArbre(node, |
getArbreMotsCles().getTree()); |
} |
}); |
// gestion de la validation |
valider.addListener(new ButtonListenerAdapter() { |
// lors du clic |
public void onClick(Button button, EventObject e) { |
// on vide les mots clés en cours |
motsClesEnCours = ""; |
// pour chaque noeud à partir de la racine |
getArbreMotsCles().getRootNode().cascade( |
new NodeTraversalCallback() { |
// on éxécute une fonction |
public boolean execute(Node node) { |
// on récupère le mot clé associé au noeud et |
// ses infos |
TreeNode tn = getArbreMotsCles().getNodeById( |
node.getId()); |
String[] usObject = (String[]) tn |
.getUserObject(); |
getOMediateur().mettreAjourMotsClesId( |
usObject[0], usObject[1]); |
if (tn.getUI().isChecked()) { |
// et les concatène à la string des mots |
// clés en cours |
motsClesEnCours += usObject[1] + ","; |
} |
return true; |
} |
}); |
// enfin on notifie le médiateur et on lui passe l'arbre et la |
// liste des mots clés ainsi obtenue |
getOMediateur().mettreAjourMotsCles(motsClesEnCours, |
arbreMotsCles.getTree()); |
} |
}); |
} |
/** |
* Envoie une demande au médiateur pour obtenir l'arbre des mots clés |
*/ |
public void obtenirArbreMotsCles() { |
getOMediateur().obtenirArbreMotsCles(this); |
} |
/** |
* Supprime un noeud de l'arbre |
* |
* @param n |
* le noeud à supprimer |
*/ |
public void supprimerNoeud(TreeNode n) { |
// si ça n'est pas la racine (qu'on ne peut pas supprimer) |
if (!n.getId().equals(getArbreMotsCles().getRootNode().getId())) { |
// on détache le noeud et on le détruit |
n.getParentNode().removeChild(n); |
n.destroy(); |
// puis on en notifie le médiateur en lui passant le noeud supprimé |
// et l'arbre |
getOMediateur() |
.supprimerMotCleDansArbre(n, arbreMotsCles.getTree()); |
} else { |
// si l'utilisateur tente de supprimer la racine, on l'avertit de |
// son erreur |
Window.alert("Impossible de supprimer la racine de l'arbre"); |
} |
} |
/** |
* Ajoute un noeud dans l'arbre au parent donné |
* |
* @param parent |
* le futur parent du noeud à ajouter |
*/ |
public void ajouterNoeud(TreeNode parent) { |
// on met l'ajout du noeud à vrai |
ajoutNoeud = true; |
// on crée un nouveau noeud vide |
TreeNode nd = new TreeNode(""); |
nd.setCls("x-view-treenode-keyword"); |
nd.setChecked(true); |
// on associe un objet au noeud qui contient des infos |
String[] usObject = new String[2]; |
// l'objet contient le nom du noeud |
usObject[0] = ""; |
usObject[1] = genererIdMotCle(nd); |
nd.setId(usObject[1]); |
nd.setUserObject(usObject); |
// l'identifiant d'un noeud c'est son hashcode |
// l'objet associé au noeud contient aussi son identifiant |
// on le concatène au parent et on étend ses enfants |
parent.appendChild(nd); |
parent.expand(); |
// enfin on place le curseur et on fait apparaitre le champ d'édition |
// pour que l'utilisateur nomme son mot clé |
te.startEdit(nd); |
} |
/** |
* Coche le noeud s'il est décoché, le décoche sinon |
* |
* @param node |
*/ |
public void gererClicNoeud(TreeNode node) { |
if (node.getUI().isChecked()) { |
node.getUI().toggleCheck(false); |
} else { |
node.getUI().toggleCheck(true); |
} |
} |
/** |
* Parcourt l'arbre et coche les noeud qui font partie de la liste des mots |
* clés à cocher |
* |
* @param motsClesIds |
* un tableau contenant les identifiants des mots clés à cocher |
*/ |
public void cocherMotsCles(final String[] motsClesIds) { |
if (getArbreMotsCles() != null |
&& getArbreMotsCles().getRootNode() != null) { |
// à partir de la racine |
getArbreMotsCles().getRootNode().cascade( |
new NodeTraversalCallback() { |
// pour chaque noeud |
public boolean execute(Node node) { |
getArbreMotsCles().getNodeById(node.getId()) |
.getUI().toggleCheck(false); |
// on parcourt le tableau des mots clés |
for (int i = 0; i < motsClesIds.length; i++) { |
// si le mot clé fait partie des id à cocher on |
// le coche |
String usObject[] = (String[]) node |
.getUserObject(); |
String nodeId = usObject[1]; |
if (nodeId.equals(motsClesIds[i])) { |
getArbreMotsCles().getNodeById(nodeId+"_obs") |
.getUI().toggleCheck(true); |
return true; |
} |
} |
// et on passe au suivant |
return true; |
} |
}); |
} |
else { |
motsClesEnAttente = motsClesIds ; |
} |
} |
/** |
* Méthode héritée de l'interface rafraichissable |
* |
* @param nouvelleDonnees |
* les nouvelles données pour l'objet |
* @param repandreRafraichissement |
* booleen qui dit si on doit répandre l'évenement |
*/ |
public void rafraichir(Object nouvelleDonnees, |
boolean repandreRafraichissement) { |
if(nouvelleDonnees instanceof Tree) { |
Tree nouvelArbre = (Tree)nouvelleDonnees ; |
// on prend sa racine et on l'attache à l'arbre des mots clés |
Node[] rootChild = getArbreMotsCles().getRootNode().getChildNodes(); |
for (int i = 0; i < rootChild.length; i++) { |
rootChild[i].remove(); |
} |
copierFilsNoeud(nouvelArbre.getRootNode(),getArbreMotsCles().getRootNode()); |
// si l'arbre n'était pas encore considéré comme instancié |
if (!arbreCharge) { |
// on signale que oui |
arbreCharge = true; |
} |
// s'il y a des mots clés en attente (lors du premier rendering) |
if (motsCleInitialises == false && motsClesEnAttente != null) { |
// on les coche |
// cocherMotsCles(motsClesEnAttente) ; |
motsCleInitialises = true; |
} |
if(motsClesEnAttente.length > 0) { |
cocherMotsCles(motsClesEnAttente); |
} |
} |
// Si on reçoit un tableau de String (cas ou l'on séléectionne une |
// nouvelle image) |
if (nouvelleDonnees instanceof String[]) { |
// et que l'arbre est instancié |
if (arbreCharge) { |
// le tableau de String contient les id des mots clés associés à |
// l'image |
// on coche les mots clés contenu dans le tableau |
String[] motsClesIds = (String[]) nouvelleDonnees; |
cocherMotsCles(motsClesIds); |
} |
// si l'arbre n'est pas encore instancié on met les mots clés en |
// attente |
else { |
motsClesEnAttente = (String[]) nouvelleDonnees; |
} |
} |
} |
private String genererIdMotCle(TreeNode nd) { |
return "" + (nd.hashCode() + (Math.random() * 10000)); |
} |
/** |
* Fonction récursive qui prend deux noeuds d'arbre en paramètre et crée un |
* copie du sous arbre du premier noeud, qu'elle concatène au deuxième |
* |
* @param ndPereOriginal |
* le père des noeuds de l'arbre original |
* @param ndPereCopie |
* le père qui va recevoir les copies |
*/ |
private void copierFilsNoeud(Node ndPereOriginal, TreeNode ndPereCopie) { |
if (ndPereCopie != null && ndPereOriginal != null) { |
Node[] ndNodeFils = ndPereOriginal.getChildNodes(); |
for (int i = 0; i < ndNodeFils.length; i++) { |
String[] usObj = (String[]) ndNodeFils[i].getUserObject(); |
TreeNode child = new TreeNode(usObj[0]); |
child.setId(usObj[1] +"_obs"); |
child.setChecked(false); |
child.setUserObject(usObj); |
ndPereCopie.appendChild(child); |
if (!ndNodeFils[i].isLeaf()) { |
copierFilsNoeud(ndNodeFils[i], child); |
} |
} |
} |
} |
} |
Property changes: |
Added: svn:mergeinfo |