2 * Copyright (C) 2018 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
.Optional
;
14 import org
.eclipse
.nebula
.widgets
.nattable
.layer
.LabelStack
;
15 import org
.eclipse
.nebula
.widgets
.nattable
.layer
.cell
.IConfigLabelAccumulator
;
17 import eu
.etaxonomy
.cdm
.api
.service
.dto
.DescriptionBaseDto
;
18 import eu
.etaxonomy
.cdm
.api
.service
.dto
.RowWrapperDTO
;
19 import eu
.etaxonomy
.cdm
.api
.service
.dto
.SpecimenRowWrapperDTO
;
20 import eu
.etaxonomy
.cdm
.api
.service
.dto
.TaxonRowWrapperDTO
;
21 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
22 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
23 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionType
;
24 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
25 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
26 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
27 import eu
.etaxonomy
.cdm
.persistence
.dto
.TaxonNodeDto
;
34 public class CharacterMatrixConfigLabelAccumulator
implements IConfigLabelAccumulator
{
36 public static final String HAS_DEFAULT
= "HAS_DEFAULT";
37 public static final String DEFAULT_OVERRIDDEN
= "DEFAULT_OVERRIDDEN";
38 public static final String QUANTITATIVE
= "QUANTITATIVE";
39 public static final String CATEGORICAL
= "CATEGORICAL";
40 public static final String CATEGORICAL_EDITABLE
= CATEGORICAL
+"_EDITABLE";
41 public static final String QUANTITATIVE_EDITABLE
= QUANTITATIVE
+"_EDITABLE";
43 private CharacterMatrix matrix
;
45 public CharacterMatrixConfigLabelAccumulator(CharacterMatrix matrix
) {
51 public void accumulateConfigLabels(LabelStack configLabels
, int columnPosition
, int rowPosition
) {
52 boolean isEditable
= true;
54 Object rowObject
= matrix
.getBodyDataProvider().getRowObject(rowPosition
);
55 if(rowObject
instanceof TaxonNodeDto
){
56 configLabels
.addLabel(CharacterMatrix
.LABEL_TAXON_ROW
);
58 else if(rowObject
instanceof TaxonRowWrapperDTO
){
59 TaxonRowWrapperDTO taxonRowWrapper
= (TaxonRowWrapperDTO
) rowObject
;
60 if(MatrixUtility
.isAggregatedTaxonDescription(taxonRowWrapper
)){
61 configLabels
.addLabel(CharacterMatrix
.LABEL_TAXON_AGGREGATED_DESCRIPTION
);
63 if(columnPosition
==0){
64 configLabels
.addLabel(CharacterMatrix
.LABEL_TAXON_AGGREGATED_DESCRIPTION_ICON
);
67 else if(MatrixUtility
.isDefaultTaxonDescription(taxonRowWrapper
)){
68 configLabels
.addLabel(CharacterMatrix
.LABEL_TAXON_DEFAULT_DESCRIPTION
);
69 if(columnPosition
==0){
70 configLabels
.addLabel(CharacterMatrix
.LABEL_TAXON_DEFAULT_DESCRIPTION_ICON
);
73 else if(MatrixUtility
.isLiteratureTaxonDescription(taxonRowWrapper
)){
74 configLabels
.addLabel(CharacterMatrix
.LABEL_TAXON_LITERATURE_DESCRIPTION
);
75 if(columnPosition
==0){
76 configLabels
.addLabel(CharacterMatrix
.LABEL_TAXON_LITERATURE_DESCRIPTION_ICON
);
78 // check for existing default values
79 if(columnPosition
>=CharacterMatrix
.LEADING_COLUMN_COUNT
){
80 Feature feature
= matrix
.getFeatures().get(columnPosition
-CharacterMatrix
.LEADING_COLUMN_COUNT
);
81 if(hasDefaultValue(feature
, taxonRowWrapper
)){
82 configLabels
.addLabel(HAS_DEFAULT
);
83 if(hasDefaultOverriddenValue(feature
, taxonRowWrapper
)){
84 configLabels
.removeLabel(HAS_DEFAULT
);
85 configLabels
.addLabel(DEFAULT_OVERRIDDEN
);
90 //check for supplemental data
91 if(!taxonRowWrapper
.getDescription().getDescription().getSources().isEmpty() && columnPosition
==0){
92 configLabels
.addLabel(CharacterMatrix
.LABEL_DESCRIPTION_HAS_SUPPLEMENTAL_DATA
);
94 configLabels
.addLabel(CharacterMatrix
.LABEL_TAXON_DESCRIPTION
);
97 if(columnPosition
==0){
98 configLabels
.addLabel(CharacterMatrix
.TAXON_COLUMN
);
100 else if(columnPosition
==1){
101 configLabels
.addLabel(CharacterMatrix
.COLLECTOR_COLUMN
);
103 else if(columnPosition
==2){
104 configLabels
.addLabel(CharacterMatrix
.IDENTIFIER_COLUMN
);
106 else if(columnPosition
==3){
107 configLabels
.addLabel(CharacterMatrix
.COUNTRY_COLUMN
);
110 Feature feature
= matrix
.getFeatures().get(columnPosition
-CharacterMatrix
.LEADING_COLUMN_COUNT
);
111 configLabels
.addLabel(MatrixUtility
.getProperty(feature
));
112 // check for default values
113 if(rowObject
instanceof SpecimenRowWrapperDTO
){
114 SpecimenRowWrapperDTO specimenRowWrapper
= (SpecimenRowWrapperDTO
)rowObject
;
115 if(hasDefaultValue(feature
, specimenRowWrapper
)){
116 configLabels
.addLabel(HAS_DEFAULT
);
117 if(hasDefaultOverriddenValue(feature
, specimenRowWrapper
)){
118 configLabels
.removeLabel(HAS_DEFAULT
);
119 configLabels
.addLabel(DEFAULT_OVERRIDDEN
);
124 if(feature
.isSupportsCategoricalData()){
125 configLabels
.addLabel(CATEGORICAL
);
127 configLabels
.addLabel(CATEGORICAL_EDITABLE
);
130 else if(feature
.isSupportsQuantitativeData()){
131 configLabels
.addLabel(QUANTITATIVE
);
133 configLabels
.addLabel(QUANTITATIVE_EDITABLE
);
139 private boolean hasDefaultOverriddenValue(Feature feature
, RowWrapperDTO
<?
> rowWrapper
) {
140 DescriptionElementBase dataValueForFeature
= rowWrapper
.getDataValueForFeature(feature
);
141 if(dataValueForFeature
!=null){
142 if(dataValueForFeature
instanceof CategoricalData
){
143 return !((CategoricalData
) dataValueForFeature
).getStatesOnly().isEmpty();
145 else if(dataValueForFeature
instanceof QuantitativeData
){
146 return !((QuantitativeData
) dataValueForFeature
).getStatisticalValues().isEmpty();
152 private boolean hasDefaultValue(Feature feature
, RowWrapperDTO
<?
> rowWrapperDTO
) {
153 if(rowWrapperDTO
instanceof SpecimenRowWrapperDTO
154 && ((SpecimenRowWrapperDTO
) rowWrapperDTO
).getDefaultDescription()!=null){
155 TaxonDescription taxDescription
= (TaxonDescription
)((SpecimenRowWrapperDTO
)rowWrapperDTO
).getDefaultDescription().getDescription().getDescription();
156 return hasDefaultValue(feature
, taxDescription
);
158 else if(rowWrapperDTO
instanceof TaxonRowWrapperDTO
){
159 TaxonRowWrapperDTO taxonRowWrapper
= (TaxonRowWrapperDTO
)rowWrapperDTO
;
160 Set
<DescriptionBaseDto
> descriptions
= taxonRowWrapper
.getTaxonDescriptions();
161 for (DescriptionBaseDto taxonDescription
: descriptions
) {
162 if(matrix
.getDescriptiveDataSet().getDescriptions().contains(taxonDescription
)
163 && taxonDescription
.getDescription().getTypes().contains(DescriptionType
.DEFAULT_VALUES_FOR_AGGREGATION
)){
164 return hasDefaultValue(feature
, (TaxonDescription
)taxonDescription
.getDescription());
171 private boolean hasDefaultValue(Feature feature
, TaxonDescription defaultDescription
) {
172 if(defaultDescription
!=null){
173 Optional
<DescriptionElementBase
> descriptionElement
= defaultDescription
.getElements().stream()
174 .filter(element
->element
.getFeature().equals(feature
))
176 if(descriptionElement
.isPresent() && descriptionElement
.get() instanceof CategoricalData
){
177 return !((CategoricalData
) descriptionElement
.get()).getStatesOnly().isEmpty();
179 else if(descriptionElement
.isPresent() && descriptionElement
.get() instanceof QuantitativeData
){
180 return !((QuantitativeData
) descriptionElement
.get()).getStatisticalValues().isEmpty();