2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.workingSet
.matrix
;
11 import java
.util
.ArrayList
;
12 import java
.util
.List
;
16 import org
.apache
.commons
.collections4
.map
.LinkedMap
;
17 import org
.eclipse
.nebula
.widgets
.nattable
.data
.IColumnPropertyAccessor
;
19 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
20 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
21 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
22 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
23 import eu
.etaxonomy
.cdm
.model
.description
.WorkingSet
;
30 public class SpecimenColumnPropertyAccessor
implements IColumnPropertyAccessor
<SpecimenDescription
>{
32 private List
<Feature
> features
= new ArrayList
<>();
33 private LinkedMap
<String
, String
> propertyToLabelMap
= new LinkedMap
<>();
36 public SpecimenColumnPropertyAccessor(WorkingSet workingSet
) {
37 FeatureTree tree
= workingSet
.getDescriptiveSystem();
38 Set
<Feature
> distinctFeatures
= tree
.getDistinctFeatures();
39 for (Feature feature
: distinctFeatures
) {
41 features
.add(feature
);
42 propertyToLabelMap
.put(feature
.getLabel(), feature
.getLabel());
47 public Map
<String
, String
> getPropertyToLabelMap() {
48 return propertyToLabelMap
;
55 public DescriptionElementBase
getDataValue(SpecimenDescription rowObject
, int columnIndex
) {
56 Feature feature
= features
.get(columnIndex
);
57 Set
<DescriptionElementBase
> elements
= rowObject
.getElements();
58 for (DescriptionElementBase descriptionElementBase
: elements
) {
59 if(descriptionElementBase
.getFeature().equals(feature
)){
60 return descriptionElementBase
;
70 public void setDataValue(SpecimenDescription rowObject
, int columnIndex
, Object newValue
) {
71 features
.remove(columnIndex
);
72 features
.add(columnIndex
, (Feature
) newValue
);
79 public int getColumnCount() {
80 return features
.size();
87 public String
getColumnProperty(int columnIndex
) {
88 return features
.get(columnIndex
).getLabel();
95 public int getColumnIndex(String propertyName
){
96 return propertyToLabelMap
.indexOf(propertyName
);