3 * Copyright (C) 2017 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.util
;
12 import java
.util
.Collection
;
14 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
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
;
27 public class TaxonTreeNodeContentProvider
implements ITreeContentProvider
{
29 private static final Object
[] NO_CHILDREN
= new Object
[0];
31 private ITaxonNodeService taxonNodeService
;
37 public Object
[] getElements(Object inputElement
) {
38 if(inputElement
instanceof Collection
){
39 return ((Collection
) inputElement
).toArray();
41 return this.getChildren(inputElement
);
48 public Object
[] getChildren(Object parentElement
) {
49 if (taxonNodeService
== null){
50 taxonNodeService
= CdmStore
.getService(ITaxonNodeService
.class);
52 Object
[] children
= null;
54 // if(parentElement instanceof Classification){
55 // children = taxonNodeService.listChildNodesAsUuidAndTitleCache(((Classification)parentElement).getRootNode()).toArray();
56 //// children = ((Classification) parentElement).getChildNodes().toArray();
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();
66 if(parentElement
instanceof TaxonNode
){
67 children
= taxonNodeService
.listChildNodesAsTaxonNodeDto((TaxonNode
)parentElement
).toArray();
69 children
= taxonNodeService
.listChildNodesAsTaxonNodeDto((UuidAndTitleCache
<TaxonNode
>)parentElement
).toArray();
72 return children
!= null ? children
: NO_CHILDREN
;
79 public Object
getParent(Object element
) {
80 if (taxonNodeService
== null){
81 taxonNodeService
= CdmStore
.getService(ITaxonNodeService
.class);
83 if(element
instanceof TaxonNodeDto
){
84 if (((TaxonNodeDto
) element
).getParentUUID() != null){
85 TaxonNode parent
= taxonNodeService
.load(((TaxonNodeDto
) element
).getParentUUID());
86 return new TaxonNodeDto(parent
);
96 public boolean hasChildren(Object element
) {
97 if(element
instanceof TaxonNode
){
98 return ((TaxonNode
) element
).getCountChildren() > 0;
100 if (element
instanceof TaxonNodeDto
){
101 return ((TaxonNodeDto
)element
).getTaxonomicChildrenCount()>0;
103 return this.getChildren(element
).length
> 0;