1
|
/**
|
2
|
* Copyright (C) 2007 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
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.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.taxeditor.navigation.navigator;
|
11
|
|
12
|
import java.util.List;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.eclipse.jface.viewers.ITreeContentProvider;
|
16
|
import org.eclipse.jface.viewers.Viewer;
|
17
|
|
18
|
import eu.etaxonomy.cdm.hibernate.HHH_9751_Util;
|
19
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
20
|
import eu.etaxonomy.cdm.model.taxon.ITaxonTreeNode;
|
21
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
22
|
|
23
|
/**
|
24
|
* <p>TaxonNodeContentProvider class.</p>
|
25
|
*
|
26
|
* @author p.ciardelli
|
27
|
* @created 02.06.2009
|
28
|
* @version 1.0
|
29
|
*/
|
30
|
public class TaxonNodeContentProvider implements ITreeContentProvider {
|
31
|
private static final Logger logger = Logger
|
32
|
.getLogger(TaxonNodeContentProvider.class);
|
33
|
|
34
|
private static final Object[] NO_CHILDREN = new Object[0];
|
35
|
|
36
|
/** {@inheritDoc} */
|
37
|
@Override
|
38
|
public Object[] getChildren(Object parentElement) {
|
39
|
Object[] children = null;
|
40
|
|
41
|
if(parentElement instanceof ITaxonTreeNode){
|
42
|
ITaxonTreeNode treeNode = (ITaxonTreeNode) HibernateProxyHelper.deproxy(parentElement);
|
43
|
List<TaxonNode> childrenSet = treeNode.getChildNodes();
|
44
|
HHH_9751_Util.removeAllNull(childrenSet);
|
45
|
children = childrenSet.toArray();
|
46
|
|
47
|
}
|
48
|
|
49
|
return children != null ? children : NO_CHILDREN;
|
50
|
}
|
51
|
|
52
|
/** {@inheritDoc} */
|
53
|
@Override
|
54
|
public Object getParent(Object element) {
|
55
|
if(element instanceof TaxonNode){
|
56
|
return ((TaxonNode) element).getParent();
|
57
|
}
|
58
|
return null;
|
59
|
}
|
60
|
|
61
|
/** {@inheritDoc} */
|
62
|
@Override
|
63
|
public boolean hasChildren(Object element) {
|
64
|
if(element instanceof TaxonNode){
|
65
|
return ((TaxonNode) element).getCountChildren() > 0;
|
66
|
}
|
67
|
return getChildren(element).length > 0;
|
68
|
}
|
69
|
|
70
|
/** {@inheritDoc} */
|
71
|
@Override
|
72
|
public Object[] getElements(Object inputElement) {
|
73
|
return this.getChildren(inputElement);
|
74
|
}
|
75
|
|
76
|
/**
|
77
|
* <p>dispose</p>
|
78
|
*/
|
79
|
@Override
|
80
|
public void dispose() {
|
81
|
}
|
82
|
|
83
|
/** {@inheritDoc} */
|
84
|
@Override
|
85
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
|
86
|
}
|
87
|
}
|