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
;
12 import java
.util
.stream
.Collectors
;
14 import org
.eclipse
.swt
.graphics
.Image
;
16 import eu
.etaxonomy
.cdm
.api
.service
.dto
.TaxonRowWrapperDTO
;
17 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionType
;
18 import eu
.etaxonomy
.cdm
.model
.description
.DescriptiveDataSet
;
19 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
20 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
21 import eu
.etaxonomy
.cdm
.model
.description
.StatisticalMeasure
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
24 import eu
.etaxonomy
.taxeditor
.model
.ImageResources
;
27 * Utility class for the character matrix editor
32 public class MatrixUtility
{
35 * Returns the column property string for the given {@link Feature}
39 public static String
getProperty(Feature feature
){
40 return feature
.getLabel();
44 * Returns a string representation for the given {@link QuantitativeData}
45 * @param data the quantitative data
46 * @return a string representation of the data
48 public static String
getQuantitativeLabel(QuantitativeData data
) {
50 Float min
= data
.getMin();
51 Float max
= data
.getMax();
52 if(min
!=null||max
!=null){
53 label
+= "["+(min
!=null?min
.toString():"?")+"-"+(max
!=null?max
.toString():"?")+"] ";
55 label
+= data
.getStatisticalValues().stream().
56 filter(value
->value
.getType().equals(StatisticalMeasure
.EXACT_VALUE()))
57 .map(exact
->Float
.toString(exact
.getValue()))
58 .collect(Collectors
.joining(", "));
64 * Returns a string representation for the given min/max values
65 * @param minTotal the min value
66 * @param maxTotal the max value
67 * @return a string representation of the data
69 public static String
getQuantitativeLabel(Float min
, Float exact
, Float max
) {
70 return (min
==null?
"":"("+min
.toString()+")") //$NON-NLS-1$
71 +(exact
==null?
"":exact
.toString()) //$NON-NLS-1$
72 +(max
==null?
"":"("+max
.toString()+")"); //$NON-NLS-1$
75 public static Classification
getClassificationForDescriptiveDataSet(DescriptiveDataSet descriptiveDataSet
){
76 Set
<TaxonNode
> taxonSubtreeFilter
= descriptiveDataSet
.getTaxonSubtreeFilter();
77 if(taxonSubtreeFilter
!=null && !taxonSubtreeFilter
.isEmpty()){
78 return taxonSubtreeFilter
.iterator().next().getClassification();
83 public static boolean isDefaultTaxonDescription(TaxonRowWrapperDTO taxonRowWrapperDTO
){
84 return hasType(taxonRowWrapperDTO
, DescriptionType
.DEFAULT_VALUES_FOR_AGGREGATION
);
87 public static boolean isAggregatedTaxonDescription(TaxonRowWrapperDTO taxonRowWrapperDTO
){
88 return hasType(taxonRowWrapperDTO
, DescriptionType
.AGGREGATED_STRUC_DESC
);
91 public static boolean isLiteratureTaxonDescription(TaxonRowWrapperDTO taxonRowWrapperDTO
){
92 return hasType(taxonRowWrapperDTO
, DescriptionType
.SECONDARY_DATA
);
95 private static boolean hasType(TaxonRowWrapperDTO taxonRowWrapperDTO
, DescriptionType descriptionType
){
96 return taxonRowWrapperDTO
.getDescription().getTypes().stream()
97 .anyMatch(type
->type
.equals(descriptionType
));
100 public static Image
getLiteratureDescriptionIcon() {
101 return ImageResources
.getImage(ImageResources
.HELP_TOPIC
);
104 public static Image
getAggregatedDescriptionIcon() {
105 return ImageResources
.getImage(ImageResources
.FUNNEL_ICON
);
108 public static Image
getDefaultDescriptionIcon() {
109 return ImageResources
.getImage(ImageResources
.VALIDATE_ICON
);