Revision 52002c73
Added by Cherian Mathew over 9 years ago
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/model/DescriptionHelper.java | ||
---|---|---|
1 | 1 |
// $Id$ |
2 | 2 |
/** |
3 | 3 |
* Copyright (C) 2007 EDIT |
4 |
* European Distributed Institute of Taxonomy
|
|
4 |
* European Distributed Institute of Taxonomy |
|
5 | 5 |
* http://www.e-taxonomy.eu |
6 |
*
|
|
6 |
* |
|
7 | 7 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
8 | 8 |
* See LICENSE.TXT at the top of this package for the full license terms. |
9 | 9 |
*/ |
... | ... | |
36 | 36 |
import eu.etaxonomy.cdm.model.description.Distribution; |
37 | 37 |
import eu.etaxonomy.cdm.model.description.Feature; |
38 | 38 |
import eu.etaxonomy.cdm.model.description.IndividualsAssociation; |
39 |
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTermBase;
|
|
39 |
import eu.etaxonomy.cdm.model.description.PresenceAbsenceTerm; |
|
40 | 40 |
import eu.etaxonomy.cdm.model.description.QuantitativeData; |
41 | 41 |
import eu.etaxonomy.cdm.model.description.TaxonInteraction; |
42 | 42 |
import eu.etaxonomy.cdm.model.description.TextData; |
... | ... | |
55 | 55 |
* @version 1.0 |
56 | 56 |
*/ |
57 | 57 |
public class DescriptionHelper { |
58 |
|
|
58 |
|
|
59 | 59 |
/** |
60 | 60 |
* Returns whatever the element's title cache equivalent is, |
61 | 61 |
* depending on its class. |
... | ... | |
64 | 64 |
* @param language a {@link eu.etaxonomy.cdm.model.common.Language} object. |
65 | 65 |
* @return a {@link java.lang.String} object. |
66 | 66 |
*/ |
67 |
public static String getCache(DescriptionElementBase element,
|
|
67 |
public static String getCache(DescriptionElementBase element, |
|
68 | 68 |
Language language) { |
69 | 69 |
String cache = null; |
70 | 70 |
if (element instanceof TextData) { |
... | ... | |
80 | 80 |
}else{ |
81 | 81 |
cache = "No taxon chosen"; |
82 | 82 |
} |
83 |
|
|
83 |
|
|
84 | 84 |
} |
85 | 85 |
if (element instanceof Distribution) { |
86 | 86 |
Distribution distribution = (Distribution) element; |
87 |
|
|
87 |
|
|
88 | 88 |
NamedArea area = distribution.getArea(); |
89 | 89 |
if(area != null){ |
90 | 90 |
cache = area.getLabel(); |
91 |
|
|
92 |
PresenceAbsenceTermBase<?> status = distribution.getStatus();
|
|
91 |
|
|
92 |
PresenceAbsenceTerm status = distribution.getStatus(); |
|
93 | 93 |
if (status == null){ |
94 | 94 |
cache += ", no status"; |
95 | 95 |
}else { |
... | ... | |
110 | 110 |
public static String getCache(DescriptionElementBase element) { |
111 | 111 |
return getCache(element, CdmStore.getDefaultLanguage()); |
112 | 112 |
} |
113 |
|
|
113 |
|
|
114 | 114 |
/** |
115 | 115 |
* Set whatever the element's title cache equivalent is, |
116 | 116 |
* depending on its class. |
... | ... | |
130 | 130 |
return; |
131 | 131 |
} |
132 | 132 |
if (element instanceof TaxonInteraction) { |
133 |
|
|
133 |
|
|
134 | 134 |
} |
135 | 135 |
if(element instanceof Distribution){ |
136 | 136 |
MessagingUtils.warn(DescriptionHelper.class, "trying to set cache on distribution, don't know what to do at the moment."); |
... | ... | |
138 | 138 |
} |
139 | 139 |
MessagingUtils.warn(DescriptionHelper.class, "No matching subclass found for DescriptionElementBase object, 'cache' not set."); |
140 | 140 |
} |
141 |
|
|
141 |
|
|
142 | 142 |
/** |
143 | 143 |
* Set whatever the element's title cache equivalent is, |
144 | 144 |
* depending on its class, using the default language. |
... | ... | |
150 | 150 |
String value) { |
151 | 151 |
setCache(element, value, CdmStore.getDefaultLanguage()); |
152 | 152 |
} |
153 |
|
|
153 |
|
|
154 | 154 |
/* (non-Javadoc) |
155 | 155 |
* @see eu.etaxonomy.taxeditor.bulkeditor.referencingobjects.IReferencingObjectsService#getObjectDescription(java.lang.Object) |
156 | 156 |
*/ |
... | ... | |
182 | 182 |
}else{ |
183 | 183 |
throw new IllegalStateException("Unknown ISourceable object for given OriginalSourceBase"); |
184 | 184 |
} |
185 |
|
|
185 |
|
|
186 | 186 |
return CdmUtils.concat("; ", new String[]{originalSource.getIdNamespace(), originalSource.getIdInSource(), sourceObjectTitle}); |
187 | 187 |
}catch(LazyInitializationException e){ |
188 | 188 |
String result = "Error initializing title cache for ISourceable of an OriginalSourceBase"; |
... | ... | |
194 | 194 |
return ((LanguageStringBase) element).getText(); |
195 | 195 |
} |
196 | 196 |
if (element instanceof DescriptionElementBase) { |
197 |
return getCache((DescriptionElementBase) element);
|
|
197 |
return getCache((DescriptionElementBase) element); |
|
198 | 198 |
} |
199 | 199 |
if (element instanceof Marker) { |
200 | 200 |
Marker marker = (Marker) element; |
... | ... | |
214 | 214 |
public static String getObjectClassname(Object element) { |
215 | 215 |
return element.getClass().getSimpleName(); |
216 | 216 |
} |
217 |
|
|
217 |
|
|
218 | 218 |
/** |
219 | 219 |
* <p>getFeatureNodeContainerText</p> |
220 | 220 |
* |
... | ... | |
242 | 242 |
*/ |
243 | 243 |
public static String getQuantitativeDataText(QuantitativeData element) { |
244 | 244 |
TextData textData = quantitativeDescriptionBuilder.build(element, getLanguageList()); |
245 |
|
|
245 |
|
|
246 | 246 |
return textData.getText(CdmStore.getDefaultLanguage()); |
247 | 247 |
} |
248 | 248 |
|
... | ... | |
254 | 254 |
*/ |
255 | 255 |
public static String getCategoricalDataText(CategoricalData element) { |
256 | 256 |
TextData textData = categoricalDescriptionBuilder.build(element, getLanguageList()); |
257 |
|
|
257 |
|
|
258 | 258 |
return textData.getText(CdmStore.getDefaultLanguage()); |
259 | 259 |
} |
260 |
|
|
260 |
|
|
261 | 261 |
private static List<Language> getLanguageList(){ |
262 | 262 |
return Arrays.asList(new Language[]{CdmStore.getDefaultLanguage()}); |
263 | 263 |
} |
264 |
|
|
264 |
|
|
265 | 265 |
private static DescriptionBuilder<QuantitativeData> quantitativeDescriptionBuilder = new DefaultQuantitativeDescriptionBuilder(); |
266 | 266 |
private static DescriptionBuilder<CategoricalData> categoricalDescriptionBuilder = new DefaultCategoricalDescriptionBuilder(); |
267 |
|
|
267 |
|
|
268 | 268 |
|
269 | 269 |
/** |
270 | 270 |
* <p>getDistributionText</p> |
... | ... | |
273 | 273 |
* @return a {@link java.lang.String} object. |
274 | 274 |
*/ |
275 | 275 |
public static String getDistributionText(Distribution element) { |
276 |
|
|
276 |
|
|
277 | 277 |
String text = "EMPTY"; |
278 |
|
|
279 |
Distribution distribution = (Distribution) element;
|
|
280 |
|
|
278 |
|
|
279 |
Distribution distribution = element; |
|
280 |
|
|
281 | 281 |
NamedArea area = distribution.getArea(); |
282 | 282 |
if(area != null){ |
283 |
|
|
283 |
|
|
284 | 284 |
text = NamedArea.labelWithLevel(area, CdmStore.getDefaultLanguage()); |
285 |
|
|
286 |
PresenceAbsenceTermBase<?> status = distribution.getStatus();
|
|
287 |
|
|
285 |
|
|
286 |
PresenceAbsenceTerm status = distribution.getStatus(); |
|
287 |
|
|
288 | 288 |
if (status != null) { |
289 | 289 |
text += ", " + status.getLabel(); |
290 | 290 |
}else{ |
... | ... | |
308 | 308 |
return "No title."; |
309 | 309 |
} |
310 | 310 |
|
311 |
|
|
312 |
|
|
311 |
|
|
312 |
|
|
313 | 313 |
/** |
314 | 314 |
* <p>getElementText</p> |
315 | 315 |
* |
316 | 316 |
* @param element a {@link eu.etaxonomy.cdm.model.description.TextData} object. |
317 | 317 |
* @return a {@link java.lang.String} object. |
318 | 318 |
*/ |
319 |
public static String getElementText(TextData element) {
|
|
319 |
public static String getElementText(TextData element) { |
|
320 | 320 |
String text = null; |
321 | 321 |
if(element.getFeature().equals(Feature.CITATION())){ |
322 | 322 |
text = ""; |
... | ... | |
338 | 338 |
} |
339 | 339 |
return CdmUtils.isEmpty(text) ? "No text provided" : text; |
340 | 340 |
} |
341 |
|
|
341 |
|
|
342 | 342 |
/** |
343 | 343 |
* <p>getTaxonInteractionText</p> |
344 | 344 |
* |
... | ... | |
347 | 347 |
*/ |
348 | 348 |
public static String getTaxonInteractionText(TaxonInteraction element) { |
349 | 349 |
String text = ""; |
350 |
Taxon taxon2 = ((TaxonInteraction) element).getTaxon2();
|
|
350 |
Taxon taxon2 = element.getTaxon2();
|
|
351 | 351 |
if(taxon2 != null && taxon2.getName() != null){ |
352 | 352 |
text = taxon2.getName().getTitleCache(); |
353 | 353 |
}else{ |
354 | 354 |
text = "No taxon chosen"; |
355 | 355 |
} |
356 |
|
|
356 |
|
|
357 | 357 |
return text; |
358 | 358 |
} |
359 | 359 |
|
... | ... | |
388 | 388 |
if (text == null || text.length() == 0) { |
389 | 389 |
text = "No label provided"; |
390 | 390 |
} |
391 |
|
|
391 |
|
|
392 | 392 |
return "Description: " + text; |
393 | 393 |
} |
394 |
|
|
394 |
|
|
395 | 395 |
/** |
396 | 396 |
* <p>getIndividualsAssociationText</p> |
397 | 397 |
* |
... | ... | |
423 | 423 |
return getCategoricalDataText((CategoricalData) element); |
424 | 424 |
} |
425 | 425 |
else if (element instanceof CommonTaxonName) { |
426 |
return getCommonNameText((CommonTaxonName) element);
|
|
426 |
return getCommonNameText((CommonTaxonName) element); |
|
427 | 427 |
} |
428 | 428 |
else if (element instanceof Distribution) { |
429 |
return getDistributionText((Distribution) element);
|
|
430 |
}
|
|
429 |
return getDistributionText((Distribution) element); |
|
430 |
} |
|
431 | 431 |
else if (element instanceof IndividualsAssociation) { |
432 | 432 |
return getIndividualsAssociationText((IndividualsAssociation) element); |
433 | 433 |
} |
Also available in: Unified diff
merge from trunk