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
.HashMap
;
14 import java
.util
.List
;
16 import java
.util
.UUID
;
18 import ca
.odell
.glazedlists
.TreeList
;
19 import eu
.etaxonomy
.cdm
.api
.service
.ITaxonNodeService
;
20 import eu
.etaxonomy
.cdm
.api
.service
.dto
.RowWrapperDTO
;
21 import eu
.etaxonomy
.cdm
.model
.description
.DescriptiveDataSet
;
22 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
24 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
25 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
28 * The tree format defines how to build the hierarchy path for the
29 * taxon column in the character matrix
35 public class DescriptionTreeFormat
implements TreeList
.Format
<Object
> {
39 private Map
<UUID
, TaxonNodeDto
> uuidToTaxonNodeDtoMap
= new HashMap
<>();
41 public DescriptionTreeFormat(DescriptiveDataSet descriptiveDataSet
) {
42 this.maxRank
= descriptiveDataSet
.getMaxRank();
46 public void getPath(List path
, Object element
) {
47 if(element
instanceof RowWrapperDTO
){
48 //TODO: check for multiple taxon nodes in multiple classifications
49 TaxonNodeDto taxonNode
= ((RowWrapperDTO
) element
).getTaxonNode();
50 //use dto from map cache because the elements have to be
51 //exactly the same for the tree format to work
52 if(uuidToTaxonNodeDtoMap
.get(taxonNode
.getUuid())!=null){
53 taxonNode
= uuidToTaxonNodeDtoMap
.get(taxonNode
.getUuid());
56 uuidToTaxonNodeDtoMap
.put(taxonNode
.getUuid(), taxonNode
);
58 addPathRecursive(path
, taxonNode
);
63 private void addPathRecursive(List path
, TaxonNodeDto node
){
65 if(maxRank
!=null && node
.getRankOrderIndex()==maxRank
.getOrderIndex()){
69 TaxonNodeDto parentNodeDto
= uuidToTaxonNodeDtoMap
.get(node
.getParentUUID());
70 if(parentNodeDto
==null){
71 TaxonNode parent
= CdmStore
.getService(ITaxonNodeService
.class).load(node
.getParentUUID());
73 parentNodeDto
= new TaxonNodeDto(parent
);
74 uuidToTaxonNodeDtoMap
.put(node
.getParentUUID(), parentNodeDto
);
77 if(parentNodeDto
!=null){
78 addPathRecursive(path
, parentNodeDto
);
85 public boolean allowsChildren(Object element
) {
90 public Comparator
<Object
> getComparator(int depth
) {
91 return new MatrixRowComparator();