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