3 * Copyright (C) 2018 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
.editor
.descriptiveDataSet
.matrix
;
12 import java
.util
.Comparator
;
13 import java
.util
.List
;
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
;
24 * The tree format defines how to build the hierarchy path for the
25 * taxon column in the character matrix
31 public class DescriptionTreeFormat
implements TreeList
.Format
<Object
> {
35 public DescriptionTreeFormat(DescriptiveDataSet descriptiveDataSet
) {
36 this.maxRank
= descriptiveDataSet
.getMaxRank();
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
);
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
);
55 private void addPathRecursive(List path
, TaxonNode node
){
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
)){
66 addPathRecursive(path
, node
.getParent());
72 public boolean allowsChildren(Object element
) {
77 public Comparator
<Object
> getComparator(int depth
) {
78 return new MatrixRowComparator();