ref #8651 Adapt to finer grained aggregation description type
[taxeditor.git] / eu.etaxonomy.taxeditor.editor / src / main / java / eu / etaxonomy / taxeditor / editor / descriptiveDataSet / matrix / MatrixUtility.java
1 /**
2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.taxeditor.editor.descriptiveDataSet.matrix;
10
11 import java.util.Set;
12 import java.util.stream.Collectors;
13
14 import org.eclipse.swt.graphics.Image;
15
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;
25
26 /**
27 * Utility class for the character matrix editor
28 * @author pplitzner
29 * @since Jan 4, 2018
30 *
31 */
32 public class MatrixUtility {
33
34 /**
35 * Returns the column property string for the given {@link Feature}
36 * @param feature
37 * @return
38 */
39 public static String getProperty(Feature feature){
40 return feature.getLabel();
41 }
42
43 /**
44 * Returns a string representation for the given {@link QuantitativeData}
45 * @param data the quantitative data
46 * @return a string representation of the data
47 */
48 public static String getQuantitativeLabel(QuantitativeData data) {
49 String label = "";
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():"?")+"] ";
54 }
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(", "));
59
60 return label;
61 }
62
63 /**
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
68 */
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$
73 }
74
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();
79 }
80 return null;
81 }
82
83 public static boolean isDefaultTaxonDescription(TaxonRowWrapperDTO taxonRowWrapperDTO){
84 return hasType(taxonRowWrapperDTO, DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION);
85 }
86
87 public static boolean isAggregatedTaxonDescription(TaxonRowWrapperDTO taxonRowWrapperDTO){
88 return hasType(taxonRowWrapperDTO, DescriptionType.AGGREGATED_STRUC_DESC);
89 }
90
91 public static boolean isLiteratureTaxonDescription(TaxonRowWrapperDTO taxonRowWrapperDTO){
92 return hasType(taxonRowWrapperDTO, DescriptionType.SECONDARY_DATA);
93 }
94
95 private static boolean hasType(TaxonRowWrapperDTO taxonRowWrapperDTO, DescriptionType descriptionType){
96 return taxonRowWrapperDTO.getDescription().getTypes().stream()
97 .anyMatch(type->type.equals(descriptionType));
98 }
99
100 public static Image getLiteratureDescriptionIcon() {
101 return ImageResources.getImage(ImageResources.HELP_TOPIC);
102 }
103
104 public static Image getAggregatedDescriptionIcon() {
105 return ImageResources.getImage(ImageResources.FUNNEL_ICON);
106 }
107
108 public static Image getDefaultDescriptionIcon() {
109 return ImageResources.getImage(ImageResources.VALIDATE_ICON);
110 }
111 }
112