Project

General

Profile

Download (2.58 KB) Statistics
| Branch: | Tag: | Revision:
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.workingSet.matrix;
11

    
12
import java.util.Comparator;
13
import java.util.List;
14
import java.util.Set;
15

    
16
import ca.odell.glazedlists.TreeList;
17
import eu.etaxonomy.cdm.model.description.WorkingSet;
18
import eu.etaxonomy.cdm.model.name.Rank;
19
import eu.etaxonomy.cdm.model.taxon.Classification;
20
import eu.etaxonomy.cdm.model.taxon.Taxon;
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
     private Classification classification;
35

    
36
     public DescriptionTreeFormat(WorkingSet workingSet) {
37
         this.maxRank = workingSet.getMaxRank();
38
         Set<TaxonNode> taxonSubtreeFilter = workingSet.getTaxonSubtreeFilter();
39
         if(taxonSubtreeFilter!=null && !taxonSubtreeFilter.isEmpty()){
40
             this.classification = taxonSubtreeFilter.iterator().next().getClassification();
41
         }
42
     }
43

    
44
     @Override
45
     public void getPath(List path, Object element) {
46
         if(element instanceof RowWrapper){
47
             //TODO: check for multiple taxon nodes in multiple classifications
48
             Taxon taxon = ((RowWrapper) element).getAssociatedTaxon();
49
             TaxonNode taxonNode = taxon.getTaxonNode(classification);
50
             addPathRecursive(path, taxonNode);
51
         }
52
         path.add(element);
53
     }
54

    
55
     private void addPathRecursive(List path, TaxonNode node){
56
         if(node.getParent()!=null
57
                 && node.getTaxon()!=null
58
                 && node.getTaxon().getName()!=null
59
                 && node.getTaxon().getName().getRank()!=null){
60
             Rank rank = node.getTaxon().getName().getRank();
61
             if(maxRank==null || maxRank.equals(rank)){
62
                 path.add(node);
63
                 return;
64
             }
65
             addPathRecursive(path, node.getParent());
66
             path.add(node);
67
         }
68
     }
69

    
70
     @Override
71
     public boolean allowsChildren(Object element) {
72
         if(element instanceof TaxonNode){
73
             return true;
74
         }
75
         return false;
76
     }
77

    
78
     @Override
79
     public Comparator<Object> getComparator(int depth) {
80
         return new MatrixRowComparator();
81
     }
82

    
83
 }
(5-5/11)