1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2018 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
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.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
|
11
|
|
12
|
import java.util.Comparator;
|
13
|
import java.util.List;
|
14
|
|
15
|
import ca.odell.glazedlists.TreeList;
|
16
|
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
|
17
|
import eu.etaxonomy.cdm.api.service.dto.SpecimenRowWrapperDTO;
|
18
|
import eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO;
|
19
|
import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
|
20
|
import eu.etaxonomy.cdm.model.name.Rank;
|
21
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
22
|
|
23
|
/**
|
24
|
* The tree format defines how to build the hierarchy path for the
|
25
|
* taxon column in the character matrix
|
26
|
*
|
27
|
* @author pplitzner
|
28
|
* @date 23.01.2018
|
29
|
*
|
30
|
*/
|
31
|
public class DescriptionTreeFormat implements TreeList.Format<Object> {
|
32
|
|
33
|
private Rank maxRank;
|
34
|
|
35
|
public DescriptionTreeFormat(DescriptiveDataSet descriptiveDataSet) {
|
36
|
this.maxRank = descriptiveDataSet.getMaxRank();
|
37
|
}
|
38
|
|
39
|
@Override
|
40
|
public void getPath(List path, Object element) {
|
41
|
if(element instanceof SpecimenRowWrapperDTO
|
42
|
&& ((SpecimenRowWrapperDTO) element).getDefaultTaxonDescription()!=null){
|
43
|
TaxonRowWrapperDTO defaultTaxonDescription = ((SpecimenRowWrapperDTO) element).getDefaultTaxonDescription();
|
44
|
addPathRecursive(path, defaultTaxonDescription.getTaxonNode());
|
45
|
path.add(defaultTaxonDescription);
|
46
|
}
|
47
|
else if(element instanceof RowWrapperDTO){
|
48
|
//TODO: check for multiple taxon nodes in multiple classifications
|
49
|
TaxonNode taxonNode = ((RowWrapperDTO) element).getTaxonNode();
|
50
|
addPathRecursive(path, taxonNode);
|
51
|
}
|
52
|
path.add(element);
|
53
|
}
|
54
|
|
55
|
private void addPathRecursive(List path, TaxonNode node){
|
56
|
if(node!=null
|
57
|
&& node.getParent()!=null
|
58
|
&& node.getTaxon()!=null
|
59
|
&& node.getTaxon().getName()!=null
|
60
|
&& node.getTaxon().getName().getRank()!=null){
|
61
|
Rank rank = node.getTaxon().getName().getRank();
|
62
|
if(maxRank==null || maxRank.equals(rank)){
|
63
|
path.add(node);
|
64
|
return;
|
65
|
}
|
66
|
addPathRecursive(path, node.getParent());
|
67
|
path.add(node);
|
68
|
}
|
69
|
}
|
70
|
|
71
|
@Override
|
72
|
public boolean allowsChildren(Object element) {
|
73
|
return true;
|
74
|
}
|
75
|
|
76
|
@Override
|
77
|
public Comparator<Object> getComparator(int depth) {
|
78
|
return new MatrixRowComparator();
|
79
|
}
|
80
|
|
81
|
}
|