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
.editor
.view
.checklist
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Arrays
;
15 import java
.util
.List
;
16 import java
.util
.SortedSet
;
17 import java
.util
.TreeSet
;
18 import java
.util
.UUID
;
20 import org
.eclipse
.jface
.preference
.IPreferenceStore
;
21 import org
.eclipse
.jface
.viewers
.ITableLabelProvider
;
22 import org
.eclipse
.jface
.viewers
.LabelProvider
;
23 import org
.eclipse
.swt
.graphics
.Image
;
25 import eu
.etaxonomy
.cdm
.api
.service
.IDescriptionService
;
26 import eu
.etaxonomy
.cdm
.api
.service
.ITermService
;
27 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
28 import eu
.etaxonomy
.cdm
.model
.common
.DefinedTermBase
;
29 import eu
.etaxonomy
.cdm
.model
.common
.Language
;
30 import eu
.etaxonomy
.cdm
.model
.common
.TermLanguageComparator
;
31 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
32 import eu
.etaxonomy
.cdm
.model
.description
.Distribution
;
33 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
34 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
35 import eu
.etaxonomy
.cdm
.model
.reference
.INomenclaturalReference
;
36 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
37 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
38 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
39 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
47 public class ChecklistLabelProvider
extends LabelProvider
implements ITableLabelProvider
{
49 public static final String DEFAULT_ENTRY
= "";
50 private IDescriptionService descriptionService
;
51 private final List
<DefinedTermBase
<?
>> namedAreas
;
58 public ChecklistLabelProvider() {
59 namedAreas
= loadNamedAreas();
66 * org.eclipse.jface.viewers.ITableLabelProvider#getColumnImage(java.lang
71 public Image
getColumnImage(Object element
, int columnIndex
) {
80 * org.eclipse.jface.viewers.ITableLabelProvider#getColumnText(java.lang
85 public String
getColumnText(Object element
, int columnIndex
) {
86 descriptionService
= CdmStore
.getService(IDescriptionService
.class);
87 Taxon taxon
= (Taxon
) element
;
88 //TODO load areas by this list
89 SortedSet
<DefinedTermBase
<?
>> sortedNamedAreas
= (SortedSet
<DefinedTermBase
<?
>>) getTermsOrderedByLabels(namedAreas
, CdmStore
.getDefaultLanguage());
91 List
<TaxonDescription
> listTaxonDescriptions
= descriptionService
.listTaxonDescriptions(taxon
, null, null, null, null, null, DESC_INIT_STRATEGY
);;
92 NonViralName
<?
> nonVirlaName
= HibernateProxyHelper
.deproxy(taxon
.getName(), NonViralName
.class);
94 switch (columnIndex
) {
96 String taxonName
= null;
97 taxonName
= (nonVirlaName
!= null) ? nonVirlaName
.getNameCache() : null;
98 return (taxonName
!= null) ? taxonName
: DEFAULT_ENTRY
;
101 String authorship
= null;
102 authorship
= (nonVirlaName
!= null) ? nonVirlaName
.getAuthorshipCache() : null;
103 return (authorship
!= null) ? authorship
: DEFAULT_ENTRY
;
106 if (taxon
.getName() != null) {
107 INomenclaturalReference nomenclaturalReference
= HibernateProxyHelper
.deproxy(
108 nonVirlaName
.getNomenclaturalReference(), Reference
.class);
109 ref
= (nomenclaturalReference
!= null) ? nomenclaturalReference
.getAbbrevTitleCache() : null;
111 return (ref
!= null) ? ref
: DEFAULT_ENTRY
;
114 if (taxon
.getName().getRank() != null) {
115 rank
= taxon
.getName().getRank().toString();
117 return (rank
!= null) ? rank
: DEFAULT_ENTRY
;
122 for (TaxonDescription td
: listTaxonDescriptions
) {
123 for (DescriptionElementBase deb
: td
.getElements()) {
124 if (deb
instanceof Distribution
) {
125 Distribution distribution
= (Distribution
) deb
;
126 String area
= distribution
.toString();
127 if(sortedNamedAreas
!= null){
128 Object
[] array
= sortedNamedAreas
.toArray();
129 DefinedTermBase
<DefinedTermBase
> term
= (DefinedTermBase
<DefinedTermBase
>) array
[columnIndex
-4];
131 if (area
.equalsIgnoreCase(term
.getTitleCache())) {
132 return (distribution
.getStatus().getTitleCache() != null)?distribution
.getStatus().getTitleCache():DEFAULT_ENTRY
;
140 return DEFAULT_ENTRY
;
144 private static final List
<String
> DESC_INIT_STRATEGY
= Arrays
.asList(new String
[] { "descriptions",
145 "descriptions.*", "description.state" });
148 private List
<DefinedTermBase
<?
>> loadNamedAreas() {
149 IPreferenceStore preferenceStore
= PreferencesUtil
.getPreferenceStore();
150 String values
= preferenceStore
.getString(PreferencesUtil
.DISTRIBUTION_AREA_OCCURENCE_STATUS
);
151 if (values
!= null && values
!= "") {
152 String
[] split
= values
.split(",");
153 List
<String
> listValue
= Arrays
.asList(split
);
154 ArrayList
<DefinedTermBase
<?
>> termlist
= new ArrayList
<DefinedTermBase
<?
>>();
155 for(String s
: listValue
){
156 UUID uuid
= UUID
.fromString(s
);
157 ITermService service
= CdmStore
.getService(ITermService
.class);
158 DefinedTermBase definedTermBase
= service
.load(uuid
);
159 termlist
.add(definedTermBase
);
166 public SortedSet
<?
> getTermsOrderedByLabels(List
<DefinedTermBase
<?
>> listTerm
,Language language
){
167 TermLanguageComparator comp
= new TermLanguageComparator();
168 comp
.setCompareLanguage(language
);
169 SortedSet result
= new TreeSet(comp
);
170 if(listTerm
!= null){
171 result
.addAll(listTerm
);
177 * @return the namedAreas
179 public List
<DefinedTermBase
<?
>> getNamedAreas() {