Project

General

Profile

Download (3.26 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.util;
11

    
12
import java.util.Collection;
13

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

    
16
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
17
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
18
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
19
import eu.etaxonomy.taxeditor.store.CdmStore;
20

    
21
/**
22
 * @author pplitzner
23
 * @date 05.09.2017
24
 *
25
 */
26
public class TaxonTreeNodeContentProvider implements ITreeContentProvider {
27

    
28
    private static final Object[] NO_CHILDREN = new Object[0];
29

    
30
    private ITaxonNodeService taxonNodeService;
31

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

    
43
    /**
44
     * {@inheritDoc}
45
     */
46
    @Override
47
    public Object[] getChildren(Object parentElement) {
48
        if (taxonNodeService == null){
49
            taxonNodeService = CdmStore.getService(ITaxonNodeService.class);
50
        }
51
        Object[] children = null;
52

    
53
//        if(parentElement instanceof Classification){
54
//            children = taxonNodeService.listChildNodesAsUuidAndTitleCache(((Classification)parentElement).getRootNode()).toArray();
55
////            children = ((Classification) parentElement).getChildNodes().toArray();
56
//        }
57
//        //taxon node
58
//        if(parentElement instanceof ITaxonTreeNode){
59
//            ITaxonTreeNode treeNode = (ITaxonTreeNode) HibernateProxyHelper.deproxy(parentElement);
60
//            List<TaxonNode> childrenSet = treeNode.getChildNodes();
61
//            HHH_9751_Util.removeAllNull(childrenSet);
62
//            children = childrenSet.toArray();
63
//        }
64

    
65
        if(parentElement instanceof TaxonNode){
66
            children = taxonNodeService.listChildNodesAsTaxonNodeDto((TaxonNode)parentElement).toArray();
67
        }else {
68
            children = taxonNodeService.listChildNodesAsTaxonNodeDto((TaxonNodeDto)parentElement).toArray();
69
        }
70

    
71
        return children != null ? children : NO_CHILDREN;
72
    }
73

    
74
    /**
75
     * {@inheritDoc}
76
     */
77
    @Override
78
    public Object getParent(Object element) {
79
        if (taxonNodeService == null){
80
            taxonNodeService = CdmStore.getService(ITaxonNodeService.class);
81
        }
82
        if(element instanceof TaxonNodeDto){
83
            if (((TaxonNodeDto) element).getParentUUID() != null){
84
                TaxonNode parent = taxonNodeService.load(((TaxonNodeDto) element).getParentUUID());
85
                return new TaxonNodeDto(parent);
86
            }
87
        }
88
        return null;
89
    }
90

    
91
    /**
92
     * {@inheritDoc}
93
     */
94
    @Override
95
    public boolean hasChildren(Object element) {
96
        if(element instanceof TaxonNode){
97
            return ((TaxonNode) element).getCountChildren() > 0;
98
        }
99
        if (element instanceof TaxonNodeDto){
100
            return ((TaxonNodeDto)element).getTaxonomicChildrenCount()>0;
101
        }
102
        return this.getChildren(element).length > 0;
103
    }
104

    
105
}
(4-4/5)