Merge branch 'release/5.42.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / model / DescriptionHelper.java
index cd37168ac16de3bddbde8f3260a2cc9a1c0873b1..a6a07de2ef32106a02b8caff9338b014b5cdc5a5 100644 (file)
@@ -13,9 +13,9 @@ import java.util.List;
 
 import org.apache.commons.lang3.StringUtils;
 
-import eu.etaxonomy.cdm.format.DescriptionElementFormatter;
 import eu.etaxonomy.cdm.format.common.ExtendedTimePeriodFormatter;
 import eu.etaxonomy.cdm.format.description.CategoricalDataFormatter;
+import eu.etaxonomy.cdm.format.description.DescriptionElementFormatter;
 import eu.etaxonomy.cdm.format.description.QuantitativeDataFormatter;
 import eu.etaxonomy.cdm.model.common.ExtendedTimePeriod;
 import eu.etaxonomy.cdm.model.common.Language;
@@ -37,6 +37,7 @@ import eu.etaxonomy.cdm.model.location.NamedArea;
 import eu.etaxonomy.cdm.model.media.Media;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
 import eu.etaxonomy.taxeditor.store.CdmStore;
 
 /**
@@ -115,7 +116,7 @@ public class DescriptionHelper {
         */
        public static void setCache(DescriptionElementBase element,
                        String value) {
-               setCache(element, value, CdmStore.getDefaultLanguage());
+               setCache(element, value, PreferencesUtil.getGlobalLanguage());
        }
 
 //     public static String getObjectClassname(Object element) {
@@ -129,7 +130,8 @@ public class DescriptionHelper {
        public static String getFeatureNodeContainerText(FeatureNodeContainer element) {
                String result = null;
                if(element.getFeatureNode() != null && element.getFeatureNode().getTerm() != null){
-                       result = element.getFeatureNode().getTerm().getLabel(CdmStore.getDefaultLanguage());
+
+                       result = element.getFeatureNode().getTerm().getPreferredRepresentation(PreferencesUtil.getGlobalLanguage()).getLabel();
                } else{
                        return "No label set";
                }
@@ -151,7 +153,7 @@ public class DescriptionHelper {
        }
 
        private static List<Language> getLanguageList(){
-               return Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
+               return Arrays.asList(new Language[]{PreferencesUtil.getGlobalLanguage()});
        }
 
        public static String getDistributionText(Distribution element) {
@@ -163,12 +165,12 @@ public class DescriptionHelper {
                NamedArea area = distribution.getArea();
                if(area != null){
 
-                       text = NamedArea.labelWithLevel(area, CdmStore.getDefaultLanguage());
+                       text = NamedArea.labelWithLevel(area, PreferencesUtil.getGlobalLanguage());
 
                        PresenceAbsenceTerm status = distribution.getStatus();
 
                        if (status != null) {
-                               text += ", " + status.getLabel();
+                               text += ", " + status.getPreferredRepresentation(PreferencesUtil.getGlobalLanguage()).getLabel();
                        }else{
                                text += ", NO STATUS";
                        }
@@ -177,7 +179,7 @@ public class DescriptionHelper {
        }
 
        public static  String getImageText(Media media) {
-                LanguageString title = media.getTitle(CdmStore.getDefaultLanguage());
+                LanguageString title = media.getTitle(PreferencesUtil.getGlobalLanguage());
                if (title != null) {
                        return title.getText();
                }
@@ -200,7 +202,7 @@ public class DescriptionHelper {
                                text = "No sources provided";
                        }
                }else{
-                       List<Language> languages = Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()});
+                       List<Language> languages = Arrays.asList(new Language[]{PreferencesUtil.getGlobalLanguage()});
                        LanguageString languageString = element.getPreferredLanguageString(languages);
                        text = languageString != null ? languageString.getText() : null;
                }
@@ -224,12 +226,34 @@ public class DescriptionHelper {
                if (name == null || name.length() == 0) {
                        name = "No name provided";
                }
+               if (commonName.getTransliteration()!= null && !StringUtils.isBlank(commonName.getTransliteration())) {
+                   name += "/" +commonName.getTransliteration() + " ";
+               }
                Language language = commonName.getLanguage();
-               if (language == null) {
-                       name += " (No language provided)";
-               } else {
-                       name += " (" + language.getLabel(CdmStore.getDefaultLanguage()) + ")";
+               NamedArea area = commonName.getArea();
+               String areaLabel = null;
+               String languageLabel = null;
+               if (area != null){
+                       areaLabel = area.getPreferredRepresentation(PreferencesUtil.getGlobalLanguage()).getLabel();
+               }
+               if (language != null){
+                       languageLabel = language.getPreferredRepresentation(PreferencesUtil.getGlobalLanguage()).getLabel();
+               }
+               if (areaLabel != null || languageLabel != null){
+                       name += " (" ;
+                       if (languageLabel != null){
+                               name += languageLabel;
+                       }
+                       if (areaLabel != null){
+                               if (languageLabel != null){
+                                       name += ", ";
+                               }
+                               name += areaLabel;
+                       }
+                       name +=  ")";
                }
+
+
                return name;
        }
 
@@ -238,7 +262,7 @@ public class DescriptionHelper {
                if (text == null || text.length() == 0) {
                        text = "No label provided";
                }
-
+               
                return text;
        }