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
.descriptiveDataSet
.matrix
;
11 import java
.util
.ArrayList
;
12 import java
.util
.Collection
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
15 import java
.util
.stream
.Collectors
;
17 import org
.eclipse
.nebula
.widgets
.nattable
.data
.IColumnPropertyAccessor
;
19 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
20 import eu
.etaxonomy
.cdm
.api
.service
.dto
.RowWrapperDTO
;
21 import eu
.etaxonomy
.cdm
.api
.service
.dto
.SpecimenRowWrapperDTO
;
22 import eu
.etaxonomy
.cdm
.api
.service
.dto
.TaxonRowWrapperDTO
;
23 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
24 import eu
.etaxonomy
.cdm
.model
.description
.State
;
25 import eu
.etaxonomy
.cdm
.model
.term
.DefinedTermBase
;
26 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermDto
;
27 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
30 * Property accessor class which maps setting and getting data for
31 * each row in the character matrix
36 public class SpecimenColumnPropertyAccessor
implements IColumnPropertyAccessor
<Object
>{
38 private CharacterMatrix matrix
;
40 public SpecimenColumnPropertyAccessor(CharacterMatrix matrix
) {
45 public Object
getDataValue(Object rowObject
, int columnIndex
) {
46 if(rowObject
instanceof SpecimenRowWrapperDTO
){
47 SpecimenRowWrapperDTO rowWrapper
= (SpecimenRowWrapperDTO
) rowObject
;
48 switch (columnIndex
) {
50 if(matrix
.isTreeView()){
51 return "#"+rowWrapper
.getSpecimen().getId();
54 return rowWrapper
.getTaxonNode();
57 return rowWrapper
.getFieldUnit();
59 return rowWrapper
.getIdentifier();
61 return rowWrapper
.getCountry();
66 Feature feature
= matrix
.getIndexToFeatureMap().get(columnIndex
);
67 return rowWrapper
.getDisplayDataForFeature(feature
);
69 else if(rowObject
instanceof TaxonRowWrapperDTO
){
70 TaxonRowWrapperDTO taxonWrapper
= (TaxonRowWrapperDTO
)rowObject
;
72 return taxonWrapper
.getDescription();
74 Feature feature
= matrix
.getIndexToFeatureMap().get(columnIndex
);
75 return taxonWrapper
.getDisplayDataForFeature(feature
);
78 else if (columnIndex
== 0) {
85 public void setDataValue(Object rowObject
, int columnIndex
, Object newValue
) {
86 if(rowObject
instanceof RowWrapperDTO
){
87 RowWrapperDTO rowWrapper
= (RowWrapperDTO
)rowObject
;
88 Feature feature
= matrix
.getIndexToFeatureMap().get(columnIndex
);
89 if(newValue
instanceof Collection
&& ((Collection
) newValue
).stream().allMatch(o
->o
instanceof TermDto
)){
90 List
<TermDto
> dtos
= (List
<TermDto
>)newValue
;
91 List
<UUID
> termUuids
= dtos
.stream().map(dto
->dto
.getUuid()).collect(Collectors
.toList());
92 List
<DefinedTermBase
> terms
= CdmStore
.getService(ITermService
.class).load(termUuids
, null);
93 List
<State
> states
= new ArrayList
<>();
94 for (DefinedTermBase definedTermBase
: terms
) {
95 if(definedTermBase
instanceof State
){
96 states
.add((State
) definedTermBase
);
99 rowWrapper
.setDataValueForFeature(feature
, states
);
105 public int getColumnCount() {
106 return matrix
.getPropertyToLabelMap().size();
110 public String
getColumnProperty(int columnIndex
) {
111 return matrix
.getPropertyToLabelMap().get(columnIndex
);
115 public int getColumnIndex(String propertyName
){
116 return matrix
.getPropertyToLabelMap().indexOf(propertyName
);