Search in sources :

Example 6 with TreeNode

use of org.primefaces.model.TreeNode in project opentheso by miledrousset.

the class NewTreeBean method reExpandTree.

/**
 * Expansion automatique de la racine
 *
 * @param listeId
 * @param idTheso
 * @param langue
 */
private void reExpandTree(ArrayList<ArrayList<String>> listeId, String idTheso, String langue, TreeChange tc) {
    // if(selectedNodes.isEmpty()){
    // idem
    ArrayList<MyTreeNode> listeNode = new ArrayList<>();
    if (root.getChildCount() == 0) {
        // On recrée la racine
        List<NodeGroup> racineNode = new GroupHelper().getListRootConceptGroup(connect.getPoolConnexion(), idTheso, langue);
        Collections.sort(racineNode);
        for (NodeGroup nodegroup : racineNode) {
            TreeNode dynamicTreeNode;
            String typeCode = nodegroup.getConceptGroup().getIdtypecode();
            String type = getTypeOfGroup(typeCode);
            // intégration des groupes
            if (nodegroup.getLexicalValue().trim().isEmpty()) {
                dynamicTreeNode = (TreeNode) new MyTreeNode(1, nodegroup.getConceptGroup().getIdgroup(), nodegroup.getConceptGroup().getIdthesaurus(), nodegroup.getIdLang(), nodegroup.getConceptGroup().getIdgroup(), nodegroup.getConceptGroup().getIdtypecode(), null, type, nodegroup.getConceptGroup().getIdgroup(), root);
                ((MyTreeNode) dynamicTreeNode).setIsGroup(true);
                new DefaultTreeNode("fake", dynamicTreeNode);
            } else {
                dynamicTreeNode = (TreeNode) new MyTreeNode(1, nodegroup.getConceptGroup().getIdgroup(), nodegroup.getConceptGroup().getIdthesaurus(), nodegroup.getIdLang(), nodegroup.getConceptGroup().getIdgroup(), nodegroup.getConceptGroup().getIdtypecode(), null, type, nodegroup.getLexicalValue(), null);
                ((MyTreeNode) dynamicTreeNode).setIsGroup(true);
                /**
                 **code pour la numérotation des groupes *****************
                 */
                GroupHelper groupHelper = new GroupHelper();
                String suffix = groupHelper.getSuffixFromNode(connect.getPoolConnexion(), nodegroup.getConceptGroup().getIdthesaurus(), nodegroup.getConceptGroup().getIdgroup());
                // ici c'est un groupe donc pas de suffix
                ((MyTreeNode) dynamicTreeNode).setPrefix(suffix);
                ((MyTreeNode) dynamicTreeNode).setData(((MyTreeNode) dynamicTreeNode).getNumerotation() + " " + dynamicTreeNode.getData());
                /**
                 ***fin de code pour la numérotation des groupes *********
                 */
                listeNode.add((MyTreeNode) dynamicTreeNode);
            }
        }
        /**
         *ici on trie la liste des groupes d après le champ data**
         */
        Collections.sort(listeNode, new TreeNodeComparator());
        /*et on l'ajoute au root **/
        // on récupère les noeuds qui étaient étendus
        ArrayList idToExpand = new ArrayList<>();
        for (TreeNode tn : tc.getExpandedNodes()) {
            idToExpand.add(((MyTreeNode) tn).getIdConcept());
        }
        for (MyTreeNode mtn : listeNode) {
            MyTreeNode tmp = new MyTreeNode(1, mtn.getIdConcept(), mtn.getIdTheso(), mtn.getLangue(), mtn.getIdConcept(), mtn.getTypeDomaine(), mtn.getIdTopConcept(), mtn.getType(), mtn.getData(), root);
            tmp.setPrefix(mtn.getPrefix());
            tmp.setSuffix(mtn.getSuffix());
            tmp.setIsGroup(true);
            new DefaultTreeNode(null, tmp);
            if (idToExpand.contains(mtn.getIdConcept())) {
                mtn.setExpanded(true);
                this.onNodeExpand(mtn);
            }
        }
        /**
         *fin **
         */
        loadOrphan(idTheso, langue);
        // loadOrphan(idTheso, langue);
        for (TreeNode tn : root.getChildren()) {
            if (tn.getType().equals("orphan")) {
                for (TreeNode tn2 : tn.getChildren()) {
                    for (ArrayList<String> tabId : listeId) {
                        if (tabId.size() == 2 && tabId.get(1).equals(((MyTreeNode) tn2).getIdConcept())) {
                            tn2.setSelected(true);
                            selectedNode = tn2;
                            selectedNodes.add(tn2);
                        } else {
                            if (tabId.get(1).equals(((MyTreeNode) tn2).getIdConcept())) {
                                reExpandChild(tabId, (MyTreeNode) tn2, 2);
                            }
                        }
                    }
                }
            }
        }
    } else {
        List<TreeNode> racineNode = root.getChildren();
        for (TreeNode dynamicTreeNode : racineNode) {
            if (!dynamicTreeNode.getType().equals("orphan")) {
                for (ArrayList<String> tabId : listeId) {
                    // Si c'est le , on étend
                    if (tabId.size() > 1 && tabId.get(0) != null) {
                        if (tabId.get(0).equals(((MyTreeNode) dynamicTreeNode).getIdCurrentGroup())) {
                            reExpandChild(tabId, (MyTreeNode) dynamicTreeNode, 1);
                        }
                    } else {
                        if (tabId.get(1).equals(((MyTreeNode) dynamicTreeNode).getIdCurrentGroup())) {
                            dynamicTreeNode.setSelected(true);
                            selectedNode = dynamicTreeNode;
                            selectedNodes.add(dynamicTreeNode);
                        } else {
                            dynamicTreeNode.setSelected(false);
                        }
                    }
                }
            } else {
                for (TreeNode tn2 : dynamicTreeNode.getChildren()) {
                    for (ArrayList<String> tabId : listeId) {
                        if (tabId.size() == 2 && tabId.get(1).equals(((MyTreeNode) tn2).getIdConcept())) {
                            tn2.setSelected(true);
                            selectedNode = tn2;
                            selectedNodes.add(tn2);
                        } else {
                            if (tabId.get(1).equals(((MyTreeNode) tn2).getIdConcept())) {
                                reExpandChild(tabId, (MyTreeNode) tn2, 2);
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : MyTreeNode(mom.trd.opentheso.bdd.helper.nodes.MyTreeNode) TreeNode(org.primefaces.model.TreeNode) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) ArrayList(java.util.ArrayList) MyTreeNode(mom.trd.opentheso.bdd.helper.nodes.MyTreeNode) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper) NodeGroup(mom.trd.opentheso.bdd.helper.nodes.group.NodeGroup)

Example 7 with TreeNode

use of org.primefaces.model.TreeNode in project opentheso by miledrousset.

the class NewTreeBean method initTree.

public void initTree(String idTheso, String langue) {
    // idThesoSelected = idTheso;
    // defaultLanguage = langue;
    root = (TreeNode) new DefaultTreeNode("Root", null);
    // attribut pour la numérotation des groupes
    int count = 1;
    // idem
    ArrayList<MyTreeNode> listeNode = new ArrayList<>();
    if (connect.getPoolConnexion() == null) {
        System.err.println("Opentheso n'a pas pu se connecter à la base de données");
        return;
    }
    List<NodeGroup> racineNode = new GroupHelper().getListRootConceptGroup(connect.getPoolConnexion(), idTheso, langue);
    Collections.sort(racineNode);
    // Les premiers noeuds de l'arbre sont de type Groupe (isGroup = true)
    for (NodeGroup nodegroup : racineNode) {
        String typeCode = nodegroup.getConceptGroup().getIdtypecode();
        String type = getTypeOfGroup(typeCode);
        if (nodegroup.getLexicalValue().trim().isEmpty()) {
            TreeNode dynamicTreeNode = (TreeNode) new MyTreeNode(1, nodegroup.getConceptGroup().getIdgroup(), nodegroup.getConceptGroup().getIdthesaurus(), nodegroup.getIdLang(), nodegroup.getConceptGroup().getIdgroup(), nodegroup.getConceptGroup().getIdtypecode(), null, type, nodegroup.getConceptGroup().getIdgroup(), root);
            ((MyTreeNode) dynamicTreeNode).setIsGroup(true);
            new DefaultTreeNode("facette", dynamicTreeNode);
        } else {
            TreeNode dynamicTreeNode = (TreeNode) new MyTreeNode(1, nodegroup.getConceptGroup().getIdgroup(), nodegroup.getConceptGroup().getIdthesaurus(), nodegroup.getIdLang(), nodegroup.getConceptGroup().getIdgroup(), nodegroup.getConceptGroup().getIdtypecode(), null, type, nodegroup.getLexicalValue(), null);
            ((MyTreeNode) dynamicTreeNode).setIsGroup(true);
            /**
             **code pour la numérotation des groupes *****************
             */
            GroupHelper groupHelper = new GroupHelper();
            String suffix = groupHelper.getSuffixFromNode(connect.getPoolConnexion(), nodegroup.getConceptGroup().getIdthesaurus(), nodegroup.getConceptGroup().getIdgroup());
            if (suffix.equalsIgnoreCase("0") || suffix.equalsIgnoreCase("00")) {
                suffix = "" + count;
                count++;
                groupHelper.saveSuffixFromNode(connect.getPoolConnexion(), nodegroup.getConceptGroup().getIdthesaurus(), nodegroup.getConceptGroup().getIdgroup(), suffix);
            }
            // ici c'est un groupe donc pas de suffix
            ((MyTreeNode) dynamicTreeNode).setPrefix(suffix);
            ((MyTreeNode) dynamicTreeNode).setData(((MyTreeNode) dynamicTreeNode).getNumerotation() + " " + dynamicTreeNode.getData());
            /**
             ***fin de code pour la numérotation des groupes *********
             */
            new DefaultTreeNode("facette", dynamicTreeNode);
            listeNode.add((MyTreeNode) dynamicTreeNode);
        }
    }
    /**
     *ici on trie la liste des groupes d après le champ data**
     */
    Collections.sort(listeNode, new TreeNodeComparator());
    /*et on l'ajoute au root **/
    for (MyTreeNode mtn : listeNode) {
        MyTreeNode tmp = new MyTreeNode(1, mtn.getIdConcept(), mtn.getIdTheso(), mtn.getLangue(), mtn.getIdConcept(), mtn.getTypeDomaine(), mtn.getIdTopConcept(), mtn.getType(), mtn.getData(), root);
        tmp.setPrefix(mtn.getPrefix());
        tmp.setSuffix(mtn.getSuffix());
        tmp.setIsGroup(true);
        new DefaultTreeNode(null, tmp);
    }
    /**
     *fin **
     */
    if (idTheso != null) {
        loadOrphan(idTheso, langue);
    }
}
Also used : DefaultTreeNode(org.primefaces.model.DefaultTreeNode) MyTreeNode(mom.trd.opentheso.bdd.helper.nodes.MyTreeNode) TreeNode(org.primefaces.model.TreeNode) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) ArrayList(java.util.ArrayList) MyTreeNode(mom.trd.opentheso.bdd.helper.nodes.MyTreeNode) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper) NodeGroup(mom.trd.opentheso.bdd.helper.nodes.group.NodeGroup)

Example 8 with TreeNode

use of org.primefaces.model.TreeNode in project opentheso by miledrousset.

the class SelectedTerme method initTree.

/**
 * Récupère les concept pour remplir la racine de l'arbre des facette
 */
public void initTree() {
    List<Integer> idFacettes = new FacetHelper().getIdFacetOfConcept(connect.getPoolConnexion(), idC, idTheso);
    ArrayList<NodeConceptTree> racineNode = new ArrayList<>();
    for (Integer i : idFacettes) {
        racineNode.add(new FacetHelper().getConceptOnFacet(connect.getPoolConnexion(), i, idTheso, idlangue));
    }
    for (NodeConceptTree n : racineNode) {
        TreeNode dynamicTreeNode;
        if (n.getTitle().trim().isEmpty()) {
            dynamicTreeNode = (TreeNode) new MyTreeNode(1, n.getIdConcept(), idTheso, idlangue, "", "", "", "dossier", n.getIdConcept(), root);
        } else {
            dynamicTreeNode = (TreeNode) new MyTreeNode(1, n.getIdConcept(), idTheso, idlangue, "", "", "", "dossier", n.getTitle(), root);
        }
        DefaultTreeNode defaultTreeNode = new DefaultTreeNode("fake", dynamicTreeNode);
        defaultTreeNode.setExpanded(true);
    }
}
Also used : NodeConceptTree(mom.trd.opentheso.bdd.helper.nodes.concept.NodeConceptTree) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) MyTreeNode(mom.trd.opentheso.bdd.helper.nodes.MyTreeNode) TreeNode(org.primefaces.model.TreeNode) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) ArrayList(java.util.ArrayList) FacetHelper(mom.trd.opentheso.bdd.helper.FacetHelper) MyTreeNode(mom.trd.opentheso.bdd.helper.nodes.MyTreeNode)

Example 9 with TreeNode

use of org.primefaces.model.TreeNode in project opentheso by miledrousset.

the class NewTreeBean method changeGroupType.

public void changeGroupType(String type) {
    MyTreeNode myTN = (MyTreeNode) this.selectedNode;
    if (!myTN.isIsGroup() && !myTN.isIsSubGroup()) {
        // normalement impossible
        return;
    }
    if (myTN.getTypeDomaine().equals(type)) {
        return;
    } else {
        myTN.setTypeDomaine(type);
        GroupHelper gh = new GroupHelper();
        gh.updateTypeGroup(this.connect.getPoolConnexion(), type, idThesoSelected, myTN.getIdConcept());
        ConceptHelper ch = new ConceptHelper();
        this.onNodeExpand(myTN);
        for (TreeNode sbn : myTN.getChildren()) {
            if (((MyTreeNode) sbn).isIsSubGroup())
                changeGroupType(type, sbn);
        }
    }
    reInit();
    this.initTree(idThesoSelected, myTN.getLangue());
    reExpand();
}
Also used : ConceptHelper(mom.trd.opentheso.bdd.helper.ConceptHelper) MyTreeNode(mom.trd.opentheso.bdd.helper.nodes.MyTreeNode) TreeNode(org.primefaces.model.TreeNode) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) MyTreeNode(mom.trd.opentheso.bdd.helper.nodes.MyTreeNode) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper)

Example 10 with TreeNode

use of org.primefaces.model.TreeNode in project opentheso by miledrousset.

the class NewTreeBean method changeGroupType.

public void changeGroupType(String type, TreeNode sbn) {
    ((MyTreeNode) sbn).setTypeDomaine(type);
    GroupHelper gh = new GroupHelper();
    gh.updateTypeGroup(this.connect.getPoolConnexion(), type, idThesoSelected, ((MyTreeNode) sbn).getIdConcept());
    this.onNodeExpand(sbn);
    for (TreeNode sn : sbn.getChildren()) {
        if (((MyTreeNode) sn).isIsSubGroup())
            changeGroupType(type, sn);
    }
}
Also used : MyTreeNode(mom.trd.opentheso.bdd.helper.nodes.MyTreeNode) TreeNode(org.primefaces.model.TreeNode) DefaultTreeNode(org.primefaces.model.DefaultTreeNode) MyTreeNode(mom.trd.opentheso.bdd.helper.nodes.MyTreeNode) GroupHelper(mom.trd.opentheso.bdd.helper.GroupHelper)

Aggregations

MyTreeNode (mom.trd.opentheso.bdd.helper.nodes.MyTreeNode)13 DefaultTreeNode (org.primefaces.model.DefaultTreeNode)13 TreeNode (org.primefaces.model.TreeNode)13 ArrayList (java.util.ArrayList)5 ConceptHelper (mom.trd.opentheso.bdd.helper.ConceptHelper)5 GroupHelper (mom.trd.opentheso.bdd.helper.GroupHelper)5 NodeConceptTree (mom.trd.opentheso.bdd.helper.nodes.concept.NodeConceptTree)3 FacetHelper (mom.trd.opentheso.bdd.helper.FacetHelper)2 NodeGroup (mom.trd.opentheso.bdd.helper.nodes.group.NodeGroup)2 Concept (mom.trd.opentheso.bdd.datas.Concept)1 Term (mom.trd.opentheso.bdd.datas.Term)1 OrphanHelper (mom.trd.opentheso.bdd.helper.OrphanHelper)1 TermHelper (mom.trd.opentheso.bdd.helper.TermHelper)1 StructIdBroaderTerm (mom.trd.opentheso.dragdrop.StructIdBroaderTerm)1 TreeChange (mom.trd.opentheso.dragdrop.TreeChange)1