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
;
16 import org
.apache
.commons
.lang3
.StringUtils
;
17 import org
.eclipse
.nebula
.widgets
.nattable
.data
.IColumnPropertyAccessor
;
19 import eu
.etaxonomy
.cdm
.api
.service
.dto
.RowWrapperDTO
;
20 import eu
.etaxonomy
.cdm
.api
.service
.dto
.SpecimenRowWrapperDTO
;
21 import eu
.etaxonomy
.cdm
.api
.service
.dto
.TaxonRowWrapperDTO
;
22 import eu
.etaxonomy
.cdm
.persistence
.dto
.DescriptionElementDto
;
23 import eu
.etaxonomy
.cdm
.persistence
.dto
.FeatureDto
;
24 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermDto
;
25 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
28 * Property accessor class which maps setting and getting data for
29 * each row in the character matrix
35 public class SpecimenColumnPropertyAccessor
implements IColumnPropertyAccessor
<Object
>{
37 private CharacterMatrix matrix
;
39 public SpecimenColumnPropertyAccessor(CharacterMatrix matrix
) {
44 public Object
getDataValue(Object rowObject
, int columnIndex
) {
45 if(rowObject
instanceof SpecimenRowWrapperDTO
){
46 SpecimenRowWrapperDTO rowWrapper
= (SpecimenRowWrapperDTO
) rowObject
;
47 switch (columnIndex
) {
49 if(matrix
.isTreeView()){
50 return "#"+rowWrapper
.getSpecimenDto().getId();
53 return rowWrapper
.getTaxonNode();
56 if (rowWrapper
.getSpecimenDto() != null){
57 if (StringUtils
.isBlank(rowWrapper
.getSpecimenDto().getCollectorsString())){
58 if (rowWrapper
.getFieldUnit() != null){
59 return rowWrapper
.getFieldUnit().getTitleCache();
61 return "no information";
64 return rowWrapper
.getSpecimenDto().getCollectorsString();
65 }else if (rowWrapper
.getFieldUnit() != null){
66 return rowWrapper
.getFieldUnit().getTitleCache();
68 return "no information";
71 return rowWrapper
.getIdentifier();
73 return rowWrapper
.getCountry();
78 FeatureDto feature
= matrix
.getIndexToFeatureMap().get(columnIndex
);
79 return rowWrapper
.getDisplayDataForFeature(feature
.getUuid());
81 else if(rowObject
instanceof TaxonRowWrapperDTO
){
82 TaxonRowWrapperDTO taxonWrapper
= (TaxonRowWrapperDTO
)rowObject
;
84 return taxonWrapper
.getDescription();
86 FeatureDto feature
= matrix
.getIndexToFeatureMap().get(columnIndex
);
90 return taxonWrapper
.getDisplayDataForFeature(feature
.getUuid());
92 } else if (columnIndex
== 0) {
98 public Object
getData(Object rowObject
, int columnIndex
) {
99 if (rowObject
instanceof SpecimenRowWrapperDTO
) {
100 SpecimenRowWrapperDTO rowWrapper
= (SpecimenRowWrapperDTO
) rowObject
;
101 switch (columnIndex
) {
103 if (matrix
.isTreeView()) {
104 return "#" + rowWrapper
.getSpecimenDto().getId();
106 return rowWrapper
.getTaxonNode();
109 if (rowWrapper
.getSpecimenDto() != null) {
110 if (StringUtils
.isBlank(rowWrapper
.getSpecimenDto().getCollectorsString())) {
111 if (rowWrapper
.getFieldUnit() != null) {
112 return rowWrapper
.getFieldUnit().getTitleCache();
114 return "no information";
117 return rowWrapper
.getSpecimenDto().getCollectorsString();
118 } else if (rowWrapper
.getFieldUnit() != null) {
119 return rowWrapper
.getFieldUnit().getTitleCache();
121 return "no information";
124 return rowWrapper
.getIdentifier();
126 return rowWrapper
.getCountry();
131 FeatureDto feature
= matrix
.getIndexToFeatureMap().get(columnIndex
);
132 Set
<DescriptionElementDto
> data
= rowWrapper
.getDataValueForFeature(feature
.getUuid());
133 DescriptionElementDto result
= null;
134 if (data
!= null && !data
.isEmpty()) {
135 result
= data
.iterator().next();
138 } else if (rowObject
instanceof TaxonRowWrapperDTO
) {
139 TaxonRowWrapperDTO taxonWrapper
= (TaxonRowWrapperDTO
) rowObject
;
140 if (columnIndex
== 0) {
141 return taxonWrapper
.getDescription();
143 FeatureDto feature
= matrix
.getIndexToFeatureMap().get(columnIndex
);
144 if (feature
== null) {
147 return taxonWrapper
.getDataValueForFeature(feature
.getUuid());
149 } else if (columnIndex
== 0) {
156 public void setDataValue(Object rowObject
, int columnIndex
, Object newValue
) {
157 if (rowObject
instanceof RowWrapperDTO
) {
158 RowWrapperDTO rowWrapper
= (RowWrapperDTO
) rowObject
;
160 FeatureDto feature
= matrix
.getIndexToFeatureMap().get(columnIndex
);
161 if(feature
.isSupportsCategoricalData()
162 && newValue
instanceof Collection
){
164 List
<Object
> dtos
= new ArrayList
<>();
166 //TODO:This needs to be adapted because already added modifiers will be deleted!!!!!
167 if (((Collection
) newValue
).stream().allMatch(o
-> o
instanceof TermDto
)) {
168 dtos
= (List
<Object
>) newValue
;
171 rowWrapper
.setDataValueForCategoricalData(feature
.getUuid(), dtos
, PreferencesUtil
.getGlobalLanguage());
172 matrix
.putRowToMerge(rowWrapper
);
178 public int getColumnCount() {
179 return matrix
.getPropertyToLabelMap().size();
183 public String
getColumnProperty(int columnIndex
) {
184 return matrix
.getPropertyToLabelMap().get(columnIndex
);
188 public int getColumnIndex(String propertyName
){
189 return matrix
.getPropertyToLabelMap().indexOf(propertyName
);