3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.model
;
13 import java
.lang
.reflect
.InvocationTargetException
;
14 import java
.lang
.reflect
.Method
;
15 import java
.util
.Arrays
;
16 import java
.util
.List
;
19 import org
.apache
.commons
.lang
.StringUtils
;
20 import org
.hibernate
.LazyInitializationException
;
22 import eu
.etaxonomy
.cdm
.api
.service
.DefaultCategoricalDescriptionBuilder
;
23 import eu
.etaxonomy
.cdm
.api
.service
.DefaultQuantitativeDescriptionBuilder
;
24 import eu
.etaxonomy
.cdm
.api
.service
.DescriptionBuilder
;
25 import eu
.etaxonomy
.cdm
.common
.CdmUtils
;
26 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
27 import eu
.etaxonomy
.cdm
.model
.common
.Group
;
28 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableEntity
;
29 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
30 import eu
.etaxonomy
.cdm
.model
.common
.LanguageString
;
31 import eu
.etaxonomy
.cdm
.model
.common
.LanguageStringBase
;
32 import eu
.etaxonomy
.cdm
.model
.common
.Marker
;
33 import eu
.etaxonomy
.cdm
.model
.common
.MarkerType
;
34 import eu
.etaxonomy
.cdm
.model
.common
.OriginalSourceBase
;
35 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipBase
;
36 import eu
.etaxonomy
.cdm
.model
.common
.RelationshipTermBase
;
37 import eu
.etaxonomy
.cdm
.model
.common
.Representation
;
38 import eu
.etaxonomy
.cdm
.model
.common
.User
;
39 import eu
.etaxonomy
.cdm
.model
.description
.CategoricalData
;
40 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
41 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionBase
;
42 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
43 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
44 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
45 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
46 import eu
.etaxonomy
.cdm
.model
.description
.IndividualsAssociation
;
47 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTerm
;
48 import eu
.etaxonomy
.cdm
.model
.description
.QuantitativeData
;
49 import eu
.etaxonomy
.cdm
.model
.description
.SpecimenDescription
;
50 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
51 import eu
.etaxonomy
.cdm
.model
.description
.TaxonInteraction
;
52 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
53 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
54 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
55 import eu
.etaxonomy
.cdm
.model
.media
.Media
;
56 import eu
.etaxonomy
.cdm
.model
.name
.HomotypicalGroup
;
57 import eu
.etaxonomy
.cdm
.model
.name
.HybridRelationship
;
58 import eu
.etaxonomy
.cdm
.model
.name
.NameRelationship
;
59 import eu
.etaxonomy
.cdm
.model
.name
.NameTypeDesignation
;
60 import eu
.etaxonomy
.cdm
.model
.name
.SpecimenTypeDesignation
;
61 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
62 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
63 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationStatusBase
;
64 import eu
.etaxonomy
.cdm
.model
.occurrence
.DeterminationEvent
;
65 import eu
.etaxonomy
.cdm
.model
.occurrence
.SpecimenOrObservationBase
;
66 import eu
.etaxonomy
.cdm
.model
.taxon
.Classification
;
67 import eu
.etaxonomy
.cdm
.model
.taxon
.SynonymRelationship
;
68 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
69 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
70 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
71 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonRelationship
;
72 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
75 * <p>DescriptionHelper class.</p>
81 public class DescriptionHelper
{
84 * Returns whatever the element's title cache equivalent is,
85 * depending on its class.
87 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
88 * @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
89 * @return a {@link java.lang.String} object.
91 public static String
getCache(DescriptionElementBase element
,
94 String mainElementLabel
= null;
95 DescriptionBase
<?
> descr
= element
.getInDescription();
97 if (descr
.isInstanceOf(TaxonDescription
.class)){
98 Taxon taxon
= CdmBase
.deproxy(descr
, TaxonDescription
.class).getTaxon();
100 mainElementLabel
= taxon
.getTitleCache();
102 }else if (descr
.isInstanceOf(SpecimenDescription
.class)){
103 SpecimenOrObservationBase
<?
> specimen
= CdmBase
.deproxy(descr
, SpecimenDescription
.class).getDescribedSpecimenOrObservation();
104 if (specimen
!= null){
105 mainElementLabel
= specimen
.getTitleCache();
107 }else if (descr
.isInstanceOf(TaxonNameDescription
.class)){
108 TaxonNameBase
<?
, ?
> name
= CdmBase
.deproxy(descr
, TaxonNameDescription
.class).getTaxonName();
110 mainElementLabel
= name
.getTitleCache();
116 if (element
instanceof TextData
) {
117 cache
= ((TextData
) element
).getText(language
);
119 if (element
instanceof CommonTaxonName
) {
120 cache
= ((CommonTaxonName
) element
).getName();
122 if (element
instanceof TaxonInteraction
) {
123 Taxon taxon2
= ((TaxonInteraction
) element
).getTaxon2();
124 if(taxon2
!= null && taxon2
.getName() != null){
125 cache
= taxon2
.getName().getTitleCache();
127 cache
= "No taxon chosen";
131 if (element
instanceof Distribution
) {
132 Distribution distribution
= (Distribution
) element
;
134 NamedArea area
= distribution
.getArea();
136 cache
= area
.getLabel();
138 PresenceAbsenceTerm status
= distribution
.getStatus();
140 cache
+= ", no status";
142 cache
+= ", " + status
.getLabel();
146 String result
= cache
== null ?
"" : cache
;
147 if (StringUtils
.isNotBlank(mainElementLabel
)){
148 result
= CdmUtils
.concat(" ", result
, "(" + mainElementLabel
+ ")");
154 * Returns whatever the element's title cache equivalent is,
155 * depending on its class, using the default language.
157 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
158 * @return a {@link java.lang.String} object.
160 public static String
getCache(DescriptionElementBase element
) {
161 return getCache(element
, CdmStore
.getDefaultLanguage());
165 * Set whatever the element's title cache equivalent is,
166 * depending on its class.
168 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
169 * @param value a {@link java.lang.String} object.
170 * @param language a {@link eu.etaxonomy.cdm.model.common.Language} object.
172 public static void setCache(DescriptionElementBase element
,
173 String value
, Language language
) {
174 if (element
instanceof TextData
) {
175 ((TextData
) element
).putText(language
, value
);
177 }else if (element
instanceof CommonTaxonName
) {
178 ((CommonTaxonName
) element
).setName(value
);
180 }else if (element
instanceof TaxonInteraction
) {
182 }else if(element
instanceof Distribution
){
183 MessagingUtils
.warn(DescriptionHelper
.class, "trying to set cache on distribution, don't know what to do at the moment.");
186 MessagingUtils
.warn(DescriptionHelper
.class, "No matching subclass found for DescriptionElementBase object, 'cache' not set.");
191 * Set whatever the element's title cache equivalent is,
192 * depending on its class, using the default language.
194 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionElementBase} object.
195 * @param value a {@link java.lang.String} object.
197 public static void setCache(DescriptionElementBase element
,
199 setCache(element
, value
, CdmStore
.getDefaultLanguage());
204 * <p>getObjectDescription</p>
206 * @param element a {@link java.lang.Object} object.
207 * @return a {@link java.lang.String} object.
209 public static String
getObjectDescription(Object element
) {
210 if (element
instanceof IdentifiableEntity
) {
212 return ((IdentifiableEntity
) element
).getTitleCache();
213 }catch(LazyInitializationException e
){
214 String result
= "No Session to initialize title cache for IdentifiableEntity";
215 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
216 return "TODO: " + result
;
218 }else if (element
instanceof OriginalSourceBase
) {
220 OriginalSourceBase
<?
> originalSource
= (OriginalSourceBase
<?
>) element
;
221 // ISourceable sourcedObject = originalSource.getSourcedObj();
222 //due to #5743 the bidirectionality for sourced object had to be removed
223 String sourceObjectTitle
= "sourced object data not available (#5743)";
224 // if(sourcedObject instanceof IIdentifiableEntity){
225 // sourceObjectTitle = ((IdentifiableEntity) sourcedObject).getTitleCache();
226 // }else if(sourcedObject instanceof DescriptionElementBase){
227 // sourceObjectTitle = "Element for description: " + ((DescriptionElementBase) sourcedObject).getInDescription().getTitleCache();
229 // throw new IllegalStateException("Unknown ISourceable object for given OriginalSourceBase");
232 return CdmUtils
.concat("; ", new String
[]{originalSource
.getIdNamespace(), originalSource
.getIdInSource(), sourceObjectTitle
});
233 }catch(LazyInitializationException e
){
234 String result
= "Error initializing title cache for ISourceable of an OriginalSourceBase";
235 MessagingUtils
.error(DescriptionHelper
.class, result
, e
);
236 return "TODO: " + result
;
238 }else if (element
instanceof LanguageStringBase
) {
239 return ((LanguageStringBase
) element
).getText();
240 }else if (element
instanceof DescriptionElementBase
) {
241 return getCache((DescriptionElementBase
) element
);
242 }else if (element
instanceof RelationshipBase
<?
, ?
, ?
>) {
243 return getCache((RelationshipBase
<?
, ?
, ?
>) element
);
244 }else if (element
instanceof TypeDesignationBase
<?
>) {
245 return getCache((TypeDesignationBase
<?
>) element
);
246 }else if (element
instanceof HomotypicalGroup
) {
247 return getCache((HomotypicalGroup
) element
);
248 }else if (element
instanceof TaxonNode
) {
249 return getCache((TaxonNode
) element
);
250 }else if (element
instanceof DeterminationEvent
) {
251 return getCache((DeterminationEvent
) element
);
252 }else if (element
instanceof Marker
) {
253 Marker marker
= (Marker
) element
;
254 MarkerType type
= marker
.getMarkerType();
255 return (type
== null ?
"- no marker type -" : marker
.getMarkerType().getLabel()) + " (" + marker
.getFlag() + ")";
256 }else if (element
instanceof User
) {
257 User user
= (User
) element
;
258 return user
.getUsername();
259 }else if (element
instanceof Group
) {
260 Group group
= (Group
) element
;
261 return group
.getName();
263 // TODO write return texts for HomotypicalGroup, etc.
264 return element
.toString();
269 private static String
getCache(DeterminationEvent detEvent
) {
271 String taxonStr
= null;
272 TaxonNameBase
<?
,?
> taxonName
= detEvent
.getTaxonName();
273 TaxonBase
<?
> taxon
= detEvent
.getTaxon();
274 if (taxonName
!= null){
275 taxonStr
= taxonName
.getTitleCache();
277 if (StringUtils
.isBlank(taxonStr
) && taxon
!= null){
278 taxonStr
= taxon
.getTitleCache();
280 if (StringUtils
.isBlank(taxonStr
)){
281 taxonStr
= "no or unlabled taxon";
286 SpecimenOrObservationBase
<?
> unit
= detEvent
.getIdentifiedUnit();
289 unitStr
= unit
.getTitleCache();
290 if (StringUtils
.isBlank(unitStr
)){
291 unitStr
= "Unlabled unit";
297 String result
= CdmUtils
.concat(" determined as ", unitStr
, taxonStr
);
302 private static String
getCache(TaxonNode taxonNode
) {
304 Classification classification
= taxonNode
.getClassification();
305 if (classification
!= null){
306 String classificationStr
= classification
.getName() == null ?
"" : classification
.getName().getText();
307 result
= CdmUtils
.concat("" , result
, classificationStr
);
308 if (StringUtils
.isBlank(result
)){
309 result
= classification
.toString();
313 TaxonNode parentNode
= taxonNode
.getParent();
314 if (parentNode
== null){
315 parentStr
= "no parent";
317 Taxon parentTaxon
= parentNode
.getTaxon();
318 if (parentTaxon
== null){
319 parentStr
= "no parent taxon";
321 TaxonNameBase
<?
,?
> parentName
= parentTaxon
.getName();
322 if (parentName
== null){
323 parentStr
= "child of " + parentTaxon
.getTitleCache();
325 parentStr
= "child of " + parentName
.getTitleCache();
329 result
= CdmUtils
.concat(": ", result
, parentStr
);
334 private static String
getCache(TypeDesignationBase
<?
> designation
) {
335 designation
= CdmBase
.deproxy(designation
);
336 TypeDesignationStatusBase
<?
> status
= designation
.getTypeStatus();
337 Set
<TaxonNameBase
> from
;
338 IdentifiableEntity
<?
> to
;
339 from
= designation
.getTypifiedNames();
340 if (designation
.isInstanceOf(SpecimenTypeDesignation
.class)){
341 to
= ((SpecimenTypeDesignation
)designation
).getTypeSpecimen();
342 }else if (designation
.isInstanceOf(NameTypeDesignation
.class)){
343 to
= ((NameTypeDesignation
)designation
).getTypeName();
345 throw new RuntimeException("Type Designation class not supported: " + designation
.getClass().getName());
347 String typeLabel
= null;
349 Representation typeRepr
= status
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
350 if (typeRepr
!= null){
351 typeLabel
= typeRepr
.getAbbreviatedLabel();
353 if (StringUtils
.isBlank(typeLabel
) && typeRepr
!= null){
354 typeLabel
= typeRepr
.getLabel();
356 if (StringUtils
.isBlank(typeLabel
) ){
357 typeLabel
= status
.getSymbol();
359 if (StringUtils
.isBlank(typeLabel
)){
360 typeLabel
= status
.getTitleCache();
363 if (StringUtils
.isBlank(typeLabel
)){
366 String fromString
= "";
367 for (TaxonNameBase
<?
,?
> name
: from
){
368 CdmUtils
.concat(",", fromString
, name
.getTitleCache());
370 String result
= CdmUtils
.concat(" ", new String
[]{from
== null ?
null : fromString
,
371 typeLabel
, to
== null?
null : to
.getTitleCache()});
375 private static String
getCache(RelationshipBase
<?
, ?
, ?
> rel
) {
376 rel
= CdmBase
.deproxy(rel
);
377 RelationshipTermBase
<?
> type
= rel
.getType();
378 IdentifiableEntity
<?
> from
;
379 IdentifiableEntity
<?
> to
;
380 if (rel
.isInstanceOf(SynonymRelationship
.class)){
381 from
= ((SynonymRelationship
)rel
).getSynonym();
382 to
= ((SynonymRelationship
)rel
).getAcceptedTaxon();
383 }else if (rel
.isInstanceOf(NameRelationship
.class)){
384 from
= ((NameRelationship
)rel
).getFromName();
385 to
= ((NameRelationship
)rel
).getToName();
386 }else if (rel
.isInstanceOf(HybridRelationship
.class)){
387 from
= ((HybridRelationship
)rel
).getParentName();
388 to
= ((HybridRelationship
)rel
).getHybridName();
389 }else if (rel
.isInstanceOf(TaxonRelationship
.class)){
390 from
= ((TaxonRelationship
)rel
).getFromTaxon();
391 to
= ((TaxonRelationship
)rel
).getToTaxon();
394 Method fromMethod
= rel
.getClass().getMethod("getRelatedFrom");
395 Method toMethod
= rel
.getClass().getMethod("getRelatedFrom");
396 fromMethod
.setAccessible(true);
397 toMethod
.setAccessible(true);
398 from
= (IdentifiableEntity
<?
>)fromMethod
.invoke(rel
);
399 to
= (IdentifiableEntity
<?
>)toMethod
.invoke(rel
);
400 } catch (NoSuchMethodException
| SecurityException
| IllegalAccessException
401 | IllegalArgumentException
| InvocationTargetException e
) {
402 throw new RuntimeException(e
);
405 String typeLabel
= null;
407 Representation typeRepr
= type
.getPreferredRepresentation(CdmStore
.getDefaultLanguage());
408 if (typeRepr
!= null){
409 typeLabel
= typeRepr
.getAbbreviatedLabel();
411 if (StringUtils
.isBlank(typeLabel
) && typeRepr
!= null){
412 typeLabel
= typeRepr
.getLabel();
414 if (StringUtils
.isBlank(typeLabel
) ){
415 typeLabel
= type
.getSymbol();
417 if (StringUtils
.isBlank(typeLabel
)){
418 typeLabel
= type
.getTitleCache();
421 if (StringUtils
.isBlank(typeLabel
)){
424 String result
= CdmUtils
.concat(" ", new String
[]{from
== null ?
null : from
.getTitleCache(),
425 typeLabel
, to
== null?
null : to
.getTitleCache()});
430 private static String
getCache(HomotypicalGroup hg
) {
432 for (TaxonNameBase
<?
,?
> tnb
: hg
.getTypifiedNames()){
433 result
= CdmUtils
.concat(", ", result
, tnb
.getTitleCache());
435 if (StringUtils
.isBlank(result
)){
436 result
= "No typified names";
442 * <p>getObjectClassname</p>
444 * @param element a {@link java.lang.Object} object.
445 * @return a {@link java.lang.String} object.
447 public static String
getObjectClassname(Object element
) {
448 return element
.getClass().getSimpleName();
452 * <p>getFeatureNodeContainerText</p>
454 * @param element a {@link eu.etaxonomy.taxeditor.model.FeatureNodeContainer} object.
455 * @return a {@link java.lang.String} object.
457 public static String
getFeatureNodeContainerText(FeatureNodeContainer element
) {
458 String result
= null;
459 if(element
.getFeatureNode() != null && element
.getFeatureNode().getFeature() != null){
460 result
= element
.getFeatureNode().getFeature().getLabel(CdmStore
.getDefaultLanguage());
462 return "No label set";
465 result
= element
.getFeatureNode().getFeature().getLabel();
471 * <p>getQuantitativeDataText</p>
473 * @param element a {@link eu.etaxonomy.cdm.model.description.QuantitativeData} object.
474 * @return a {@link java.lang.String} object.
476 public static String
getQuantitativeDataText(QuantitativeData element
) {
477 TextData textData
= quantitativeDescriptionBuilder
.build(element
, getLanguageList());
479 return textData
.getText(CdmStore
.getDefaultLanguage());
483 * <p>getCategoricalDataText</p>
485 * @param element a {@link eu.etaxonomy.cdm.model.description.CategoricalData} object.
486 * @return a {@link java.lang.String} object.
488 public static String
getCategoricalDataText(CategoricalData element
) {
489 TextData textData
= categoricalDescriptionBuilder
.build(element
, getLanguageList());
491 return textData
.getText(CdmStore
.getDefaultLanguage());
494 private static List
<Language
> getLanguageList(){
495 return Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
498 private static DescriptionBuilder
<QuantitativeData
> quantitativeDescriptionBuilder
= new DefaultQuantitativeDescriptionBuilder();
499 private static DescriptionBuilder
<CategoricalData
> categoricalDescriptionBuilder
= new DefaultCategoricalDescriptionBuilder();
503 * <p>getDistributionText</p>
505 * @param element a {@link eu.etaxonomy.cdm.model.description.Distribution} object.
506 * @return a {@link java.lang.String} object.
508 public static String
getDistributionText(Distribution element
) {
510 String text
= "EMPTY";
512 Distribution distribution
= element
;
514 NamedArea area
= distribution
.getArea();
517 text
= NamedArea
.labelWithLevel(area
, CdmStore
.getDefaultLanguage());
519 PresenceAbsenceTerm status
= distribution
.getStatus();
521 if (status
!= null) {
522 text
+= ", " + status
.getLabel();
524 text
+= ", NO STATUS";
531 * <p>getImageText</p>
533 * @param media a {@link eu.etaxonomy.cdm.model.media.Media} object.
534 * @return a {@link java.lang.String} object.
536 public static String
getImageText(Media media
) {
537 LanguageString title
= media
.getTitle(CdmStore
.getDefaultLanguage());
539 return title
.getText();
547 * <p>getElementText</p>
549 * @param element a {@link eu.etaxonomy.cdm.model.description.TextData} object.
550 * @return a {@link java.lang.String} object.
552 public static String
getElementText(TextData element
) {
554 if(element
.getFeature().equals(Feature
.CITATION())){
556 for(DescriptionElementSource source
: element
.getSources()){
557 if(source
.getCitation() != null){
558 text
+= source
.getCitation().getTitleCache();
560 if(source
.getNameUsedInSource() != null){
561 text
+= " [ " + source
.getNameUsedInSource().getTitleCache() + " ]";
564 if(CdmUtils
.isEmpty(text
)){
565 text
= "No sources provided";
568 List
<Language
> languages
= Arrays
.asList(new Language
[]{CdmStore
.getDefaultLanguage()});
569 LanguageString languageString
= element
.getPreferredLanguageString(languages
);
570 text
= languageString
!= null ? languageString
.getText() : null;
572 return CdmUtils
.isEmpty(text
) ?
"No text provided" : text
;
576 * <p>getTaxonInteractionText</p>
578 * @param element a {@link eu.etaxonomy.cdm.model.description.TaxonInteraction} object.
579 * @return a {@link java.lang.String} object.
581 public static String
getTaxonInteractionText(TaxonInteraction element
) {
583 Taxon taxon2
= element
.getTaxon2();
584 if(taxon2
!= null && taxon2
.getName() != null){
585 text
= taxon2
.getName().getTitleCache();
587 text
= "No taxon chosen";
594 * <p>getCommonNameText</p>
596 * @param commonName a {@link eu.etaxonomy.cdm.model.description.CommonTaxonName} object.
597 * @return a {@link java.lang.String} object.
599 public static String
getCommonNameText(CommonTaxonName commonName
) {
600 String name
= commonName
.getName();
601 if (name
== null || name
.length() == 0) {
602 name
= "No name provided";
604 Language language
= commonName
.getLanguage();
605 if (language
== null) {
606 name
+= " (No language provided)";
608 name
+= " (" + language
.getDescription() + ")";
614 * <p>getDescriptionText</p>
616 * @param element a {@link eu.etaxonomy.cdm.model.description.DescriptionBase} object.
617 * @return a {@link java.lang.String} object.
619 public static String
getDescriptionText(DescriptionBase element
) {
620 String text
= element
.getTitleCache();
621 if (text
== null || text
.length() == 0) {
622 text
= "No label provided";
629 * <p>getIndividualsAssociationText</p>
631 * @param element a {@link eu.etaxonomy.cdm.model.description.IndividualsAssociation} object.
632 * @return a {@link java.lang.String} object.
634 public static String
getIndividualsAssociationText(IndividualsAssociation element
) {
635 SpecimenOrObservationBase derivedUnit
= element
.getAssociatedSpecimenOrObservation();
636 if(derivedUnit
!= null){
637 return derivedUnit
.getTitleCache();
639 return "No unit chosen";
645 * @param element a {@link java.lang.Object} object.
646 * @return a {@link java.lang.String} object.
648 public static String
getLabel(Object element
){
649 String noLabelString
= "[no label]";
650 if (element
instanceof FeatureNodeContainer
){
651 return getFeatureNodeContainerText((FeatureNodeContainer
) element
);
653 else if (element
instanceof DescriptionBase
) {
654 return getDescriptionText((DescriptionBase
) element
);
656 else if(element
instanceof CategoricalData
){
657 String categoricalDataText
= getCategoricalDataText((CategoricalData
) element
);
658 if(categoricalDataText
==null || categoricalDataText
.isEmpty()){
659 categoricalDataText
= noLabelString
;
661 return categoricalDataText
;
663 else if (element
instanceof CommonTaxonName
) {
664 return getCommonNameText((CommonTaxonName
) element
);
666 else if (element
instanceof Distribution
) {
667 return getDistributionText((Distribution
) element
);
669 else if (element
instanceof IndividualsAssociation
) {
670 return getIndividualsAssociationText((IndividualsAssociation
) element
);
672 else if (element
instanceof QuantitativeData
) {
673 String quantitativeDataText
= getQuantitativeDataText((QuantitativeData
) element
);
674 if(quantitativeDataText
==null || quantitativeDataText
.isEmpty()){
675 quantitativeDataText
= noLabelString
;
677 return quantitativeDataText
;
679 else if (element
instanceof TaxonInteraction
) {
680 return getTaxonInteractionText((TaxonInteraction
) element
);
682 else if (element
instanceof TextData
) {
683 return getElementText((TextData
) element
);
686 return element
.toString();