Project

General

Profile

Download (2.52 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.workingSet.matrix;
10

    
11
import org.eclipse.nebula.widgets.nattable.data.IColumnPropertyAccessor;
12

    
13
import eu.etaxonomy.cdm.model.description.Feature;
14

    
15
/**
16
 * Property accesor class which maps setting and getting data for
17
 * each row in the character matrix
18
 * @author pplitzner
19
 * @since Nov 26, 2017
20
 *
21
 */
22
public class SpecimenColumnPropertyAccessor implements IColumnPropertyAccessor<Object>{
23

    
24
    private CharacterMatrix matrix;
25

    
26
    public SpecimenColumnPropertyAccessor(CharacterMatrix matrix) {
27
        this.matrix = matrix;
28
    }
29

    
30

    
31
    /**
32
     * {@inheritDoc}
33
     */
34
    @Override
35
    public Object getDataValue(Object rowObject, int columnIndex) {
36
        if(rowObject instanceof RowWrapper){
37
            RowWrapper rowWrapper = (RowWrapper)rowObject;
38
            switch (columnIndex) {
39
            case 0:
40
                return rowWrapper.getTaxonNode();
41
            case 1:
42
                return rowWrapper.getFieldUnit();
43
            case 2:
44
                return rowWrapper.getIdentifier();
45
            case 3:
46
                return rowWrapper.getCountry();
47

    
48
            default:
49
                break;
50
            }
51
            Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
52
            return rowWrapper.getDataValueForFeature(feature);
53
        } else if (columnIndex == 0) {
54
            return rowObject;
55
        }
56
        return null;
57
    }
58

    
59
    /**
60
     * {@inheritDoc}
61
     */
62
    @Override
63
    public void setDataValue(Object rowObject, int columnIndex, Object newValue) {
64
        if(rowObject instanceof RowWrapper){
65
            RowWrapper rowWrapper = (RowWrapper)rowObject;
66
            Feature feature = matrix.getIndexToFeatureMap().get(columnIndex);
67
            rowWrapper.setDataValueForFeature(feature, newValue);
68
        }
69
    }
70

    
71
    /**
72
     * {@inheritDoc}
73
     */
74
    @Override
75
    public int getColumnCount() {
76
        return matrix.getPropertyToLabelMap().size();
77
    }
78

    
79
    /**
80
     * {@inheritDoc}
81
     */
82
    @Override
83
    public String getColumnProperty(int columnIndex) {
84
        return matrix.getPropertyToLabelMap().get(columnIndex);
85
    }
86

    
87
    /**
88
     * {@inheritDoc}
89
     */
90
    @Override
91
    public int getColumnIndex(String propertyName){
92
        return matrix.getPropertyToLabelMap().indexOf(propertyName);
93
    }
94

    
95
}
(9-9/12)