ref #8785: update descriptions in description list after merge
[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
13 import org.eclipse.swt.graphics.Image;
14
15 import eu.etaxonomy.cdm.api.service.dto.TaxonRowWrapperDTO;
16 import eu.etaxonomy.cdm.model.description.DescriptionType;
17 import eu.etaxonomy.cdm.model.description.DescriptiveDataSet;
18 import eu.etaxonomy.cdm.model.description.Feature;
19 import eu.etaxonomy.cdm.model.taxon.Classification;
20 import eu.etaxonomy.cdm.model.taxon.TaxonNode;
21 import eu.etaxonomy.taxeditor.model.ImageResources;
22
23 /**
24 * Utility class for the character matrix editor
25 * @author pplitzner
26 * @since Jan 4, 2018
27 *
28 */
29 public class MatrixUtility {
30
31 /**
32 * Returns the column property string for the given {@link Feature}
33 * @param feature
34 * @return
35 */
36 public static String getProperty(Feature feature){
37 return feature.getLabel();
38 }
39
40 /**
41 * Returns a string representation for the given min/max values
42 * @param minTotal the min value
43 * @param maxTotal the max value
44 * @return a string representation of the data
45 */
46 public static String getQuantitativeLabel(Float min, Float exact, Float max) {
47 return (min==null?"":"("+min.toString()+")") //$NON-NLS-1$
48 +(exact==null?"":exact.toString()) //$NON-NLS-1$
49 +(max==null?"":"("+max.toString()+")"); //$NON-NLS-1$
50 }
51
52 public static Classification getClassificationForDescriptiveDataSet(DescriptiveDataSet descriptiveDataSet){
53 Set<TaxonNode> taxonSubtreeFilter = descriptiveDataSet.getTaxonSubtreeFilter();
54 if(taxonSubtreeFilter!=null && !taxonSubtreeFilter.isEmpty()){
55 return taxonSubtreeFilter.iterator().next().getClassification();
56 }
57 return null;
58 }
59
60 public static boolean isDefaultTaxonDescription(TaxonRowWrapperDTO taxonRowWrapperDTO){
61 return hasType(taxonRowWrapperDTO, DescriptionType.DEFAULT_VALUES_FOR_AGGREGATION);
62 }
63
64 public static boolean isAggregatedTaxonDescription(TaxonRowWrapperDTO taxonRowWrapperDTO){
65 return hasType(taxonRowWrapperDTO, DescriptionType.AGGREGATED_STRUC_DESC);
66 }
67
68 public static boolean isLiteratureTaxonDescription(TaxonRowWrapperDTO taxonRowWrapperDTO){
69 return hasType(taxonRowWrapperDTO, DescriptionType.SECONDARY_DATA);
70 }
71
72 private static boolean hasType(TaxonRowWrapperDTO taxonRowWrapperDTO, DescriptionType descriptionType){
73 return taxonRowWrapperDTO.getDescription().getDescription().getTypes().stream()
74 .anyMatch(type->type.equals(descriptionType));
75 }
76
77 public static Image getLiteratureDescriptionIcon() {
78 return ImageResources.getImage(ImageResources.HELP_TOPIC);
79 }
80
81 public static Image getAggregatedDescriptionIcon() {
82 return ImageResources.getImage(ImageResources.FUNNEL_ICON);
83 }
84
85 public static Image getDefaultDescriptionIcon() {
86 return ImageResources.getImage(ImageResources.VALIDATE_ICON);
87 }
88 }
89