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
.util
.ArrayList
;
14 import java
.util
.List
;
16 import org
.apache
.log4j
.Logger
;
18 import eu
.etaxonomy
.cdm
.api
.service
.ILocationService
;
19 import eu
.etaxonomy
.cdm
.api
.service
.ILocationService
.NamedAreaVocabularyType
;
20 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
21 import eu
.etaxonomy
.cdm
.model
.description
.AbsenceTerm
;
22 import eu
.etaxonomy
.cdm
.model
.description
.CommonTaxonName
;
23 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
24 import eu
.etaxonomy
.cdm
.model
.description
.PresenceAbsenceTermBase
;
25 import eu
.etaxonomy
.cdm
.model
.description
.PresenceTerm
;
26 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
27 import eu
.etaxonomy
.cdm
.model
.location
.NamedArea
;
28 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaLevel
;
29 import eu
.etaxonomy
.cdm
.model
.location
.NamedAreaType
;
30 import eu
.etaxonomy
.taxeditor
.TaxEditorPlugin
;
31 import eu
.etaxonomy
.taxeditor
.datasource
.CdmDataSourceRepository
;
38 public class DescriptionUtil
{
39 private static final Logger logger
= Logger
40 .getLogger(DescriptionUtil
.class);
43 * Returns whatever the element's title cache equivalent is,
44 * depending on its class.
50 public static String
getCache(DescriptionElementBase element
,
53 if (element
instanceof TextData
) {
54 cache
= ((TextData
) element
).getText(language
);
56 if (element
instanceof CommonTaxonName
) {
57 cache
= ((CommonTaxonName
) element
).getName();
59 return cache
== null ?
"" : cache
;
63 * Returns whatever the element's title cache equivalent is,
64 * depending on its class, using the default language.
69 public static String
getCache(DescriptionElementBase element
) {
70 return getCache(element
, Language
.DEFAULT());
74 * Set whatever the element's title cache equivalent is,
75 * depending on its class.
81 public static void setCache(DescriptionElementBase element
,
82 String value
, Language language
) {
83 if (element
instanceof TextData
) {
84 ((TextData
) element
).putText(value
, language
);
87 if (element
instanceof CommonTaxonName
) {
88 ((CommonTaxonName
) element
).setName(value
);
91 logger
.warn("No matching subclass found for DescriptionElementBase object, 'cache' not set.");
95 * Set whatever the element's title cache equivalent is,
96 * depending on its class, using the default language.
101 public static void setCache(DescriptionElementBase element
,
103 setCache(element
, value
, Language
.DEFAULT());
106 public static IDistributionInfoProvider
getDistributionInfoProvider() {
107 IDistributionInfoProvider provider
= new DistributionInfoProvider();
111 static class DistributionInfoProvider
implements IDistributionInfoProvider
{
113 private static final String TDWG
= "TDWG Areas";
114 private static final String ISO_COUNTRY
= "ISO Country Codes";
115 private static final String ISO_WATERBODY
= "ISO Waterbody Codes";
116 private static ILocationService locationService
;
117 private List
<Object
> vocabTypes
;
120 * @see eu.etaxonomy.taxeditor.model.IDistributionInfoProvider#getAbsenceTerms()
123 public List
<AbsenceTerm
> getAbsenceTerms() {
124 List
<AbsenceTerm
> absenceTerms
= new ArrayList
<AbsenceTerm
>();
125 absenceTerms
.add(AbsenceTerm
.ABSENT());
130 * @see eu.etaxonomy.taxeditor.model.IDistributionInfoProvider#getPresenceTerms()
133 public List
<PresenceTerm
> getPresenceTerms() {
134 List
<PresenceTerm
> presenceTerms
= new ArrayList
<PresenceTerm
>();
135 presenceTerms
.add(PresenceTerm
.CULTIVATED());
136 presenceTerms
.add(PresenceTerm
.ENDEMIC_FOR_THE_RELEVANT_AREA());
137 presenceTerms
.add(PresenceTerm
.INTRODUCED());
138 return presenceTerms
;
142 * @see eu.etaxonomy.taxeditor.model.IDistributionInfoProvider#getVocabularyNextLevelAreas(eu.etaxonomy.cdm.model.location.NamedArea)
145 public List
<NamedArea
> getVocabularyNextLevelAreas(NamedArea namedArea
) {
146 List
<NamedArea
> namedAreas
= new ArrayList
<NamedArea
>();
147 namedAreas
.add(NamedArea
.NewInstance("USA", "USA", "USA"));
148 namedAreas
.add(NamedArea
.NewInstance("Canada", "Canada", "CAN"));
149 namedAreas
.add(NamedArea
.NewInstance("Mexico", "Mexico", "MEX"));
153 private ILocationService
getLocationService() {
154 if (locationService
== null) {
155 locationService
= TaxEditorPlugin
.getDefault().getApplicationController().getLocationService();
157 return locationService
;
161 * @see eu.etaxonomy.taxeditor.model.IDistributionInfoProvider#getVocabularyTopLevelAreas(java.lang.Object)
164 public List
<NamedArea
> getVocabularyTopLevelAreas(Object vocabularyType
) {
166 if (!(vocabularyType
instanceof NamedAreaVocabularyType
)) {
169 for (Object o
:getLocationService().getNamedAreaVocabulary(
170 (NamedAreaVocabularyType
) vocabularyType
, NamedAreaLevel
.TDWG_LEVEL1(),
171 NamedAreaType
.NATURAL_AREA())) {
172 logger
.warn(o
.toString());
175 if (vocabularyType
.equals(TDWG
)) {
176 // for (Object o : locationService.getNamedAreaTypeVocabulary()) {
177 // for (Object o : locationService.getNamedAreaLevelVocabulary()) {
178 // NamedAreaVocabularyType
179 // for (Object o : locationService.getNamedAreaVocabulary(vocabularyType, namedAreaLevel, namedAreaType) .getNamedAreaLevelVocabulary()) {
180 // logger.warn(o.toString());
183 if (vocabularyType
.equals(ISO_COUNTRY
)) {
186 if (vocabularyType
.equals(ISO_WATERBODY
)) {
190 // List<NamedArea> namedAreas = new ArrayList<NamedArea>();
191 // namedAreas.add(NamedArea.NewInstance("North America", "North America", "NA"));
192 // namedAreas.add(NamedArea.NewInstance("Europe", "Europe", "EUR"));
193 // return namedAreas;
197 * @see eu.etaxonomy.taxeditor.model.IDistributionInfoProvider#getVocabularyTypes()
200 public List
<Object
> getVocabularyTypes() {
201 if (vocabTypes
== null) {
202 vocabTypes
= new ArrayList
<Object
>();
203 for (NamedAreaVocabularyType vocabType
: getLocationService().getNamedAreaVocabularyTypes()) {
204 vocabTypes
.add(vocabType
);
208 // vocabTypes.add("TDWG Areas");
209 // vocabTypes.add("ISO Country Codes");
210 // vocabTypes.add("ISO Waterbody Codes");
211 // return vocabTypes;
216 * @see eu.etaxonomy.taxeditor.model.IDistributionInfoProvider#getVocabularyTypeLabel()
219 public String
getVocabularyTypeLabel(Object vocabularyType
) {
220 if (vocabularyType
instanceof String
) {
221 return (String
) vocabularyType
;
223 return vocabularyType
.toString();
228 * @see eu.etaxonomy.taxeditor.model.IDistributionInfoProvider#getPresenceAbsenceTermLabel(eu.etaxonomy.cdm.model.description.PresenceTerm)
231 public String
getPresenceAbsenceTermLabel(PresenceAbsenceTermBase term
) {
232 return term
.getDescription();
236 * @see eu.etaxonomy.taxeditor.model.IDistributionInfoProvider#getNamedAreaChildren(eu.etaxonomy.cdm.model.location.NamedArea)
239 public List
<NamedArea
> getNamedAreaChildren(NamedArea namedArea
) {
240 // TODO Auto-generated method stub
245 * @see eu.etaxonomy.taxeditor.model.IDistributionInfoProvider#getNamedAreaParent(eu.etaxonomy.cdm.model.location.NamedArea)
248 public NamedArea
getNamedAreaParent(NamedArea namedArea
) {
249 // TODO Auto-generated method stub