Project

General

Profile

Download (3.29 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.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 accesor 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

    
34
    /**
35
     * {@inheritDoc}
36
     */
37
    @Override
38
    public Object getDataValue(Object rowObject, int columnIndex) {
39
        if(rowObject instanceof SpecimenRowWrapperDTO){
40
            SpecimenRowWrapperDTO rowWrapper = (SpecimenRowWrapperDTO) rowObject;
41
            switch (columnIndex) {
42
            case 0:
43
                if(matrix.isTreeView()){
44
                    return "#"+rowWrapper.getSpecimen().getId();
45
                }
46
                else{
47
                    return rowWrapper.getTaxonNode();
48
                }
49
            case 1:
50
                return rowWrapper.getFieldUnit();
51
            case 2:
52
                return rowWrapper.getIdentifier();
53
            case 3:
54
                return rowWrapper.getCountry();
55

    
56
            default:
57
                break;
58
            }
59
            Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
60
            return rowWrapper.getDataValueForFeature(feature);
61
        } else if(rowObject instanceof TaxonRowWrapperDTO){
62
            TaxonRowWrapperDTO taxonWrapper = (TaxonRowWrapperDTO)rowObject;
63
            if(columnIndex==0){
64
                return taxonWrapper.getTaxonNode();
65
            }
66
            Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
67
            return taxonWrapper.getDataValueForFeature(feature);
68

    
69
        }
70
        else if (columnIndex == 0) {
71
            return rowObject;
72
        }
73
        return null;
74
    }
75

    
76
    /**
77
     * {@inheritDoc}
78
     */
79
    @Override
80
    public void setDataValue(Object rowObject, int columnIndex, Object newValue) {
81
        if(rowObject instanceof RowWrapperDTO){
82
            RowWrapperDTO rowWrapper = (RowWrapperDTO)rowObject;
83
            Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
84
            rowWrapper.setDataValueForFeature(feature, newValue);
85
        }
86
    }
87

    
88
    /**
89
     * {@inheritDoc}
90
     */
91
    @Override
92
    public int getColumnCount() {
93
        return matrix.getPropertyToLabelMap().size();
94
    }
95

    
96
    /**
97
     * {@inheritDoc}
98
     */
99
    @Override
100
    public String getColumnProperty(int columnIndex) {
101
        return matrix.getPropertyToLabelMap().get(columnIndex);
102
    }
103

    
104
    /**
105
     * {@inheritDoc}
106
     */
107
    @Override
108
    public int getColumnIndex(String propertyName){
109
        return matrix.getPropertyToLabelMap().indexOf(propertyName);
110
    }
111

    
112
}
(19-19/20)