2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
9 package eu
.etaxonomy
.taxeditor
.util
;
11 import java
.util
.Collection
;
13 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
15 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
16 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
17 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
18 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
24 public class TaxonTreeNodeContentProvider
implements ITreeContentProvider
{
26 private static final Object
[] NO_CHILDREN
= new Object
[0];
28 private ITaxonNodeService taxonNodeService
;
31 public Object
[] getElements(Object inputElement
) {
32 if(inputElement
instanceof Collection
){
33 return ((Collection
) inputElement
).toArray();
35 return this.getChildren(inputElement
);
39 public Object
[] getChildren(Object parentElement
) {
40 if (taxonNodeService
== null){
41 taxonNodeService
= CdmStore
.getService(ITaxonNodeService
.class);
43 Object
[] children
= null;
45 // if(parentElement instanceof Classification){
46 // children = taxonNodeService.listChildNodesAsUuidAndTitleCache(((Classification)parentElement).getRootNode()).toArray();
47 //// children = ((Classification) parentElement).getChildNodes().toArray();
50 // if(parentElement instanceof ITaxonTreeNode){
51 // ITaxonTreeNode treeNode = (ITaxonTreeNode) HibernateProxyHelper.deproxy(parentElement);
52 // List<TaxonNode> childrenSet = treeNode.getChildNodes();
53 // HHH_9751_Util.removeAllNull(childrenSet);
54 // children = childrenSet.toArray();
57 if(parentElement
instanceof TaxonNode
){
58 children
= taxonNodeService
.listChildNodesAsTaxonNodeDto((TaxonNode
)parentElement
).toArray();
60 children
= taxonNodeService
.listChildNodesAsTaxonNodeDto((TaxonNodeDto
)parentElement
).toArray();
63 return children
!= null ? children
: NO_CHILDREN
;
67 public Object
getParent(Object element
) {
68 if (taxonNodeService
== null){
69 taxonNodeService
= CdmStore
.getService(ITaxonNodeService
.class);
71 if(element
instanceof TaxonNodeDto
){
72 if (((TaxonNodeDto
) element
).getParentUUID() != null){
73 TaxonNode parent
= taxonNodeService
.load(((TaxonNodeDto
) element
).getParentUUID());
74 return new TaxonNodeDto(parent
);
81 public boolean hasChildren(Object element
) {
82 if(element
instanceof TaxonNode
){
83 return ((TaxonNode
) element
).getCountChildren() > 0;
85 if (element
instanceof TaxonNodeDto
){
86 return ((TaxonNodeDto
)element
).getTaxonomicChildrenCount()>0;
88 return this.getChildren(element
).length
> 0;