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;
|
10
|
|
11
|
import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;
|
12
|
|
13
|
import eu.etaxonomy.cdm.api.service.dto.RowWrapperDTO;
|
14
|
import eu.etaxonomy.cdm.model.description.Feature;
|
15
|
|
16
|
/**
|
17
|
* Property accesor class which maps setting and getting data for
|
18
|
* each row in the character matrix
|
19
|
* @author pplitzner
|
20
|
* @since Nov 26, 2017
|
21
|
*
|
22
|
*/
|
23
|
public class SpecimenColumnPropertyAccessor implements IColumnPropertyAccessor<Object>{
|
24
|
|
25
|
private CharacterMatrix matrix;
|
26
|
|
27
|
public SpecimenColumnPropertyAccessor(CharacterMatrix matrix) {
|
28
|
this.matrix = matrix;
|
29
|
}
|
30
|
|
31
|
|
32
|
/**
|
33
|
* {@inheritDoc}
|
34
|
*/
|
35
|
@Override
|
36
|
public Object getDataValue(Object rowObject, int columnIndex) {
|
37
|
if(rowObject instanceof RowWrapperDTO){
|
38
|
RowWrapperDTO rowWrapper = (RowWrapperDTO)rowObject;
|
39
|
switch (columnIndex) {
|
40
|
case 0:
|
41
|
if(matrix.isTreeView()){
|
42
|
return "#"+rowWrapper.getSpecimen().getId();
|
43
|
}
|
44
|
else{
|
45
|
return rowWrapper.getTaxonNode();
|
46
|
}
|
47
|
case 1:
|
48
|
return rowWrapper.getFieldUnit();
|
49
|
case 2:
|
50
|
return rowWrapper.getIdentifier();
|
51
|
case 3:
|
52
|
return rowWrapper.getCountry();
|
53
|
|
54
|
default:
|
55
|
break;
|
56
|
}
|
57
|
Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
|
58
|
return rowWrapper.getDataValueForFeature(feature);
|
59
|
} else if (columnIndex == 0) {
|
60
|
return rowObject;
|
61
|
}
|
62
|
return null;
|
63
|
}
|
64
|
|
65
|
/**
|
66
|
* {@inheritDoc}
|
67
|
*/
|
68
|
@Override
|
69
|
public void setDataValue(Object rowObject, int columnIndex, Object newValue) {
|
70
|
if(rowObject instanceof RowWrapperDTO){
|
71
|
RowWrapperDTO rowWrapper = (RowWrapperDTO)rowObject;
|
72
|
Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
|
73
|
rowWrapper.setDataValueForFeature(feature, newValue);
|
74
|
}
|
75
|
}
|
76
|
|
77
|
/**
|
78
|
* {@inheritDoc}
|
79
|
*/
|
80
|
@Override
|
81
|
public int getColumnCount() {
|
82
|
return matrix.getPropertyToLabelMap().size();
|
83
|
}
|
84
|
|
85
|
/**
|
86
|
* {@inheritDoc}
|
87
|
*/
|
88
|
@Override
|
89
|
public String getColumnProperty(int columnIndex) {
|
90
|
return matrix.getPropertyToLabelMap().get(columnIndex);
|
91
|
}
|
92
|
|
93
|
/**
|
94
|
* {@inheritDoc}
|
95
|
*/
|
96
|
@Override
|
97
|
public int getColumnIndex(String propertyName){
|
98
|
return matrix.getPropertyToLabelMap().indexOf(propertyName);
|
99
|
}
|
100
|
|
101
|
}
|