Project

General

Profile

Download (2.14 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.name.Rank;
18
import eu.etaxonomy.cdm.model.taxon.Taxon;
19
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
20

    
21
/**
22
 * @author pplitzner
23
 * @date 23.01.2018
24
 *
25
 */
26
 public class DescriptionTreeFormat implements TreeList.Format<Object> {
27

    
28
     private Rank maxRank;
29

    
30
     public DescriptionTreeFormat(Rank maxRank) {
31
         this.maxRank = maxRank;
32
     }
33

    
34
     @Override
35
     public void getPath(List path, Object element) {
36
         if(element instanceof RowWrapper){
37
             //TODO: check for multiple taxon nodes in multiple classifications
38
             Taxon taxon = ((RowWrapper) element).getAssociatedTaxon();
39
             Set<TaxonNode> taxonNodes = taxon.getTaxonNodes();
40
             if(taxonNodes!=null){
41
                 TaxonNode node = taxonNodes.iterator().next();
42
                 addPathRecursive(path, node);
43
             }
44
         }
45
         path.add(element);
46
     }
47

    
48
     private void addPathRecursive(List path, TaxonNode node){
49
         if(node.getParent()!=null
50
                 && node.getTaxon()!=null
51
                 && node.getTaxon().getName()!=null
52
                 && node.getTaxon().getName().getRank()!=null){
53
             Rank rank = node.getTaxon().getName().getRank();
54
             if(maxRank.equals(rank)){
55
                 path.add(node);
56
                 return;
57
             }
58
             addPathRecursive(path, node.getParent());
59
             path.add(node);
60
         }
61
     }
62

    
63
     @Override
64
     public boolean allowsChildren(Object element) {
65
         if(element instanceof TaxonNode){
66
             return true;
67
         }
68
         return false;
69
     }
70

    
71
     @Override
72
     public Comparator<Object> getComparator(int depth) {
73
         return new MatrixRowComparator();
74
     }
75

    
76
 }
(5-5/11)