Project

General

Profile

Download (2.65 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9
package eu.etaxonomy.taxeditor.editor.workingSet.matrix.supplementalInfo;
10

    
11
import java.util.Collection;
12

    
13
import org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter;
14

    
15
import eu.etaxonomy.cdm.model.agent.AgentBase;
16
import eu.etaxonomy.cdm.model.location.NamedArea;
17
import eu.etaxonomy.cdm.model.occurrence.FieldUnit;
18
import eu.etaxonomy.cdm.model.occurrence.GatheringEvent;
19
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
20
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
21

    
22
/**
23
 * @author pplitzner
24
 * @since Dec 14, 2017
25
 *
26
 */
27
public class SupplementalInfoDisplayConverter extends DisplayConverter{
28

    
29
    /**
30
     * {@inheritDoc}
31
     */
32
    @Override
33
    public Object canonicalToDisplayValue(Object canonicalValue) {
34
        String displayValue = "";
35
        if(canonicalValue instanceof TaxonNode){
36
            TaxonNode node = (TaxonNode)canonicalValue;
37
            displayValue = node.getTaxon().getName().getNameCache();
38
        }
39
        else if(canonicalValue instanceof FieldUnit){
40
            FieldUnit fieldUnit = (FieldUnit)canonicalValue;
41
            GatheringEvent gatheringEvent = fieldUnit.getGatheringEvent();
42
            if(gatheringEvent!=null){
43
                AgentBase collector = gatheringEvent.getCollector();
44
                if(collector!=null){
45
                    displayValue += collector.getTitleCache()+" ";
46
                }
47
                String fieldNumber = fieldUnit.getFieldNumber();
48
                if(fieldNumber!=null){
49
                    displayValue += fieldNumber;
50
                }
51
            }
52
        }
53
        else if(canonicalValue instanceof NamedArea){
54
            displayValue = ((NamedArea) canonicalValue).getLabel();
55
        }
56
        else if(canonicalValue instanceof Collection){
57
            String separator = ", ";
58
            for(Object object:((Collection<?>) canonicalValue)){
59
                if(object instanceof TaxonBase && ((TaxonBase) object).getName()!=null){
60
                    displayValue += ((TaxonBase) object).getName()+separator;
61
                }
62
            }
63
            displayValue = displayValue.substring(0, displayValue.length()-separator.length());
64
        }
65

    
66
        if(displayValue.isEmpty() && canonicalValue!=null){
67
            return canonicalValue.toString();
68
        }
69
        return displayValue;
70
    }
71

    
72
    /**
73
     * {@inheritDoc}
74
     */
75
    @Override
76
    public Object displayToCanonicalValue(Object displayValue) {
77
        return null;
78
    }
79

    
80
}
    (1-1/1)