Project

General

Profile

Download (2.96 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2017 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.navigation.navigator.e4;
11

    
12
import java.util.List;
13

    
14
import org.eclipse.jface.viewers.ITreeContentProvider;
15

    
16
import eu.etaxonomy.cdm.hibernate.HHH_9751_Util;
17
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
18
import eu.etaxonomy.cdm.model.taxon.Classification;
19
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
20
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
21
import eu.etaxonomy.taxeditor.navigation.navigator.Root;
22

    
23
/**
24
 * @author pplitzner
25
 * @date 05.09.2017
26
 *
27
 */
28
public class TaxonNavigatorContentProviderE4 implements ITreeContentProvider {
29

    
30
    private static final Object[] NO_CHILDREN = new Object[0];
31

    
32
    /**
33
     * {@inheritDoc}
34
     */
35
    @Override
36
    public Object[] getElements(Object inputElement) {
37
        return this.getChildren(inputElement);
38
    }
39

    
40
    /**
41
     * {@inheritDoc}
42
     */
43
    @Override
44
    public Object[] getChildren(Object parentElement) {
45
        Object[] children = null;
46

    
47
        if (parentElement instanceof Root) {
48
            children = ((Root) parentElement).getParentBeans().toArray();
49
        }else if(parentElement instanceof Classification){
50
            children = ((Classification) parentElement).getChildNodes().toArray();
51
        }
52
        //FIXME E4 show synonym in navigator?
53
//        //synonym
54
//        if (parentElement instanceof Synonym) {
55
//            children = NO_CHILDREN;
56
//        } else if (parentElement instanceof TaxonNode) {
57
//            List<TaxonBase> list = new ArrayList<TaxonBase>();
58
//
59
//            Taxon taxon = ((TaxonNode) parentElement).getTaxon();
60
//
61
//            for (TaxonBase taxonBase : new IterableSynonymyList(taxon)) {
62
//                if (taxonBase instanceof Synonym) {
63
//                    list.add(taxonBase);
64
//                }
65
//            }
66
//            children = list.toArray();
67
//        }
68
        //taxon node
69
        if(parentElement instanceof ITaxonTreeNode){
70
            ITaxonTreeNode treeNode = (ITaxonTreeNode) HibernateProxyHelper.deproxy(parentElement);
71
            List<TaxonNode> childrenSet = treeNode.getChildNodes();
72
            HHH_9751_Util.removeAllNull(childrenSet);
73
            children = childrenSet.toArray();
74
        }
75
        return children != null ? children : NO_CHILDREN;
76
    }
77

    
78
    /**
79
     * {@inheritDoc}
80
     */
81
    @Override
82
    public Object getParent(Object element) {
83
        if(element instanceof TaxonNode){
84
            return ((TaxonNode) element).getParent();
85
        }
86
        return null;
87
    }
88

    
89
    /**
90
     * {@inheritDoc}
91
     */
92
    @Override
93
    public boolean hasChildren(Object element) {
94
        if(element instanceof TaxonNode){
95
            return ((TaxonNode) element).getCountChildren() > 0;
96
        }
97
        return this.getChildren(element).length > 0;
98
    }
99

    
100
}
(1-1/6)