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
|
|
18
|
/**
|
19
|
* Converts CategoricalData and States of one cell of the character matrix to a
|
20
|
* String.
|
21
|
*
|
22
|
* @author pplitzner
|
23
|
* @since Dec 1, 2017
|
24
|
*
|
25
|
*/
|
26
|
public class CategoricalDataDisplayConverter extends DisplayConverter {
|
27
|
|
28
|
/**
|
29
|
* {@inheritDoc}
|
30
|
*/
|
31
|
@Override
|
32
|
public Object canonicalToDisplayValue(Object canonicalValue) {
|
33
|
if(canonicalValue instanceof CategoricalData){
|
34
|
CategoricalData categoricalData = (CategoricalData)canonicalValue;
|
35
|
String result = categoricalData.getStatesOnly().toString();
|
36
|
result = result.substring(1, result.length() - 1);
|
37
|
return result;
|
38
|
}
|
39
|
else if(canonicalValue instanceof State){
|
40
|
return ((State) canonicalValue).getLabel();
|
41
|
}
|
42
|
else if (canonicalValue instanceof Collection) {
|
43
|
// Collection.toString() will add [ and ] around
|
44
|
// the values in the Collection
|
45
|
// So by removing the leading and ending
|
46
|
// character, we remove the brackets
|
47
|
String result = canonicalValue.toString();
|
48
|
result = result.substring(1, result.length() - 1);
|
49
|
return result;
|
50
|
}
|
51
|
else if(canonicalValue!=null){
|
52
|
return canonicalValue.toString();
|
53
|
}
|
54
|
return null;
|
55
|
}
|
56
|
|
57
|
/**
|
58
|
* {@inheritDoc}
|
59
|
*/
|
60
|
@Override
|
61
|
public Object displayToCanonicalValue(Object displayValue) {
|
62
|
return null;
|
63
|
}
|
64
|
|
65
|
}
|