1 |
b22738ad
|
Patrick Plitzner
|
/**
|
2 |
|
|
* Copyright (C) 2017 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 |
|
|
package eu.etaxonomy.taxeditor.util;
|
10 |
|
|
|
11 |
d8baa72e
|
Patrick Plitzner
|
import java.util.Collection;
|
12 |
67c1a4e3
|
Katja Luther
|
import java.util.Collections;
|
13 |
|
|
import java.util.Comparator;
|
14 |
|
|
import java.util.List;
|
15 |
b22738ad
|
Patrick Plitzner
|
|
16 |
|
|
import org.eclipse.jface.viewers.ITreeContentProvider;
|
17 |
|
|
|
18 |
cedc4ff1
|
Katja Luther
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
19 |
b22738ad
|
Patrick Plitzner
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
20 |
cedc4ff1
|
Katja Luther
|
import eu.etaxonomy.cdm.persistence.dto.TaxonNodeDto;
|
21 |
67c1a4e3
|
Katja Luther
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
22 |
cedc4ff1
|
Katja Luther
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
23 |
b22738ad
|
Patrick Plitzner
|
|
24 |
|
|
/**
|
25 |
|
|
* @author pplitzner
|
26 |
|
|
* @date 05.09.2017
|
27 |
|
|
*/
|
28 |
|
|
public class TaxonTreeNodeContentProvider implements ITreeContentProvider {
|
29 |
|
|
|
30 |
|
|
private static final Object[] NO_CHILDREN = new Object[0];
|
31 |
|
|
|
32 |
cedc4ff1
|
Katja Luther
|
private ITaxonNodeService taxonNodeService;
|
33 |
|
|
|
34 |
b22738ad
|
Patrick Plitzner
|
@Override
|
35 |
|
|
public Object[] getElements(Object inputElement) {
|
36 |
d8baa72e
|
Patrick Plitzner
|
if(inputElement instanceof Collection){
|
37 |
159e7b25
|
Andreas Müller
|
return ((Collection<?>) inputElement).toArray();
|
38 |
d8baa72e
|
Patrick Plitzner
|
}
|
39 |
b22738ad
|
Patrick Plitzner
|
return this.getChildren(inputElement);
|
40 |
|
|
}
|
41 |
|
|
|
42 |
|
|
@Override
|
43 |
|
|
public Object[] getChildren(Object parentElement) {
|
44 |
cedc4ff1
|
Katja Luther
|
if (taxonNodeService == null){
|
45 |
|
|
taxonNodeService = CdmStore.getService(ITaxonNodeService.class);
|
46 |
|
|
}
|
47 |
b22738ad
|
Patrick Plitzner
|
Object[] children = null;
|
48 |
|
|
|
49 |
cedc4ff1
|
Katja Luther
|
// if(parentElement instanceof Classification){
|
50 |
|
|
// children = taxonNodeService.listChildNodesAsUuidAndTitleCache(((Classification)parentElement).getRootNode()).toArray();
|
51 |
|
|
//// children = ((Classification) parentElement).getChildNodes().toArray();
|
52 |
|
|
// }
|
53 |
|
|
// //taxon node
|
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();
|
59 |
|
|
// }
|
60 |
67c1a4e3
|
Katja Luther
|
List<TaxonNodeDto> childrenList = null;
|
61 |
159e7b25
|
Andreas Müller
|
|
62 |
cedc4ff1
|
Katja Luther
|
if(parentElement instanceof TaxonNode){
|
63 |
67c1a4e3
|
Katja Luther
|
childrenList = taxonNodeService.listChildNodesAsTaxonNodeDto((TaxonNode)parentElement);
|
64 |
cedc4ff1
|
Katja Luther
|
}else {
|
65 |
67c1a4e3
|
Katja Luther
|
childrenList = taxonNodeService.listChildNodesAsTaxonNodeDto((TaxonNodeDto)parentElement);
|
66 |
b22738ad
|
Patrick Plitzner
|
}
|
67 |
67c1a4e3
|
Katja Luther
|
Comparator<TaxonNodeDto> comparator = PreferencesUtil.getNodeComparator();
|
68 |
|
|
Collections.sort(childrenList, comparator);
|
69 |
|
|
children = childrenList.toArray();
|
70 |
b22738ad
|
Patrick Plitzner
|
return children != null ? children : NO_CHILDREN;
|
71 |
|
|
}
|
72 |
|
|
|
73 |
159e7b25
|
Andreas Müller
|
|
74 |
67c1a4e3
|
Katja Luther
|
|
75 |
b22738ad
|
Patrick Plitzner
|
@Override
|
76 |
|
|
public Object getParent(Object element) {
|
77 |
eb140397
|
Katja Luther
|
if (taxonNodeService == null){
|
78 |
|
|
taxonNodeService = CdmStore.getService(ITaxonNodeService.class);
|
79 |
|
|
}
|
80 |
cedc4ff1
|
Katja Luther
|
if(element instanceof TaxonNodeDto){
|
81 |
|
|
if (((TaxonNodeDto) element).getParentUUID() != null){
|
82 |
887f95c5
|
Katja Luther
|
TaxonNodeDto parentDto = taxonNodeService.dto(((TaxonNodeDto) element).getParentUUID());
|
83 |
|
|
// TaxonNode parent = taxonNodeService.load(((TaxonNodeDto) element).getParentUUID());
|
84 |
|
|
if (parentDto != null){
|
85 |
|
|
// return new TaxonNodeDto(parent);
|
86 |
|
|
return parentDto;
|
87 |
687bfc97
|
Katja Luther
|
}
|
88 |
cedc4ff1
|
Katja Luther
|
}
|
89 |
b22738ad
|
Patrick Plitzner
|
}
|
90 |
|
|
return null;
|
91 |
|
|
}
|
92 |
|
|
|
93 |
|
|
@Override
|
94 |
|
|
public boolean hasChildren(Object element) {
|
95 |
|
|
if(element instanceof TaxonNode){
|
96 |
|
|
return ((TaxonNode) element).getCountChildren() > 0;
|
97 |
|
|
}
|
98 |
cedc4ff1
|
Katja Luther
|
if (element instanceof TaxonNodeDto){
|
99 |
|
|
return ((TaxonNodeDto)element).getTaxonomicChildrenCount()>0;
|
100 |
|
|
}
|
101 |
b22738ad
|
Patrick Plitzner
|
return this.getChildren(element).length > 0;
|
102 |
|
|
}
|
103 |
|
|
}
|