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.descriptiveDataSet.matrix.categorical;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
|
13
|
import org.eclipse.nebula.widgets.nattable.data.convert.DisplayConverter;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.description.CategoricalData;
|
16
|
import eu.etaxonomy.cdm.model.description.State;
|
17
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
18
|
import eu.etaxonomy.cdm.remote.l10n.TermRepresentation_L10n;
|
19
|
import eu.etaxonomy.taxeditor.model.DescriptionHelper;
|
20
|
|
21
|
/**
|
22
|
* Converts CategoricalData and States of one cell of the character matrix to a
|
23
|
* String.
|
24
|
*
|
25
|
* @author pplitzner
|
26
|
* @since Dec 1, 2017
|
27
|
*
|
28
|
*/
|
29
|
public class CategoricalDataDisplayConverter extends DisplayConverter {
|
30
|
|
31
|
/**
|
32
|
* {@inheritDoc}
|
33
|
*/
|
34
|
@Override
|
35
|
public Object canonicalToDisplayValue(Object canonicalValue) {
|
36
|
if(canonicalValue instanceof CategoricalData){
|
37
|
String text = DescriptionHelper.getLabel(canonicalValue);
|
38
|
return text.equals(DescriptionHelper.NO_LABEL_STRING)?"":text;
|
39
|
}
|
40
|
else if(canonicalValue instanceof State){
|
41
|
return ((State) canonicalValue).getLabel();
|
42
|
}
|
43
|
else if(canonicalValue instanceof TermDto){
|
44
|
((TermDto) canonicalValue).localize(new TermRepresentation_L10n());
|
45
|
return ((TermDto) canonicalValue).getRepresentation_L10n();
|
46
|
}
|
47
|
else if (canonicalValue instanceof Collection) {
|
48
|
// Collection.toString() will add [ and ] around
|
49
|
// the values in the Collection
|
50
|
// So by removing the leading and ending
|
51
|
// character, we remove the brackets
|
52
|
String result = canonicalValue.toString();
|
53
|
result = result.substring(1, result.length() - 1);
|
54
|
return result;
|
55
|
}
|
56
|
else if(canonicalValue!=null){
|
57
|
return canonicalValue.toString();
|
58
|
}
|
59
|
return null;
|
60
|
}
|
61
|
|
62
|
/**
|
63
|
* {@inheritDoc}
|
64
|
*/
|
65
|
@Override
|
66
|
public Object displayToCanonicalValue(Object displayValue) {
|
67
|
return null;
|
68
|
}
|
69
|
|
70
|
}
|