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
;
13 import java
.util
.List
;
15 import org
.eclipse
.jface
.viewers
.ITreeContentProvider
;
17 import eu
.etaxonomy
.cdm
.hibernate
.HHH_9751_Util
;
18 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
19 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
20 import eu
.etaxonomy
.cdm
.model
.taxon
.ITaxonTreeNode
;
21 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
28 public class TaxonTreeNodeContentProvider
implements ITreeContentProvider
{
30 private static final Object
[] NO_CHILDREN
= new Object
[0];
36 public Object
[] getElements(Object inputElement
) {
37 if(inputElement
instanceof Collection
){
38 return ((Collection
) inputElement
).toArray();
40 return this.getChildren(inputElement
);
47 public Object
[] getChildren(Object parentElement
) {
48 Object
[] children
= null;
50 if(parentElement
instanceof Classification
){
51 children
= ((Classification
) parentElement
).getChildNodes().toArray();
54 if(parentElement
instanceof ITaxonTreeNode
){
55 ITaxonTreeNode treeNode
= (ITaxonTreeNode
) HibernateProxyHelper
.deproxy(parentElement
);
56 List
<TaxonNode
> childrenSet
= treeNode
.getChildNodes();
57 HHH_9751_Util
.removeAllNull(childrenSet
);
58 children
= childrenSet
.toArray();
60 return children
!= null ? children
: NO_CHILDREN
;
67 public Object
getParent(Object element
) {
68 if(element
instanceof TaxonNode
){
69 return ((TaxonNode
) element
).getParent();
78 public boolean hasChildren(Object element
) {
79 if(element
instanceof TaxonNode
){
80 return ((TaxonNode
) element
).getCountChildren() > 0;
82 return this.getChildren(element
).length
> 0;