Project

General

Profile

Download (3.33 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.cdm.persistence.dto.UuidAndTitleCache;
20
import eu.etaxonomy.taxeditor.store.CdmStore;
21

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

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

    
31
    private ITaxonNodeService taxonNodeService;
32

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

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

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

    
66
        if(parentElement instanceof TaxonNode){
67
            children = taxonNodeService.listChildNodesAsTaxonNodeDto((TaxonNode)parentElement).toArray();
68
        }else {
69
            children = taxonNodeService.listChildNodesAsTaxonNodeDto((UuidAndTitleCache<TaxonNode>)parentElement).toArray();
70
        }
71

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

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

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

    
106
}
(4-4/5)